-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of query hashing by using a precomputed schema hash #6622
Conversation
The `QueryHash` type was reused here, but it's not hashing a query at all.
This is just to keep it compiling right now, we can remove it at the end (it's probably right to do so)
Adding it to all the transitive usage sites is a lot of work. Renamed it for clarity.
It would be better to make everything not-pub, but let's do that separately.
It's vital that we populate `configuration.apollo` before we try to populate `configuration.apollo.schema_id`.
@@ -313,6 +313,8 @@ fn setup_from_mocks( | |||
configuration: serde_json::Value, | |||
mocks: &[(&'static str, &'static str)], | |||
) -> TestHarness<'static> { | |||
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@goto-bus-stop This looks like an unintentional change introduced by the merge.
Is it correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests failed without it. We have to do this in several places after the hyper 1.0 upgrade on dev, but it's a bit weird that these tests were passing on dev before :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because tonic changed. We need to call this.
@@ -354,6 +354,8 @@ fn setup_from_mocks( | |||
configuration: serde_json::Value, | |||
mocks: &[(&'static str, &'static str)], | |||
) -> TestHarness<'static> { | |||
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@goto-bus-stop looks like the same happened here
// FIXME: It seems bad that you can create an empty hash easily and use it in security-critical | ||
// places. This impl should be deleted outright and we should update usage sites. | ||
// If the query hash is truly not required to contain data in those usage sites, we should use | ||
// something like an Option instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems potentially quite bad. File an issue so we don’t forget it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the impact of fixing this now? Adding something that is a security risk doesn't sound good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BrynCooke Actual call to default happening here:
https://github.com/apollographql/router/pull/6622/files#diff-7108edf02483a7de6d8c37b938df0634afc78590242b4fc94709c9dd2e626fb4R108
Previously, it was just less noticeable, and my change and @goto-bus-stop comments just make it stand out more.
Fixing it will significantly increase scope of this PR but @SimonSapin is right, we need to open an issue about it.
I will do that right now
@Mergifyio backport 1.59.2 |
✅ Backports have been created
|
…sh (#6622) Co-authored-by: Simon Sapin <[email protected]> Co-authored-by: Renée Kooi <[email protected]> (cherry picked from commit 8c81327) # Conflicts: # apollo-router/src/query_planner/bridge_query_planner.rs # apollo-router/src/query_planner/caching_query_planner.rs # apollo-router/src/query_planner/fetch.rs # apollo-router/src/query_planner/snapshots/apollo_router__query_planner__bridge_query_planner__tests__plan_root.snap # apollo-router/src/spec/query/change.rs # apollo-router/src/spec/schema.rs # apollo-router/tests/integration/redis.rs # apollo-router/tests/snapshots/type_conditions___test_type_conditions_disabled.snap # apollo-router/tests/snapshots/type_conditions___test_type_conditions_enabled.snap # apollo-router/tests/snapshots/type_conditions___test_type_conditions_enabled_generate_query_fragments.snap # apollo-router/tests/snapshots/type_conditions___test_type_conditions_enabled_list_of_list.snap # apollo-router/tests/snapshots/type_conditions___test_type_conditions_enabled_list_of_list_of_list.snap # apollo-router/tests/snapshots/type_conditions___test_type_conditions_enabled_shouldnt_make_article_fetch.snap
@Mergifyio backport 1.x |
✅ Backports have been created
|
…sh (#6622) Co-authored-by: Simon Sapin <[email protected]> Co-authored-by: Renée Kooi <[email protected]> (cherry picked from commit 8c81327) # Conflicts: # apollo-router/src/query_planner/fetch.rs # apollo-router/src/spec/schema.rs
@Mergifyio refresh |
✅ Pull request refreshed |
…sh (backport #6622) (#6631) Co-authored-by: Ivan Goncharov <[email protected]> Co-authored-by: Renée Kooi <[email protected]>
…sh (backport #6622) (#6633) Co-authored-by: Ivan Goncharov <[email protected]> Co-authored-by: Renée Kooi <[email protected]>
This PR reverts the query hashing back to a simpler algorithm, which is faster and has more predictable CPU and memory costs.
Previous vs. New Algorithm
Key Change
Benefits of the New Approach
Implementation Details
SchemaHash
type has been introduced and the existingQueryHash
type refined.QueryHash
is now created viaSchemaHash::operation_hash
with a query string and optional operation name.Future Plan
QueryHash
creation for now, but they will be removed in subsequent PRs.Checklist
Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.
Exceptions
Note any exceptions here
Notes
Footnotes
It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. ↩
Configuration is an important part of many changes. Where applicable please try to document configuration examples. ↩
Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions. ↩