Bucket gql.loaderBatchSize tag to limit metric cardinality#2277
Open
isaac-levine wants to merge 2 commits intoNetflix:masterfrom
Open
Bucket gql.loaderBatchSize tag to limit metric cardinality#2277isaac-levine wants to merge 2 commits intoNetflix:masterfrom
isaac-levine wants to merge 2 commits intoNetflix:masterfrom
Conversation
The gql.loaderBatchSize tag on the gql.dataLoader timer emits raw integer values (e.g. "152", "140", "10"), causing unbounded cardinality in Prometheus and other metrics backends. Every distinct batch size creates a separate time series. Bucket the batch size into predefined ranges [5, 10, 25, 50, 100, 200, 500, 1000, 2000, 5000, 10000] using the same approach already used for gql.query.complexity in ComplexityUtils. This limits the tag to at most 12 distinct values. Fixes Netflix#1974
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request checklist
Pull Request type
Summary
The
gql.loaderBatchSizetag on thegql.dataLoadertimer currently emits raw integer values (e.g."152","140","10","176"), creating a unique time series for every distinct batch size. This causes a cardinality explosion in Prometheus and other metrics backends, forcing people to strip the tag entirely viaMeterFilteras a workaround.This PR buckets the batch size into predefined ranges
[5, 10, 25, 50, 100, 200, 500, 1000, 2000, 5000, 10000], limiting the tag to at most 12 distinct values. This uses the same bucketing approach already used forgql.query.complexityinComplexityUtils.Before:
After:
Changes
BatchLoaderWithContextInterceptor.kt: AddedbucketBatchSize()function and applied it to theLOADER_BATCH_SIZEtag valueBatchLoaderWithContextInterceptorTest.kt: New unit test covering all bucket boundaries and verifying exactly 12 distinct output valuesNote on backward compatibility
This is a breaking change for dashboards or alerts that match on specific
gql.loaderBatchSizevalues. However, the current behavior is considered a bug as users are already stripping this tag entirely to avoid cardinality issues (see #1974). The bucketed values are strictly more useful than the raw integers for monitoring purposes.Fixes #1974