-
Notifications
You must be signed in to change notification settings - Fork 330
Cooperative Cancellation #7604
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
Merged
Merged
Cooperative Cancellation #7604
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
fe1e0f5
add cooperative cancellation and timeout test
Velfi 6b0a5ef
update test name
Velfi f093728
update insta snapshots
Velfi dff11b5
use enum for coop cancellation config
Velfi ca5e396
add cancellation test
Velfi 822ef3a
add measurement mode
Velfi e8f6c38
add client drop test
Velfi 9d77cf4
add proper metric and span support for CC
Velfi 176b20d
undo histogram breaking change
Velfi 3e73bd1
run formatter
Velfi 459fc56
fix clippy lints
Velfi f88b253
fix bug in CC impl
Velfi 6502284
prepare for PR review
Velfi 937a30b
add changeset
Velfi f8139fe
Merge remote-tracking branch 'origin/dev' into zelda/feature-cooperat…
Velfi e36f9ae
remove leftover fixtures
Velfi 2080e00
Update apollo-router/src/query_planner/caching_query_planner.rs
Velfi 0c66b09
respond to PR comments
Velfi bb2a1de
Merge branch 'dev' into zelda/feature-cooperative-cancellation
Velfi bf6575b
respond to PR comments
Velfi f9ecebd
Merge branch 'dev' into zelda/feature-cooperative-cancellation
Velfi 91692b2
fix snapshot test
Velfi 9cdde3f
add missing description
Velfi a39455e
fix snapshot test
Velfi 09dd3ae
fix clippy lint
Velfi 54a0d97
put back what was accidentally deleted
Velfi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
.changesets/feat_zelda_feature_cooperative_cancellation.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ## Cooperative Cancellation for Query Planning | ||
|
|
||
| This release introduces cooperative cancellation support for query planning operations. This feature allows the router | ||
| to gracefully handle query planning timeouts and cancellations, improving resource utilization. | ||
| Metrics are emitted for cooperative cancellation: | ||
|
|
||
| - Records the "outcome" of query planning on the `apollo.router.query_planning.plan.duration` metric. | ||
| - Records the "outcome" of query planning on the `query_planning` span. | ||
|
|
||
| ### Example | ||
|
|
||
| Configuring a timeout in Measure Mode: | ||
| ```yaml | ||
| supergraph: | ||
| query_planning: | ||
| experimental_cooperative_cancellation: | ||
| enabled: true | ||
| mode: measure | ||
| timeout: 1s | ||
| ``` | ||
|
|
||
| By [@Velfi](https://github.com/Velfi) in https://github.com/apollographql/router/pull/7604 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
apollo-router/src/configuration/cooperative_cancellation.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use std::time::Duration; | ||
|
|
||
| use schemars::JsonSchema; | ||
| use serde::Deserialize; | ||
| use serde::Serialize; | ||
|
|
||
| use crate::configuration::mode::Mode; | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)] | ||
| #[serde(deny_unknown_fields, default)] | ||
| pub(crate) struct CooperativeCancellation { | ||
| /// When true, cooperative cancellation is enabled. | ||
| enabled: bool, | ||
| /// When enabled, this sets whether the router will cancel query planning or | ||
| /// merely emit a metric when it would have happened. | ||
| mode: Mode, | ||
| #[serde(deserialize_with = "humantime_serde::deserialize")] | ||
| #[serde(serialize_with = "humantime_serde::serialize")] | ||
| #[schemars(with = "Option<String>")] | ||
| /// Enable timeout for query planning. | ||
| timeout: Option<Duration>, | ||
| } | ||
|
|
||
| impl Default for CooperativeCancellation { | ||
| fn default() -> Self { | ||
| Self { | ||
| enabled: true, | ||
| mode: Mode::Measure, | ||
| timeout: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl CooperativeCancellation { | ||
| /// Returns the timeout, if configured. | ||
| pub(crate) fn timeout(&self) -> Option<Duration> { | ||
| self.timeout | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| /// Create a new `CooperativeCancellation` config in enforcement mode. | ||
| pub(crate) fn enabled() -> Self { | ||
| Self { | ||
| enabled: true, | ||
| mode: Mode::Enforce, | ||
| timeout: None, | ||
| } | ||
| } | ||
|
|
||
| /// Returns true if cooperative cancellation is enabled. | ||
| pub(crate) fn is_enabled(&self) -> bool { | ||
| self.enabled | ||
| } | ||
|
|
||
| /// Returns true if this config is in measure mode. | ||
| pub(crate) fn is_measure_mode(&self) -> bool { | ||
| self.mode.is_measure_mode() | ||
| } | ||
|
|
||
| /// Returns true if this config is in enforce mode. | ||
| pub(crate) fn is_enforce_mode(&self) -> bool { | ||
| self.mode.is_enforce_mode() | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| /// Create a new `CooperativeCancellation` config in enforcement mode with a timeout. | ||
| pub(crate) fn enabled_with_timeout(timeout: Duration) -> Self { | ||
| Self { | ||
| enabled: true, | ||
| mode: Mode::Enforce, | ||
| timeout: Some(timeout), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use schemars::JsonSchema; | ||
| use serde::Deserialize; | ||
| use serde::Serialize; | ||
|
|
||
| // Don't add a default here. Instead, Default should be implemented for | ||
| // individual cases of Mode<T>. | ||
| #[derive(Debug, Clone, Copy, Deserialize, Serialize, JsonSchema)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub(crate) enum Mode { | ||
| Measure, | ||
| Enforce, | ||
| } | ||
|
|
||
| impl Mode { | ||
| /// Returns true if this config is in measure mode. | ||
| pub(crate) fn is_measure_mode(&self) -> bool { | ||
| matches!(self, Mode::Measure) | ||
| } | ||
|
|
||
| /// Returns true if this config is in enforce mode. | ||
| pub(crate) fn is_enforce_mode(&self) -> bool { | ||
| matches!(self, Mode::Enforce) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.