Netflix / dgs-framework

GraphQL for Java with Spring Boot made easy.
https://netflix.github.io/dgs
Apache License 2.0
3.03k stars 286 forks source link

Add request size metric #1886

Closed kailyak closed 2 months ago

kailyak commented 2 months ago

Pull request checklist

Pull Request type

Changes in this PR

Added micrometer DistributionSummmary metric for graphQL request size.

Metric Name: gql.request.size
Tags: [
    - tag(gql.operation={operationTypeValue})
    - tag(gql.operation.name={operationNameValue})
    - tag(gql.query.complexity={qComplexityValue})
    - tag(gql.query.sig.hash={sigHashValue})
    ]

This metric is useful in measuring the request size for a graphql operation. The request size measurement is the size in bytes of the request body, obtained via the Content-Length header in the graphql request. This avoids needing to de/serialize data. A graphql request body contains: query, variables, and operationname. Via this approach, the Content-Type header for the response is not available at this point in the request processing. This change is scoped to the request size metric, as it is a metric that is useful in correlating graphql request sizes to graphql operations.

Tested via smoke tests and manual testing on ExampleApp.

Side note: An alternative approach considered was adding a web filter which would allow for more efficient measurement of both the request and response sizes but it is not standardized for graphql clients to send operation-name as a header. Presently getting the operation-name in the filter would require deserializing the http request body to get the "operationName" field.

kailyak commented 2 months ago

Thank you for the feedback, an internal implementation of these metrics is being explored first, closed out this PR.