Skip to content

Commit

Permalink
Our metrics are currently mutated at the supergraph service. This is …
Browse files Browse the repository at this point in the history
…a throwback from when the router service did not exist.

Move operation count metrics to the first thing that happens in the pipeline.
Note that this won't catch disconnects because they are reliant on the status code of the response, which will stop processing before the metric is incremented.

Fixes #3915
  • Loading branch information
bryn committed Sep 27, 2023
1 parent bca9d86 commit 97ba9f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 14 additions & 2 deletions apollo-router/src/axum_factory/axum_http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,10 @@ where
(license, Instant::now(), Arc::new(AtomicU64::new(0))),
license_handler,
))
.layer(TraceLayer::new_for_http().make_span_with(PropagatingMakeSpan { license }))
.layer(Extension(service_factory))
.layer(cors);
.layer(cors)
.layer(TraceLayer::new_for_http().make_span_with(PropagatingMakeSpan { license }))
.layer(middleware::from_fn(metrics_handler));

let route = endpoints_on_main_listener
.into_iter()
Expand All @@ -414,6 +415,17 @@ where
Ok(ListenAddrAndRouter(listener, route))
}

async fn metrics_handler<B>(request: Request<B>, next: Next<B>) -> Response {
let resp = next.run(request).await;
u64_counter!(
"apollo.router.operations",
"The number of graphql operations performed by the Router",
1,
"http.response.status_code" = resp.status().as_u16() as i64
);
resp
}

async fn license_handler<B>(
State((license, start, delta)): State<(LicenseState, Instant, Arc<AtomicU64>)>,
request: Request<B>,
Expand Down
12 changes: 0 additions & 12 deletions apollo-router/src/plugins/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,12 +833,6 @@ impl Telemetry {
if !parts.status.is_success() {
metric_attrs.push(KeyValue::new("error", parts.status.to_string()));
}
u64_counter!(
"apollo.router.operations",
"The number of graphql operations performed by the Router",
1,
"http.response.status_code" = parts.status.as_u16() as i64
);
let response = http::Response::from_parts(
parts,
once(ready(first_response.unwrap_or_default()))
Expand All @@ -850,12 +844,6 @@ impl Telemetry {
}
Err(err) => {
metric_attrs.push(KeyValue::new("status", "500"));
u64_counter!(
"apollo.router.operations",
"The number of graphql operations performed by the Router",
1,
"http.response.status_code" = 500
);
Err(err)
}
};
Expand Down

0 comments on commit 97ba9f6

Please sign in to comment.