config: validate remote_write queue_config fields#18209
Open
Sanchit2662 wants to merge 1 commit intoprometheus:mainfrom
Open
config: validate remote_write queue_config fields#18209Sanchit2662 wants to merge 1 commit intoprometheus:mainfrom
Sanchit2662 wants to merge 1 commit intoprometheus:mainfrom
Conversation
Signed-off-by: Sanchit2662 <[email protected]>
Author
|
Hi @grobinson-grafana , Adds missing queue_config validation to catch misconfigurations (like max_samples_per_send: 0) at load time instead of panicking at runtime. Happy to adjust if needed, thanks! |
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.
Summary
While working with remote write configurations, I noticed that
queue_configparameters had zero validation. This meant users could accidentally setmax_samples_per_send: 0(or other invalid combinations) and Prometheus would accept the config silently—only to panic at runtime with an integer divide-by-zero error when the queue manager started.The panic happens in
newQueue()when calculatingcapacity / batchSizewithbatchSize=0. Beyond the crash, other misconfigurations likemin_shards > max_shardsormax_backoff < min_backoffwere also silently accepted, leading to undefined runtime behavior.This PR adds proper validation to catch these issues at config load time.
Fix
Added
QueueConfig.Validate()method inconfig/config.gothat checks:max_shards,min_shards,max_samples_per_send,capacity)min_shards≤max_shardsmax_backoff≥min_backoffThe validation is called from
RemoteWriteConfig.UnmarshalYAML()so invalid configs fail fast during startup.Key changes:
config/config.go— Added validation method (~20 LOC):Also added 3 test cases in
config/config_test.goand corresponding bad config YAML files inconfig/testdata/covering each validation path.Does this PR introduce a user-facing change?