From 059143fec227528e0edbf648d113961137c8e6d3 Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Fri, 21 Jul 2023 10:36:14 +0100 Subject: [PATCH 1/3] Add coprocessor metrics Introduces a new metric for the router: ``` apollo.router.operations.coprocessor ``` It has two attributes: ``` coprocessor.stage: string (RouterRequest, RouterResponse, SubgraphRequest, SubgraphResponse) coprocessor.succeeded: bool ``` fixes: https://github.com/apollographql/router-private/issues/177 --- apollo-router/src/plugins/coprocessor.rs | 52 ++++++++++++++++++++---- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/apollo-router/src/plugins/coprocessor.rs b/apollo-router/src/plugins/coprocessor.rs index 09fea6aee7..cf41be8a39 100644 --- a/apollo-router/src/plugins/coprocessor.rs +++ b/apollo-router/src/plugins/coprocessor.rs @@ -285,7 +285,8 @@ impl RouterStage { let sdl = sdl.clone(); async move { - process_router_request_stage( + let mut succeeded = true; + let result = process_router_request_stage( http_client, coprocessor_url, sdl, @@ -294,11 +295,19 @@ impl RouterStage { ) .await .map_err(|error| { + succeeded = false; tracing::error!( "external extensibility: router request stage error: {error}" ); error - }) + }); + tracing::info!( + monotonic_counter.apollo.router.operations.coprocessor = 1u64, + coprocessor.stage = %PipelineStep::RouterRequest, + coprocessor.succeeded = succeeded, + "Total operations with co-processors enabled" + ); + result } }) }); @@ -314,7 +323,8 @@ impl RouterStage { async move { let response: router::Response = fut.await?; - process_router_response_stage( + let mut succeeded = true; + let result = process_router_response_stage( http_client, coprocessor_url, sdl, @@ -323,11 +333,19 @@ impl RouterStage { ) .await .map_err(|error| { + succeeded = false; tracing::error!( "external extensibility: router response stage error: {error}" ); error - }) + }); + tracing::info!( + monotonic_counter.apollo.router.operations.coprocessor = 1u64, + coprocessor.stage = %PipelineStep::RouterResponse, + coprocessor.succeeded = succeeded, + "Total operations with co-processors enabled" + ); + result } }) }); @@ -400,7 +418,8 @@ impl SubgraphStage { let request_config = request_config.clone(); async move { - process_subgraph_request_stage( + let mut succeeded = true; + let result = process_subgraph_request_stage( http_client, coprocessor_url, service_name, @@ -409,11 +428,19 @@ impl SubgraphStage { ) .await .map_err(|error| { + succeeded = false; tracing::error!( "external extensibility: subgraph request stage error: {error}" ); error - }) + }); + tracing::info!( + monotonic_counter.apollo.router.operations.coprocessor = 1u64, + coprocessor.stage = %PipelineStep::SubgraphRequest, + coprocessor.succeeded = succeeded, + "Total operations with co-processors enabled" + ); + result } }) }); @@ -430,7 +457,8 @@ impl SubgraphStage { async move { let response: subgraph::Response = fut.await?; - process_subgraph_response_stage( + let mut succeeded = true; + let result = process_subgraph_response_stage( http_client, coprocessor_url, service_name, @@ -439,11 +467,19 @@ impl SubgraphStage { ) .await .map_err(|error| { + succeeded = false; tracing::error!( "external extensibility: subgraph response stage error: {error}" ); error - }) + }); + tracing::info!( + monotonic_counter.apollo.router.operations.coprocessor = 1u64, + coprocessor.stage = %PipelineStep::SubgraphResponse, + coprocessor.succeeded = succeeded, + "Total operations with co-processors enabled" + ); + result } }) }); From 6500fb76698a2402bab37308950f795eeb3e0729 Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Fri, 21 Jul 2023 10:46:39 +0100 Subject: [PATCH 2/3] add changeset --- .../feat_garypen_177_coprocessor_metrics.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .changesets/feat_garypen_177_coprocessor_metrics.md diff --git a/.changesets/feat_garypen_177_coprocessor_metrics.md b/.changesets/feat_garypen_177_coprocessor_metrics.md new file mode 100644 index 0000000000..b03777ed5c --- /dev/null +++ b/.changesets/feat_garypen_177_coprocessor_metrics.md @@ -0,0 +1,16 @@ +### Add coprocessor metrics ([PR #3483](https://github.com/apollographql/router/pull/3483)) + +Introduces a new metric for the router: + +``` +apollo.router.operations.coprocessor +``` + +It has two attributes: + +``` +coprocessor.stage: string (RouterRequest, RouterResponse, SubgraphRequest, SubgraphResponse) +coprocessor.succeeded: bool +``` + +By [@garypen](https://github.com/garypen) in https://github.com/apollographql/router/pull/3483 \ No newline at end of file From c95cc0b28be97d31cd2e8faf1ec0875017961165 Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Fri, 21 Jul 2023 10:53:16 +0100 Subject: [PATCH 3/3] document new metric --- docs/source/configuration/metrics.mdx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/source/configuration/metrics.mdx b/docs/source/configuration/metrics.mdx index 6b0b637ac2..e00779253a 100644 --- a/docs/source/configuration/metrics.mdx +++ b/docs/source/configuration/metrics.mdx @@ -89,6 +89,15 @@ All cache metrics listed above have the following attributes: - `kind`: the cache being queried (`apq`, `query planner`, `introspection`) - `storage`: The backend storage of the cache (`memory`, `redis`) +#### Coprocessor + +- `apollo_router_operations_coprocessor_total` - Total operations with co-processors enabled. + +The coprocessor operations metric has the following attributes: + +- `coprocessor.stage`: string (`RouterRequest`, `RouterResponse`, `SubgraphRequest`, `SubgraphResponse`) +- `coprocessor.succeeded`: bool + #### Performance - `apollo_router_processing_time` - Time spent processing a request (outside of waiting for external or subgraph requests) in seconds.