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

feat(engine-v1): Add operation metrics #1714

Merged
merged 1 commit into from
May 14, 2024
Merged

Conversation

Finistere
Copy link
Member

Description

Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context.

Type of change

  • πŸ’” Breaking
  • πŸš€ Feature
  • πŸ› Fix
  • πŸ› οΈ Tooling
  • πŸ”¨ Refactoring
  • πŸ§ͺ Test
  • πŸ“¦ Dependency
  • πŸ“– Requires documentation update

Copy link

linear bot commented May 13, 2024

@Finistere Finistere marked this pull request as ready for review May 14, 2024 07:38
@Finistere Finistere requested a review from a team as a code owner May 14, 2024 07:38
@Finistere Finistere requested a review from jakubadamw May 14, 2024 07:38
let extensions = self.create_extensions(session_data.clone());
let gql_span = GqlRequestSpan::new().into_span();
let normalized_query = operation_normalizer::normalize(request.query(), request.operation_name()).ok();
Copy link
Member

Choose a reason for hiding this comment

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

Not much we can do to avoid it I supppose but wonder what impact adding this is going to have on the wasm size...

Copy link
Member Author

Choose a reason for hiding this comment

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

we do it already in the worker anyway already, so won't change anything

Copy link
Member

Choose a reason for hiding this comment

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

We do it in the gateway currently, but this is going to run in the executor, no? Hence wondering

Copy link
Member Author

Choose a reason for hiding this comment

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

hum good point, you're right

Comment on lines +144 to +162
let normalized_query = operation_normalizer::normalize(request.query(), request.operation_name()).ok();
let (response, headers) = self.execute_with_auth(ctx, request, auth).await?;
if let Some((operation, normalized_query)) = response.graphql_operation.clone().zip(normalized_query) {
self.operation_metrics.record(
grafbase_tracing::metrics::GraphqlOperationMetricsAttributes {
ty: match operation.r#type {
common_types::OperationType::Query { .. } => "query",
common_types::OperationType::Mutation => "mutation",
common_types::OperationType::Subscription => "subscription",
},
name: operation.name,
normalized_query_hash: blake3::hash(normalized_query.as_bytes()).into(),
normalized_query,
has_errors: !response.errors.is_empty(),
cache_status: headers
.get(X_GRAFBASE_CACHE)
.and_then(|v| v.to_str().ok().map(|s| s.to_string())),
},
start.elapsed(),
Copy link
Member

Choose a reason for hiding this comment

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

I assume I'm missing something: why are we doing this here and in the engine?

Copy link
Member Author

Choose a reason for hiding this comment

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

because gateway-core deals with the caching so need to be here, but the stream interface doesn't let me retrieve the necessary information. So need to do in the engine for stream

Copy link
Member Author

Choose a reason for hiding this comment

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

The alternative would be imposing constraints on Executor::StreamingResponse to be able to retrieve headers and send all the metadata through it

Copy link
Member

Choose a reason for hiding this comment

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

So need to do in the engine for stream

Ah, that'll be what I'm missing - didn't notice it was stream only

@Finistere Finistere force-pushed the gb-6698-add-engine-v1-metrics branch from 7d50ab2 to e10c96f Compare May 14, 2024 09:15
@Finistere Finistere merged commit b4dfbb9 into main May 14, 2024
@Finistere Finistere deleted the gb-6698-add-engine-v1-metrics branch May 14, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants