Issue 4632: fix exemplars calculation#5115
Merged
ruslan-mikhailov merged 5 commits intografana:mainfrom May 19, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes issue 4632 by correcting the exemplars calculation and ensuring at least one exemplar is requested per shard.
- Adjusted pagesPerRequest logic to search the entire block when its size is below the request threshold.
- Corrected the exemplarsPerShard computation and division order in backend request building to use pages as the numerator and totalRecords as the denominator.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| modules/frontend/search_sharder.go | Added early return for small blocks in page calculation. |
| modules/frontend/metrics_query_range_sharder.go | Updated exemplarsPerShard and backendRequests exemplar calculation. |
| modules/frontend/metrics_query_range_sharder_test.go | Added tests for various block and exemplar configurations. |
Comments suppressed due to low confidence (2)
modules/frontend/metrics_query_range_sharder.go:172
- The exemplarsPerShard calculation now correctly returns at least one exemplar per shard by applying the max function, but please verify that integer division does not inadvertently truncate values beyond the intended behavior.
return max(uint32(math.Ceil(float64(exemplars)*1.2))/total, 1) // require at least 1 exemplar per shard
modules/frontend/metrics_query_range_sharder.go:247
- The adjustment in the backendRequests function now correctly uses pages as the numerator and totalRecords as the denominator; please ensure that this division reflects the intended exemplar scaling for each block.
exemplars = max(uint32(float64(exemplars)*float64(pages)/float64(m.TotalRecords)), 1)
7937c11 to
3a0617f
Compare
zalegrala
reviewed
May 7, 2025
| "github.com/grafana/tempo/tempodb/backend" | ||
| ) | ||
|
|
||
| func FuzzExemplarsPerShard(f *testing.F) { |
zalegrala
approved these changes
May 7, 2025
Contributor
zalegrala
left a comment
There was a problem hiding this comment.
This looks correct to me. Nice work on the tests.
| }, | ||
| } | ||
| tenantID := "test-tenant" | ||
| targetBytesPerRequest := 1000 |
Contributor
There was a problem hiding this comment.
Leaving this static I suppose is desired because the test cases have blocksizes and records above and below this number to test each side of the calculation.
In case exemplars * 1.2 is less than total it could lead to dropping all exemplars
Search the entire block if it's small
3a0617f to
9dd34fe
Compare
Contributor
Author
|
+ rebase from latest master to resolve merge conflicts |
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.
What this PR does:
small block)Which issue(s) this PR fixes:
Fixes #4632
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]