Skip to content

Commit

Permalink
Add a histogram metric tracking evaluated query plans
Browse files Browse the repository at this point in the history
the `experimental_plans_limit` option can be used to limit the number of query plans evaluated for a query, but there was no way to know what is a reasonable value for that option. This adds a histogram metric tracking the number of evaluated query plans, which should give more context to configure this.
  • Loading branch information
Geal committed Aug 23, 2024
1 parent a0a98d4 commit ae3f9ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
27 changes: 25 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ dependencies = [
"reqwest",
"rhai",
"rmp",
"router-bridge",
"router-bridge 0.5.30+v2.8.3 (git+https://github.com/apollographql/federation-rs?branch=geal/plan-count)",
"rowan",
"rstack",
"rust-embed",
Expand Down Expand Up @@ -5803,6 +5803,29 @@ dependencies = [
"which",
]

[[package]]
name = "router-bridge"
version = "0.5.30+v2.8.3"
source = "git+https://github.com/apollographql/federation-rs?branch=geal/plan-count#2883d18d519b13a0d6830898c0eb197b59ad4571"
dependencies = [
"anyhow",
"async-channel 1.9.0",
"deno_console",
"deno_core",
"deno_url",
"deno_web",
"deno_webidl",
"rand 0.8.5",
"serde",
"serde_json",
"thiserror",
"tokio",
"tower",
"tower-service",
"tracing",
"which",
]

[[package]]
name = "router-fuzz"
version = "0.0.0"
Expand All @@ -5818,7 +5841,7 @@ dependencies = [
"libfuzzer-sys",
"log",
"reqwest",
"router-bridge",
"router-bridge 0.5.30+v2.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"schemars",
"serde",
"serde_json",
Expand Down
3 changes: 2 additions & 1 deletion apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ regex = "1.10.5"
reqwest.workspace = true

# note: this dependency should _always_ be pinned, prefix the version with an `=`
router-bridge = "=0.5.30+v2.8.3"
#router-bridge = "=0.5.30+v2.8.3"
router-bridge = { git = "https://github.com/apollographql/federation-rs", branch = "geal/plan-count" }

rust-embed = { version = "8.4.0", features = ["include-exclude"] }
rustls = "0.21.12"
Expand Down
10 changes: 10 additions & 0 deletions apollo-router/src/query_planner/bridge_query_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ impl PlannerMode {
query_plan: QueryPlan {
node: root_node.map(Arc::new),
},
evaluated_plan_count: plan.statistics.evaluated_plan_count.into_inner()
as u64,
},
})
}
Expand Down Expand Up @@ -554,13 +556,20 @@ impl BridgeQueryPlanner {
QueryPlanResult {
query_plan: QueryPlan { node: Some(node) },
formatted_query_plan,
evaluated_plan_count,
},
mut usage_reporting,
} => {
if let Some(sig) = operation_signature {
usage_reporting.stats_report_key = sig;
}

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

if matches!(
self.configuration
.experimental_apollo_metrics_generation_mode,
Expand Down Expand Up @@ -949,6 +958,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

0 comments on commit ae3f9ec

Please sign in to comment.