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

Update Apollo usage reporting to include persisted query metrics #7166

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

Conversation

bonnici
Copy link
Contributor

@bonnici bonnici commented Apr 3, 2025

  • Enables reporting of persisted query usage by PQ ID to Apollo
  • Refactors usage reporting generation (particularly related to errors) so that more Apollo reporting related code is moved into the apollo_studio_interop module

Review by commit is recommended.


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 Apr 3, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 766372c9bdbcceb184faa00d

This comment has been minimized.

@router-perf
Copy link

router-perf bot commented Apr 3, 2025

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

@bonnici bonnici force-pushed the njm/P-416/pq-reporting branch from 91e1978 to bf3cfcb Compare April 3, 2025 06:19
@bonnici bonnici force-pushed the njm/P-416/pq-reporting branch from c3081a3 to dd86724 Compare April 4, 2025 05:03
@bonnici bonnici changed the title WIP: Update Apollo usage reporting to include persisted query metrics Update Apollo usage reporting to include persisted query metrics Apr 7, 2025
@bonnici bonnici marked this pull request as ready for review April 7, 2025 06:19
@bonnici bonnici requested review from a team as code owners April 7, 2025 06:19
@bonnici bonnici requested a review from a team April 7, 2025 06:20
@bonnici bonnici force-pushed the njm/P-416/pq-reporting branch from c67f5ad to a96f8e9 Compare April 7, 2025 06:26
Copy link
Contributor

@rregitsky rregitsky left a comment

Choose a reason for hiding this comment

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

One main question about using an enum (last comment). Otherwise nits/clean-up suggestions.

Comment on lines 193 to 197
pub(crate) fn with_pq_id(&self, pq_id: Option<String>) -> UsageReporting {
let mut updated_usage_report = self.clone();
updated_usage_report.pq_id = pq_id;
updated_usage_report
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be a bit cleaner with struct update syntax:

pub(crate) fn with_pq_id(&self, pq_id: Option<String>) -> UsageReporting {  
  UsageReporting {
    pq_id,
    ..self.clone()
  }
}

Comment on lines 168 to 176
pub(crate) struct UsageReporting {
/// The `stats_report_key` is a unique identifier derived from schema and query.
/// Metric data sent to Studio must be aggregated
/// via grouped key of (`client_name`, `client_version`, `stats_report_key`).
pub(crate) stats_report_key: String,
/// The operation name, or None if there is no operation name
pub(crate) operation_name: Option<String>,
/// The normalized operation signature, or None if there is no valid signature
pub(crate) operation_signature: Option<String>,
/// The error key to use for the stats report, or None if there is no error
pub(crate) error_key: Option<String>,
/// The persisted query ID used to request this operation, or None if the query was not requested via PQ ID
pub(crate) pq_id: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be crazy to split this into an enum? I feel like we're already splitting logic a lot here in the for_error case.

enum UsageReporting {
  ERROR{key: String},
  OPERATION{name: String, signature: String, pq_id: Option<String>}
}

Copy link
Contributor Author

@bonnici bonnici Apr 9, 2025

Choose a reason for hiding this comment

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

I started going down this route but it makes code a bit too complicated. Also there is a possible future where we'll want to be able to have an error that still has referenced fields by type, or maybe an operation name/signature (via query metadata). We'd need to update the reporting code, but if we do that we'd definitely need to change back from an enum.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. I'm surprised the code ends up more complex that way. Every time I saw a for_error() in your code I was thinking "that'd look nice as a UsageReporting::Error() instead". And I'd imagine the internal logic is basically just doing match instead of the if/else on what attrs exist in the current code.

Understood on the possible future state -- In my head it'd be easy to add those init params if we need them to the error enum, but I haven't worked with enums in practice so I'll trust your experience on all this 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had another go and I think I figured it out

Comment on lines 191 to 207
pub(crate) fn with_pq_id(&self, maybe_pq_id: Option<String>) -> UsageReporting {
match self {
UsageReporting::Operation(op_details)
| UsageReporting::PersistedQuery {
operation_details: op_details,
..
} => match maybe_pq_id {
Some(pq_id) => UsageReporting::PersistedQuery {
operation_details: op_details.clone(),
persisted_query_id: pq_id,
},
None => UsageReporting::Operation(op_details.clone()),
},
// PQ ID has no effect on errors
UsageReporting::Error { .. } => self.clone(),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This fn feels a little weird to me that we're only maybe making a pq report. It would be a bit cleaner if we forced the caller to say if it's a pq or not (make pq_id non-optional), but that'd still be weird in the error case. Not sure of a better solution and I'm not super opinionated about it 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated it so PQ ID is required, which makes it a bit nicer.

@bonnici bonnici force-pushed the njm/P-416/pq-reporting branch from f8b67aa to 93702d5 Compare April 11, 2025 05:26
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.

3 participants