-
Notifications
You must be signed in to change notification settings - Fork 585
Issue 4632: fix exemplars calculation #5115
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
Issue 4632: fix exemplars calculation #5115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
"github.com/grafana/tempo/tempodb/backend" | ||
) | ||
|
||
func FuzzExemplarsPerShard(f *testing.F) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for the fuzz.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks correct to me. Nice work on the tests.
}, | ||
} | ||
tenantID := "test-tenant" | ||
targetBytesPerRequest := 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
+ rebase from latest master to resolve merge conflicts |
* [bugfix] Request at least 1 exemplar per shard In case exemplars * 1.2 is less than total it could lead to dropping all exemplars * Test buildBackendRequests * [bugfix] Correct exemplars calculation * [bugfix] Correct calculation of required pages per request Search the entire block if it's small * Changelog
What this PR does:
small block
)Which issue(s) this PR fixes:
Fixes #4632
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]