Thanks to visit codestin.com
Credit goes to github.com

Skip to content

config: validate remote_write queue_config fields#18209

Open
Sanchit2662 wants to merge 1 commit intoprometheus:mainfrom
Sanchit2662:validate-remote-write-queue-config
Open

config: validate remote_write queue_config fields#18209
Sanchit2662 wants to merge 1 commit intoprometheus:mainfrom
Sanchit2662:validate-remote-write-queue-config

Conversation

@Sanchit2662
Copy link

@Sanchit2662 Sanchit2662 commented Mar 1, 2026

Summary

While working with remote write configurations, I noticed that queue_config parameters had zero validation. This meant users could accidentally set max_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 calculating capacity / batchSize with batchSize=0. Beyond the crash, other misconfigurations like min_shards > max_shards or max_backoff < min_backoff were 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 in config/config.go that checks:

  • All numeric fields are positive (max_shards, min_shards, max_samples_per_send, capacity)
  • min_shardsmax_shards
  • max_backoffmin_backoff

The validation is called from RemoteWriteConfig.UnmarshalYAML() so invalid configs fail fast during startup.

Key changes:

config/config.go — Added validation method (~20 LOC):

func (c *QueueConfig) Validate() error {
    if c.MaxSamplesPerSend <= 0 {
        return errors.New("remote write queue max_samples_per_send must be positive")
    }
    if c.Capacity <= 0 {
        return errors.New("remote write queue capacity must be positive")
    }
    // ... additional checks for shards and backoff
    if c.MinShards > c.MaxShards {
        return errors.New("remote write queue min_shards must not be greater than max_shards")
    }
    return nil
}

Also added 3 test cases in config/config_test.go and corresponding bad config YAML files in config/testdata/ covering each validation path.


Does this PR introduce a user-facing change?

[BUGFIX] Config: Validate remote_write queue_config fields at load time to prevent runtime panic and silent misconfiguration.

@Sanchit2662
Copy link
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant