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

Move QP compatibility checks into constructor and add metric #5811

Merged
merged 19 commits into from
Aug 20, 2024

Conversation

SimonSapin
Copy link
Contributor

This aligns better with experimental_query_planner_mode: both_best_effort falling back to legacy when the QueryPlanner::new constructor returns an error.


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Tests added and passing3
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

Footnotes

  1. 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.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

Copy link
Contributor

@SimonSapin, please consider creating a changeset entry in /.changesets/. These instructions describe the process and tooling.

@router-perf
Copy link

router-perf bot commented Aug 13, 2024

CI performance tests

  • const - Basic stress test that runs with a constant number of users
  • demand-control-instrumented - A copy of the step test, but with demand control monitoring and metrics enabled
  • demand-control-uninstrumented - A copy of the step test, but with demand control monitoring enabled
  • enhanced-signature - Enhanced signature enabled
  • events - Stress test for events with a lot of users and deduplication ENABLED
  • events_big_cap_high_rate - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity
  • events_big_cap_high_rate_callback - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity using callback mode
  • events_callback - Stress test for events with a lot of users and deduplication ENABLED in callback mode
  • events_without_dedup - Stress test for events with a lot of users and deduplication DISABLED
  • events_without_dedup_callback - Stress test for events with a lot of users and deduplication DISABLED using callback mode
  • extended-reference-mode - Extended reference mode enabled
  • large-request - Stress test with a 1 MB request payload
  • no-tracing - Basic stress test, no tracing
  • reload - Reload test over a long period of time at a constant rate of users
  • step-jemalloc-tuning - Clone of the basic stress test for jemalloc tuning
  • step-local-metrics - Field stats that are generated from the router rather than FTV1
  • step-with-prometheus - A copy of the step test with the Prometheus metrics exporter enabled
  • step - Basic stress test that steps up the number of users over time
  • xlarge-request - Stress test with 10 MB request payload
  • xxlarge-request - Stress test with 100 MB request payload

@SimonSapin SimonSapin marked this pull request as draft August 13, 2024 14:14
@SimonSapin
Copy link
Contributor Author

SimonSapin commented Aug 13, 2024

Draft while we consider adding a new metric for constructor errors

Edit: metrics can be a follow-up PR

@SimonSapin SimonSapin marked this pull request as ready for review August 13, 2024 14:50
field
.directives
.iter()
.filter(|d| d.name.as_str() == JOIN_FIELD)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we look up the correct name of the directive on the supergraph's .metadata()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On one hand, probably yes. On the other hand, we have enough occurrences of "join__ in the code base that I doubt anything works if a supregraph uses import renames.

Maybe composition supports renames when reading subgraphs be never emits them in a supergraph?

SimonSapin and others added 5 commits August 13, 2024 17:33
This adds a function to capture metrics for rust qp intialisation. We want to capture whether or not initialisation was a success. We also want to capture which unsupported feature triggered a failure - `@context`, progressive `@overrides` or a fed1 supergraph. There is an addition of "internal init error" to capture the remaining possible match arms.

In order to classify unsupported features, this commit also adds an `UnsupportedFeatureKind` enum to apollo-federation errors.
Copy link
Member

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the single attribute!

One thing we should keep in mind: does this give users a scary warning on startup if they're using default configuration (both_best_effort) and new federation features (like prog. override)? It should be clear that they don't need to worry about anything except fed 1 issues, I think.

apollo-router/src/query_planner/bridge_query_planner.rs Outdated Show resolved Hide resolved
apollo-router/src/query_planner/bridge_query_planner.rs Outdated Show resolved Hide resolved
}
}

metric_rust_qp_init(None);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in an else or we get duplicate metics

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this made me realise we are missing the other two kinds of errors in this match - AggregateFederationError and MultipleFederationErrors. They would have been counted as a "success" 🙈

lrlna and others added 4 commits August 15, 2024 15:13
Co-authored-by: Renée <renee.kooi@apollographql.com>
additionally adds integration tests with reloading a schema with a broken one for `new`, `both_best_effort` and `both` query planner modes.
@lrlna lrlna enabled auto-merge (squash) August 16, 2024 13:29
@lrlna
Copy link
Member

lrlna commented Aug 16, 2024

@goto-bus-stop at the moment we get a WARN:

2024-08-16T13:45:45.605895Z WARN  Failed to initialize the new query planner, falling back to legacy: The supergraph schema failed to produce a valid API schema:  `experimental_query_planner_mode: new` or `both` cannot yet be used with progressive overrides. Remove uses of progressive overrides to try the experimental query planner, otherwise switch back to `legacy` or `both_best_effort`.",

Followed by a log saying the reload is complete:

2024-08-16T13:45:45.777923Z INFO  reload complete

Should we soften the wording a bit more in the falling back to legacy?

}

#[tokio::test(flavor = "multi_thread")]
async fn fed1_schema_with_both_best_effort_qp() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added reload to both_best_effort integration tests for all 3 features (fed1, context, progressive overrides) so we can also check that the log differs between setting the config to new and both_best_effort

use crate::integration::common::graph_os_enabled;
use crate::integration::IntegrationTest;

const PROMETHEUS_METRICS_CONFIG: &str = include_str!("telemetry/fixtures/prometheus.router.yaml");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added prometheus to the config so we can also check that the metrics are emitted for the reload integration tests.

@lrlna
Copy link
Member

lrlna commented Aug 16, 2024

This is ready for a re-review on Monday @goto-bus-stop. The failing CI is due to a transitive dependency that requires a rustc upgrade.

@lrlna lrlna requested a review from goto-bus-stop August 16, 2024 16:37
Comment on lines +1008 to +1023
if let Some(init_error_kind) = init_error_kind {
u64_counter!(
"apollo.router.lifecycle.query_planner.init",
"Rust query planner initialization",
1,
"init.error_kind" = init_error_kind,
"init.is_success" = false
);
} else {
u64_counter!(
"apollo.router.lifecycle.query_planner.init",
"Rust query planner initialization",
1,
"init.is_success" = true
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok for a metric attribute to be sometimes missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. but it could maybe be collapsed to a single attribute (init.error_kind = "none"). Though it's the same cardinality either way

@SimonSapin
Copy link
Contributor Author

We can make the warning less scary by downgrading it to info level and rewording the message to start with "Falling back to legacy QP" instead of having that part be in the middle of a long message

router
.assert_log_contains(
"could not create router: \
The supergraph schema failed to produce a valid API schema: \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mention of API schema here is not quite correct. It comes from apollo-router/src/error.rs:

impl From<FederationError> for ServiceBuildError {
    fn from(err: FederationError) -> Self {
        ServiceBuildError::ApiSchemaError(err)
    }
}

QP initialization is the only place where this enum variant is used (since API schema generation has moved to apollo_router::spec::Schema creation), so it should be renamed to QueryPlannerInit or something, and the message reworded

@goto-bus-stop goto-bus-stop dismissed their stale review August 20, 2024 08:40

blocking comment addressed

@SimonSapin SimonSapin disabled auto-merge August 20, 2024 09:03
@SimonSapin SimonSapin enabled auto-merge (squash) August 20, 2024 10:27
@SimonSapin SimonSapin changed the title Move QP compatibility checks into constructor Move QP compatibility checks into constructor and add metric Aug 20, 2024
@SimonSapin SimonSapin merged commit 4e6773c into dev Aug 20, 2024
12 of 13 checks passed
@SimonSapin SimonSapin deleted the simon/qp-lifecycle branch August 20, 2024 10:55
@abernix abernix mentioned this pull request Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants