Skip to content
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

Fix the query hashing algorithm #6205

Merged
merged 106 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 104 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
f61d243
add test cases
IvanGoncharov Apr 26, 2024
12658ac
add a separator between each part of the hash
Geal May 27, 2024
b768d00
deactivate the query string hashing for now
Geal May 27, 2024
78ca936
fix some tests
Geal May 27, 2024
2511864
reactivate all tests
Geal May 27, 2024
d783eee
fixes for query variables
Geal May 27, 2024
459681d
fix some field hashing tests
Geal May 27, 2024
842dce9
add separators
Geal May 27, 2024
9bb31df
hash some directives
Geal May 27, 2024
d632e8a
hash the schema
Geal May 28, 2024
9da105e
hash directive definitions
Geal May 28, 2024
6e6d517
cleanup
Geal May 28, 2024
85d93fe
hash interface implementers
Geal May 28, 2024
7968c22
update hashes
Geal May 28, 2024
47dc6fe
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 3, 2024
4d7ceea
lint
Geal Jun 3, 2024
9c34952
add a test for directives applied to interface definitions
Geal Jun 3, 2024
fcb3f3f
cleanup
Geal Jun 3, 2024
0b17980
add a metric tracking how many query plans could be reused
Geal Jun 3, 2024
bd7e5eb
simplify the caching key
Geal Jun 3, 2024
22359ed
update hashes
Geal Jun 3, 2024
dfd8819
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 3, 2024
4d47696
fix integration tests
Geal Jun 3, 2024
d1e2f34
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 7, 2024
adb9d11
lint
Geal Jun 7, 2024
2263dcb
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 7, 2024
98ec603
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 13, 2024
bf53aa2
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 13, 2024
b8361b9
update snapshots
Geal Jun 13, 2024
ccf9fe2
update snapshots
Geal Jun 13, 2024
c218be8
hash the rust query planner options too
Geal Jun 13, 2024
3e53969
remove JSON serialization in redis key generation
Geal Jun 13, 2024
37bd5de
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 13, 2024
f9d5b10
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 18, 2024
935ecf9
update separators for default_valur
Geal Jun 18, 2024
b4ce95a
update snapshots
Geal Jun 18, 2024
9dae438
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 24, 2024
edca1bc
update snapshots
Geal Jun 24, 2024
56ce0db
update SetContext snapshots
Geal Jun 24, 2024
88b8d5d
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jun 26, 2024
049834e
fix log message
Geal Jun 27, 2024
3f128e1
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jul 1, 2024
52bee1d
docs and changeset
Geal Jul 1, 2024
df38cec
update changeset
Geal Jul 1, 2024
42a7dfe
use both schema hash and query hash
Geal Jul 1, 2024
f80c1e7
more precise way to write the redis cache key
Geal Jul 1, 2024
4b492de
fmt
Geal Jul 1, 2024
183bc4c
Update apollo-router/src/query_planner/caching_query_planner.rs
Geal Jul 1, 2024
b4ed22a
Update apollo-router/src/query_planner/caching_query_planner.rs
Geal Jul 1, 2024
1a46211
fix config hashing
Geal Jul 1, 2024
6c88132
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Jul 31, 2024
750aaa1
fix
Geal Jul 31, 2024
52e3424
fix QP test
Geal Jul 31, 2024
66ebc0d
introduce the metrics
Geal Jul 31, 2024
d4170f7
Apply suggestions from code review
Geal Jul 31, 2024
df8e6fc
add a prefix for planner configuration hashing
Geal Jul 31, 2024
52e27df
use the new metrics
Geal Jul 31, 2024
66c9a00
algorithm documentation
Geal Jul 31, 2024
391ab81
Update apollo-router/src/spec/query/change.rs
Geal Jul 31, 2024
e1067ed
add more tests
Geal Jul 31, 2024
bf734b9
more tests for input objects
Geal Jul 31, 2024
81604c2
update metadata hashing
Geal Jul 31, 2024
f9c71a5
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Aug 13, 2024
4f8f5ec
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Aug 27, 2024
bd11be2
update snapshots
Geal Aug 27, 2024
e3ca286
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Aug 29, 2024
1b76c0a
isolate loops
Geal Aug 29, 2024
555e507
hash implemented interfaces
Geal Aug 29, 2024
efc3274
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Aug 30, 2024
6bf14a7
lint
Geal Aug 30, 2024
2a37728
hash implemented interfaces for objects
Geal Aug 30, 2024
603b27b
update keys in tests
Geal Aug 30, 2024
a5c0c7c
update snapshots
Geal Aug 30, 2024
5fdaa4b
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Sep 6, 2024
0151f0f
fix
Geal Sep 6, 2024
028a088
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Sep 9, 2024
1fcb704
add a mode to measure query plan reuse
Geal Sep 9, 2024
c57ec66
fix
Geal Sep 9, 2024
cde0142
aranch 'dev' into geal/fix-hashing-algorithm
Geal Sep 16, 2024
bd325e6
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Oct 18, 2024
fc348d7
unneeded change
Geal Oct 18, 2024
e22917d
snapshots
Geal Oct 21, 2024
3d053cb
snapshots
Geal Oct 21, 2024
86b70b0
Merge branch 'dev' into geal/fix-hashing-algorithm
abernix Oct 23, 2024
72bc405
add separators for the query plan cache key
Geal Oct 29, 2024
f58c7e8
Merge branch 'dev' into geal/fix-hashing-algorithm
Geal Oct 29, 2024
53ed3bd
separate the query hash algorithm fixes
Geal Oct 29, 2024
30e6002
remove changeset
Geal Oct 29, 2024
8b6db27
update snapshots
Geal Oct 29, 2024
0f8d90d
update snapshots
Geal Oct 29, 2024
9394ee7
Apply suggestions from code review
Geal Oct 31, 2024
350fde0
review feedback
Geal Oct 31, 2024
1598fbf
separate field definition hashing from query field hashing and cache it
Geal Oct 31, 2024
4c444ca
Merge branch 'dev' into geal/fix-query-hashing
Geal Nov 5, 2024
fb25e9d
add a test for the context and fromContext directives
Geal Nov 5, 2024
56e81af
add support for the context directives
Geal Nov 5, 2024
8302c45
lint
Geal Nov 5, 2024
71209e3
Merge branch 'dev' into geal/fix-query-hashing
Geal Nov 5, 2024
55161ef
add comment for fromContext
Geal Nov 6, 2024
57c3096
Merge branch 'dev' into geal/fix-query-hashing
Geal Nov 12, 2024
f618d2c
Merge branch 'dev' into geal/fix-query-hashing
Geal Nov 18, 2024
4b0d42a
fix test
Geal Nov 18, 2024
e9b8997
fix tests
Geal Nov 18, 2024
b61497d
Add changelog
IvanGoncharov Nov 28, 2024
74fcb14
Apply suggestions from code review
IvanGoncharov Nov 29, 2024
9aeedd2
Add notice about changes in cache keys
IvanGoncharov Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changesets/fix_fix_query_hashing.md
IvanGoncharov marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Fix the query hashing algorithm ([PR #6205](https://github.com/apollographql/router/pull/6205))

The Router includes a schema-aware query hashing algorithm designed to return the same hash across schema updates if the query remains unaffected. This update enhances the algorithm by addressing various corner cases, improving its reliability and consistency.

By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/6205kkk
IvanGoncharov marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ expression: query_plan
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "23605b350473485e40bc8b1245f0c5c226a2997a96291bf3ad3412570a5172bb",
"schemaAwareHash": "cdab250089cc24ee95f749d187d2f936878348e62061b85fe6d1dccb9f4c26a1",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ expression: query_plan
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "d14f50b039a3b961385f4d2a878c5800dd01141cddd3f8f1874a5499bbe397a9",
"schemaAwareHash": "113c32833cf7c2bb4324b08c068eb6613ebe0f77efaf3098ae6f0ed7b2df11de",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down Expand Up @@ -63,7 +63,7 @@ expression: query_plan
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "caa182daf66e4ffe9b1af8c386092ba830887bbae0d58395066fa480525080ec",
"schemaAwareHash": "7ef79e08871a3e122407b86d57079c3607cfd26a1993e2c239603a39d04d1bd8",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ expression: "serde_json::to_value(response).unwrap()"
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "c595a39efeab9494c75a29de44ec4748c1741ddb96e1833e99139b058aa9da84",
"schemaAwareHash": "2504c66db02c170d0040785e0ac3455155db03beddcb7cc4d16f08ca02201fac",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down Expand Up @@ -109,7 +109,7 @@ expression: "serde_json::to_value(response).unwrap()"
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "7054d7662e20905b01d6f937e6b588ed422e0e79de737c98e3d51b6dc610179f",
"schemaAwareHash": "0f8abdb350d59e86567b72717be114a465c59ac4e6027d7179de6448b0fbc5a4",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down Expand Up @@ -156,7 +156,7 @@ expression: "serde_json::to_value(response).unwrap()"
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "76d400fc6a494cbe05a44751923e570ee31928f0fb035ea36c14d4d6f4545482",
"schemaAwareHash": "a1e19c2c170464974293f946f09116216e71424a821908beb0062091475dad11",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down Expand Up @@ -200,7 +200,7 @@ expression: "serde_json::to_value(response).unwrap()"
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "bff0ce0cfd6e2830949c59ae26f350d06d76150d6041b08c3d0c4384bc20b271",
"schemaAwareHash": "466ef25e373cf367e18ed264f76c7c4b2f27fe2ef105cb39d8528320addaedc7",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ expression: "serde_json::to_value(response).unwrap()"
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "c595a39efeab9494c75a29de44ec4748c1741ddb96e1833e99139b058aa9da84",
"schemaAwareHash": "2504c66db02c170d0040785e0ac3455155db03beddcb7cc4d16f08ca02201fac",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down Expand Up @@ -109,7 +109,7 @@ expression: "serde_json::to_value(response).unwrap()"
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "7054d7662e20905b01d6f937e6b588ed422e0e79de737c98e3d51b6dc610179f",
"schemaAwareHash": "0f8abdb350d59e86567b72717be114a465c59ac4e6027d7179de6448b0fbc5a4",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down Expand Up @@ -156,7 +156,7 @@ expression: "serde_json::to_value(response).unwrap()"
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "76d400fc6a494cbe05a44751923e570ee31928f0fb035ea36c14d4d6f4545482",
"schemaAwareHash": "a1e19c2c170464974293f946f09116216e71424a821908beb0062091475dad11",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down Expand Up @@ -200,7 +200,7 @@ expression: "serde_json::to_value(response).unwrap()"
"inputRewrites": null,
"outputRewrites": null,
"contextRewrites": null,
"schemaAwareHash": "bff0ce0cfd6e2830949c59ae26f350d06d76150d6041b08c3d0c4384bc20b271",
"schemaAwareHash": "466ef25e373cf367e18ed264f76c7c4b2f27fe2ef105cb39d8528320addaedc7",
"authorization": {
"is_authenticated": false,
"scopes": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Fetch(
output_rewrites: None,
context_rewrites: None,
schema_aware_hash: QueryHash(
"5c5036eef33484e505dd5a8666fd0a802e60d830964a4dbbf662526398563ffd",
"65e550250ef331b8dc49d9e2da8f4cd5add979720cbe83ba545a0f78ece8d329",
),
authorization: CacheKeyMetadata {
is_authenticated: false,
Expand Down
4 changes: 3 additions & 1 deletion apollo-router/src/spec/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ impl Query {
let operation = Operation::from_hir(&operation, schema, &mut defer_stats, &fragments)?;

let mut visitor =
QueryHashVisitor::new(schema.supergraph_schema(), &schema.raw_sdl, document);
QueryHashVisitor::new(schema.supergraph_schema(), &schema.raw_sdl, document).map_err(
|e| SpecError::QueryHashing(format!("could not calculate the query hash: {e}")),
)?;
traverse::document(&mut visitor, document, operation_name).map_err(|e| {
SpecError::QueryHashing(format!("could not calculate the query hash: {e}"))
})?;
Expand Down
Loading