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

Per-operation and client error metric #6443

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open

Conversation

bonnici
Copy link
Contributor

@bonnici bonnici commented Dec 12, 2024

This adds a new metric that tracks errors per operation, client, and error code. The metric in incremented whenever an error occurs and includes the following attributes:

  • client name
  • client version
  • apollo operation ID
  • error code
  • operation name
  • operation type (query/mutation/subscription)

This new metric is marked as experimental and disabled by default, since using it in a high-cardinality graph will likely mean that we'll hit OTel cardinality issues.


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Tests added and passing3
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Dec 12, 2024

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 2 changed, 0 removed
* graphos/reference/migration/from-router-v1.mdx
* graphos/reference/router/telemetry/instrumentation/standard-instruments.mdx

Build ID: d6eafb54039dc8c1ca88d695

URL: https://www.apollographql.com/docs/deploy-preview/d6eafb54039dc8c1ca88d695

@router-perf
Copy link

router-perf bot commented Dec 12, 2024

CI performance tests

  • connectors-const - Connectors stress test that runs with a constant number of users
  • const - Basic stress test that runs with a constant number of users
  • demand-control-instrumented - A copy of the step test, but with demand control monitoring and metrics enabled
  • demand-control-uninstrumented - A copy of the step test, but with demand control monitoring enabled
  • enhanced-signature - Enhanced signature enabled
  • events - Stress test for events with a lot of users and deduplication ENABLED
  • events_big_cap_high_rate - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity
  • events_big_cap_high_rate_callback - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity using callback mode
  • events_callback - Stress test for events with a lot of users and deduplication ENABLED in callback mode
  • events_without_dedup - Stress test for events with a lot of users and deduplication DISABLED
  • events_without_dedup_callback - Stress test for events with a lot of users and deduplication DISABLED using callback mode
  • extended-reference-mode - Extended reference mode enabled
  • large-request - Stress test with a 1 MB request payload
  • no-tracing - Basic stress test, no tracing
  • reload - Reload test over a long period of time at a constant rate of users
  • step-jemalloc-tuning - Clone of the basic stress test for jemalloc tuning
  • step-local-metrics - Field stats that are generated from the router rather than FTV1
  • step-with-prometheus - A copy of the step test with the Prometheus metrics exporter enabled
  • step - Basic stress test that steps up the number of users over time
  • xlarge-request - Stress test with 10 MB request payload
  • xxlarge-request - Stress test with 100 MB request payload

println!("temp_service: {temp_service}");

u64_counter!(
"temp.nick.apollo.router.operations.error",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 Cool to see a PoC in under 50 lines.

@bonnici bonnici changed the title POC work for error categorization metric Per-operation and client error metric Jan 14, 2025
@bonnici bonnici force-pushed the njm/P-1319/error-cat-poc branch from 05abe17 to 1582ded Compare January 15, 2025 05:55
@bonnici bonnici force-pushed the njm/P-1319/error-cat-poc branch from 1582ded to a46fee7 Compare January 15, 2025 20:25
@bonnici bonnici marked this pull request as ready for review January 15, 2025 20:30
@bonnici bonnici requested review from a team as code owners January 15, 2025 20:30
@bonnici bonnici requested a review from a team as a code owner January 15, 2025 20:37
fn count_errors(&self, errors: &[graphql::Error], context: &Context) {
let codes = errors
.iter()
.map(|e| e.extensions.get("code").and_then(|c| c.as_str()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC for errors without a code, it would count against the "empty" code e.g. code="". I think we could consider defining an explicit UNKNOWN code but it seems fine to support this with an empty code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is an empty string. I can easily add a fallback code but I think an empty string is just as good.

apollo-router/src/services/router/service.rs Outdated Show resolved Hide resolved
if matches!(self.oltp_error_metrics_mode, OtlpErrorMetricsMode::Enabled) {
let code_str = code.unwrap_or_default().to_string();
u64_counter!(
"apollo.router.operations.error",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that the Router team has asked for this to be a private metric - would that mean we would need to call it apollo_private.router.operations.error? Ultimately we don't want it to be, so I'm fine with it not being private at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pass the "private" filter regex and not pass the "public" filter regex, so it should be private. I don't really know how to test that thought because it is still coming through in prometheus.

    pub(crate) fn private<T: Into<MeterProvider>>(delegate: T) -> Self {
        FilterMeterProvider::builder()
            .delegate(delegate)
            .allow(
                Regex::new(
                    r"apollo\.(graphos\.cloud|router\.(operations?|lifecycle|config|schema|query|query_planning|telemetry|instance))(\..*|$)|apollo_router_uplink_fetch_count_total|apollo_router_uplink_fetch_duration_seconds",
                )
                .expect("regex should have been valid"),
            )
            .build()
    }

    pub(crate) fn public<T: Into<MeterProvider>>(delegate: T) -> Self {
        FilterMeterProvider::builder()
            .delegate(delegate)
            .deny(
                Regex::new(r"apollo\.router\.(config|entities|instance|operations\.(connectors|fetch|request_size|response_size)|schema\.connectors)(\..*|$)")
                    .expect("regex should have been valid"),
            )
            .build()
    }

@timbotnik
Copy link
Contributor

This is looking pretty good to me.

Copy link
Contributor

@timbotnik timbotnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good from my side.

Base automatically changed from next to dev January 20, 2025 15:02
@bonnici bonnici enabled auto-merge (squash) January 23, 2025 05:50
@bonnici bonnici disabled auto-merge January 23, 2025 05:53
@SimonSapin
Copy link
Contributor

error[E0432]: unresolved import `opentelemetry_api`
  --> apollo-router/src/services/router/tests.rs:12:5
   |
12 | use opentelemetry_api::KeyValue;
   |     ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `opentelemetry_api`

The dependency on opentelemetry_api was removed in #6493. In dev I see other files with use opentelemetry::KeyValue;, maybe that's what you need?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants