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 metric tracking coprocessor latency #3513

Merged
merged 6 commits into from
Aug 9, 2023
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
17 changes: 17 additions & 0 deletions .changesets/feat_geal_coprocessor_latency_metric.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### add a metric tracking coprocessor latency ([Issue #2924](https://github.com/apollographql/router/issues/2924))

Introduces a new metric for the router:

```
apollo.router.operations.coprocessor.duration
```

It has one attributes:

```
coprocessor.stage: string (RouterRequest, RouterResponse, SubgraphRequest, SubgraphResponse)
```

It is an histogram metric tracking the time spent calling into the coprocessor

By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/3513
29 changes: 29 additions & 0 deletions apollo-router/src/plugins/coprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::ops::ControlFlow;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;

use bytes::Bytes;
use futures::future::ready;
Expand Down Expand Up @@ -557,8 +558,15 @@ where

tracing::debug!(?payload, "externalized output");
let guard = request.context.enter_active_request();
let start = Instant::now();
let co_processor_result = payload.call(http_client, &coprocessor_url).await;
let duration = start.elapsed().as_secs_f64();
drop(guard);
tracing::info!(
histogram.apollo.router.operations.coprocessor.duration = duration,
coprocessor.stage = %PipelineStep::RouterRequest,
);

tracing::debug!(?co_processor_result, "co-processor returned");
let co_processor_output = co_processor_result?;

Expand Down Expand Up @@ -706,8 +714,15 @@ where
// Second, call our co-processor and get a reply.
tracing::debug!(?payload, "externalized output");
let guard = response.context.enter_active_request();
let start = Instant::now();
let co_processor_result = payload.call(http_client.clone(), &coprocessor_url).await;
let duration = start.elapsed().as_secs_f64();
drop(guard);
tracing::info!(
histogram.apollo.router.operations.coprocessor.duration = duration,
coprocessor.stage = %PipelineStep::RouterResponse,
);

tracing::debug!(?co_processor_result, "co-processor returned");
let co_processor_output = co_processor_result?;

Expand Down Expand Up @@ -871,8 +886,15 @@ where

tracing::debug!(?payload, "externalized output");
let guard = request.context.enter_active_request();
let start = Instant::now();
let co_processor_result = payload.call(http_client, &coprocessor_url).await;
let duration = start.elapsed().as_secs_f64();
drop(guard);
tracing::info!(
histogram.apollo.router.operations.coprocessor.duration = duration,
coprocessor.stage = %PipelineStep::SubgraphRequest,
);

tracing::debug!(?co_processor_result, "co-processor returned");
let co_processor_output = co_processor_result?;
validate_coprocessor_output(&co_processor_output, PipelineStep::SubgraphRequest)?;
Expand Down Expand Up @@ -1003,8 +1025,15 @@ where

tracing::debug!(?payload, "externalized output");
let guard = response.context.enter_active_request();
let start = Instant::now();
let co_processor_result = payload.call(http_client, &coprocessor_url).await;
let duration = start.elapsed().as_secs_f64();
drop(guard);
tracing::info!(
histogram.apollo.router.operations.coprocessor.duration = duration,
coprocessor.stage = %PipelineStep::SubgraphResponse,
);

tracing::debug!(?co_processor_result, "co-processor returned");
let co_processor_output = co_processor_result?;

Expand Down
1 change: 1 addition & 0 deletions docs/source/configuration/metrics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ All cache metrics listed above have the following attributes:
#### Coprocessor

- `apollo_router_operations_coprocessor_total` - Total operations with co-processors enabled.
- `apollo_router_operations_coprocessor.duration` - Time spent waiting for the coprocessor to answer, in seconds

The coprocessor operations metric has the following attributes:

Expand Down