Fix: Align error rate samples to request rate samples#656
Open
tejhan wants to merge 1 commit into
Open
Conversation
Signed-off-by: tejhan-diallo <tejhan.diallo@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes incorrect Request & Error chart plotting by aligning Prometheus error-rate samples to request-rate samples by timestamp instead of array index, preventing misaligned/missing points when the two queries return different sample sets.
Changes:
- Build a timestamp-keyed map of error-rate samples (
errorByTimestamp) to align error values to request timestamps. - Update request/error series construction to use timestamp lookup with a
0fallback when an error sample is missing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+402
to
414
| // Create a map of error values keyed by timestamp for correct alignment with | ||
| // request values, since Prometheus may return different timestamps for each query. | ||
| const errorByTimestamp = new Map<number, number>(); | ||
| if (errorResults.length > 0 && errorResults[0].values) { | ||
| errorResults[0].values.forEach((v: [number, string]) => { | ||
| errorByTimestamp.set(v[0], safeParseFloat(v[1])); | ||
| }); | ||
| } | ||
| requestResults[0].values.forEach((v: [number, string]) => { | ||
| const timestamp = new Date(v[0] * 1000).toLocaleTimeString(); | ||
| const requestRate = safeParseFloat(v[1]); | ||
| const errorRate = | ||
| errorResults.length > 0 && errorResults[0].values[idx] | ||
| ? safeParseFloat(errorResults[0].values[idx][1]) | ||
| : 0; | ||
| const errorRate = errorByTimestamp.get(v[0]) ?? 0; | ||
|
|
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.
Description
The Request & Error chart joined the two Prometheus queries by array index. In scenarios where the error query returns a different # of samples or timestamps, the values would be unaligned, causing Error data to either incorrectly populate the chart or some data being dropped.
Type of Change
Changes Made
errorByTimestampto map return values specifically to timestamps.Testing
Test Cases
Describe the test cases that were run:
Screenshots/Videos
If applicable, add screenshots or videos to demonstrate the changes.
Checklist
Breaking Changes
If this is a breaking change, describe:
Performance Impact
Documentation Updates
Reviewer Notes
Any specific areas you'd like reviewers to focus on or questions you have.