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

Add a histogram metric tracking evaluated query plans #5875

Merged
merged 9 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changesets/feat_geal_evaluate_plan_count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Add a histogram metric tracking evaluated query plans ([PR #5875](https://github.com/apollographql/router/pull/5875))

The `supergraph.query_planning.experimental_plans_limit` option can be used to limit the number of query plans evaluated for a query, to reduce the time spent planning. When reaching that limit, the planner would still return a valid query plan, but maybe the most optimized one.
This adds the `apollo.router.query_planning.plan.evaluated_plans` histogram metric to track the number of evaluated query plans, giving more context to configure this option.

By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/5875
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5630,9 +5630,9 @@ dependencies = [

[[package]]
name = "router-bridge"
version = "0.6.0+v2.9.0"
version = "0.6.1+v2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96ef4910ade6753863c8437a76e88e236ab91688dcfe739d73417ae7848f3b92"
checksum = "b3be2d3ebbcbceb19dc813f5cee507295c673bb4e3f7a7cd532c8c27c95f92fc"
dependencies = [
"anyhow",
"async-channel 1.9.0",
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ regex = "1.10.5"
reqwest.workspace = true

# note: this dependency should _always_ be pinned, prefix the version with an `=`
router-bridge = "=0.6.0+v2.9.0"
router-bridge = "=0.6.1+v2.9.0"

rust-embed = { version = "8.4.0", features = ["include-exclude"] }
rustls = "0.21.12"
Expand Down
33 changes: 33 additions & 0 deletions apollo-router/src/query_planner/bridge_query_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,19 @@ impl PlannerMode {
if let Some(node) = &mut root_node {
init_query_plan_root_node(node)?;
}

Ok(PlanSuccess {
usage_reporting,
data: QueryPlanResult {
formatted_query_plan: Some(Arc::new(plan.to_string())),
query_plan: QueryPlan {
node: root_node.map(Arc::new),
},
evaluated_plan_count: plan
.statistics
.evaluated_plan_count
.clone()
.into_inner() as u64,
},
})
}
Expand Down Expand Up @@ -532,6 +538,7 @@ impl BridgeQueryPlanner {
QueryPlanResult {
query_plan: QueryPlan { node: Some(node) },
formatted_query_plan,
evaluated_plan_count,
},
mut usage_reporting,
} => {
Expand All @@ -549,6 +556,12 @@ impl BridgeQueryPlanner {
doc.clone()
};

u64_histogram!(
"apollo.router.query_planning.plan.evaluated_plans",
"Number of query plans evaluated for a query before choosing the best one",
evaluated_plan_count
);

let generated_usage_reporting = generate_usage_reporting(
&signature_doc.executable,
&doc.executable,
Expand Down Expand Up @@ -844,6 +857,7 @@ impl BridgeQueryPlanner {
pub struct QueryPlanResult {
pub(super) formatted_query_plan: Option<Arc<String>>,
pub(super) query_plan: QueryPlan,
pub(super) evaluated_plan_count: u64,
}

impl QueryPlanResult {
Expand Down Expand Up @@ -1595,4 +1609,23 @@ mod tests {
"init.is_success" = false
);
}

#[test(tokio::test)]
async fn test_evaluated_plans_histogram() {
async {
let _ = plan(
EXAMPLE_SCHEMA,
include_str!("testdata/query.graphql"),
include_str!("testdata/query.graphql"),
None,
PlanOptions::default(),
)
.await
.unwrap();

assert_histogram_exists!("apollo.router.query_planning.plan.evaluated_plans", u64);
}
.with_metrics()
.await;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The coprocessor operations metric has the following attributes:
- `apollo.router.query_planning.plan.duration` - Histogram of plan durations isolated to query planning time only.
- `apollo.router.query_planning.total.duration` - Histogram of plan durations including queue time.
- `apollo.router.query_planning.queued` - A gauge of the number of queued plans requests.
- `apollo.router.query_planning.plan.evaluated_plans` - Histogram of the number of evaluated query plans.
- `apollo.router.v8.heap.used` - heap memory used by V8, in bytes.
- `apollo.router.v8.heap.total` - total heap allocated by V8, in bytes.

Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ reqwest = { workspace = true, features = ["json", "blocking"] }
serde_json.workspace = true
tokio.workspace = true
# note: this dependency should _always_ be pinned, prefix the version with an `=`
router-bridge = "=0.6.0+v2.9.0"
router-bridge = "=0.6.1+v2.9.0"

[dev-dependencies]
anyhow = "1"
Expand Down
Loading