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

graphql: metrics for validation and parsing phases #3760

Merged
merged 1 commit into from
Jul 27, 2022

Conversation

kamilkisiela
Copy link
Contributor

@kamilkisiela kamilkisiela commented Jul 21, 2022

New Prometheus metrics

  • query_parsing_time
  • query_validation_time

Closes #3752

@kamilkisiela kamilkisiela force-pushed the kamil-graphql-metrics branch from 92d5c46 to 841e8e0 Compare July 21, 2022 12:40
@leoyvens
Copy link
Collaborator

Seems there are build issues.

@kamilkisiela
Copy link
Contributor Author

kamilkisiela commented Jul 21, 2022

I'm trying to add parsing and validation time metrics to GraphQLServiceMetrics now, figuring out how to pass Duration from Query to handle_graphql_query().

This way it's all in one place.

@kamilkisiela kamilkisiela force-pushed the kamil-graphql-metrics branch from 841e8e0 to b2cd397 Compare July 21, 2022 13:36
@kamilkisiela kamilkisiela changed the title graphql: metrics for the GraphQL validation phase graphql: metrics for validation and parsing phases Jul 21, 2022
@leoyvens
Copy link
Collaborator

Tests are not passing.

@kamilkisiela kamilkisiela requested a review from leoyvens July 21, 2022 16:20
@@ -45,12 +46,14 @@ pub type Data = Object;
/// A collection of query results that is serialized as a single result.
pub struct QueryResults {
results: Vec<Arc<QueryResult>>,
pub validation_time: Option<Duration>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not great that this field had to be added. Could perhaps the GraphQlRunner have access to the GraphQLServiceMetrics and register the metric immediately after taking the measurement?

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 created GraphQLMetrics that is passed to GraphQlRunner and is responsible for all metrics related to GraphQL:

  • query_execution_time
  • query_parsing_time
  • query_validation_time
  • query_result_size
  • query_result_max

@kamilkisiela kamilkisiela force-pushed the kamil-graphql-metrics branch 3 times, most recently from 81dc87a to e525140 Compare July 22, 2022 10:20
Copy link
Collaborator

@leoyvens leoyvens left a comment

Choose a reason for hiding this comment

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

Nice refactor!

Comment on lines 50 to 53
pub trait GraphQLMetrics: Send + Sync + 'static {
fn observe_query_execution(&self, duration: Duration, results: &QueryResults) -> ();
fn observe_query_parsing(&self, duration: Duration, results: &QueryResults) -> ();
fn observe_query_validation(&self, duration: Duration, id: &DeploymentHash) -> ();
Copy link
Collaborator

Choose a reason for hiding this comment

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

The -> () can be omitted.

Suggested change
pub trait GraphQLMetrics: Send + Sync + 'static {
fn observe_query_execution(&self, duration: Duration, results: &QueryResults) -> ();
fn observe_query_parsing(&self, duration: Duration, results: &QueryResults) -> ();
fn observe_query_validation(&self, duration: Duration, id: &DeploymentHash) -> ();
pub trait GraphQLMetrics: Send + Sync + 'static {
fn observe_query_execution(&self, duration: Duration, results: &QueryResults);
fn observe_query_parsing(&self, duration: Duration, results: &QueryResults);
fn observe_query_validation(&self, duration: Duration, id: &DeploymentHash);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, did

@@ -120,7 +120,7 @@ where
let validated = ValidatedRequest::new(body, &req_parts.headers)?;
let query = validated.query;

let query = match PreparedQuery::new(&self.logger, schema, None, query, None, 100) {
let query = match PreparedQuery::new(&self.logger, schema, None, query, None, 100, None) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to use a fake metrics collector like there is for tests, than have this be an option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@leoyvens
Copy link
Collaborator

@kamilkisiela this just needs to be rebased.

@kamilkisiela kamilkisiela force-pushed the kamil-graphql-metrics branch from cf91af7 to a90028a Compare July 27, 2022 07:56
@kamilkisiela
Copy link
Contributor Author

@leoyvens rebased

@leoyvens leoyvens merged commit 38c60e6 into master Jul 27, 2022
@leoyvens leoyvens deleted the kamil-graphql-metrics branch July 27, 2022 13:47
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.

Metrics are missing for GraphQL validations
2 participants