fix: prevent native histogram double-rebuild race condition#1113
Open
nicwestvold wants to merge 4 commits intomainfrom
Open
fix: prevent native histogram double-rebuild race condition#1113nicwestvold wants to merge 4 commits intomainfrom
nicwestvold wants to merge 4 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a race in GmdVizPanel where two async detection paths (metadata vs. returned dataframe type) could both trigger a rebuild when a metric is a native histogram, and adds defensive handling in query builders so persisted configs referencing unknown PromQL functions don’t crash query construction.
Changes:
- Add guards in
GmdVizPanelto prevent redundant “switch-to-heatmap” rebuilds and unsubscribe deterministically on firstLoadingState.Done. - Add runtime checks around
PROMQL_FUNCTIONS.get(fn)in timeseries/stat/percentiles query param builders, logging and skipping unknown functions. - Add/extend unit tests for the histogram race guard paths and unknown-function handling.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/shared/GmdVizPanel/GmdVizPanel.tsx | Adds guards + earlier unsubscribe to prevent double-rebuild when native histogram is detected via two async paths. |
| src/shared/GmdVizPanel/tests/GmdVizPanel.test.ts | New tests covering the two-path guard behavior and unsubscribe behavior. |
| src/shared/GmdVizPanel/types/timeseries/getTimeseriesQueryRunnerParams.ts | Skips unknown PromQL function entries and logs a warning instead of crashing. |
| src/shared/GmdVizPanel/types/timeseries/tests/getTimeseriesQueryRunnerParams.test.ts | Adds test asserting unknown PromQL functions are skipped and warning is logged. |
| src/shared/GmdVizPanel/types/stat/getStatQueryRunnerParams.ts | Same unknown-function guard + warning for stat query builder. |
| src/shared/GmdVizPanel/types/stat/tests/getStatQueryRunnerParams.test.ts | Adds unknown-function test coverage for stat query builder. |
| src/shared/GmdVizPanel/types/percentiles/getPercentilesQueryRunnerParams.ts | Adds unknown-function guards for both histogram and non-histogram percentile query paths. |
| src/shared/GmdVizPanel/types/percentiles/tests/getPercentilesQueryRunnerParams.test.ts | Adds tests for unknown-function handling in both percentile query paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/shared/GmdVizPanel/types/timeseries/__tests__/getTimeseriesQueryRunnerParams.test.ts
Show resolved
Hide resolved
src/shared/GmdVizPanel/types/stat/__tests__/getStatQueryRunnerParams.test.ts
Show resolved
Hide resolved
src/shared/GmdVizPanel/types/percentiles/__tests__/getPercentilesQueryRunnerParams.test.ts
Show resolved
Hide resolved
src/shared/GmdVizPanel/types/percentiles/__tests__/getPercentilesQueryRunnerParams.test.ts
Show resolved
Hide resolved
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
Native histogram metrics could fail to load:
subscribeToStateChangessetpanelConfig.type = 'heatmap'but omittedmetricType: 'native-histogram', so queries never updated. A secondary race allowed both detection paths to independently triggerbuildVizPanel().📖 Changes
metricType: 'native-histogram'in thesubscribeToStateChangespaththis.state.panelConfigat resolution timeDoneevent unconditionally!assertions in query builders with guards that warn and skip🧪 How to test?
GmdVizPanel.test.tsand the three query builder test files