thanos-io/thanos · error

labels.default-time-range cannot be set to 0

Error message

labels.default-time-range cannot be set to 0

What it means

The query-frontend requires labels.default-time-range to be explicitly set to a non-zero duration. This value is used as the default end-time range for label queries, so a zero value is treated as an unconfigured/invalid config. Validate() rejects it during startup.

Solutions

  1. Set labels.default-time-range to a positive duration (e.g. 24h) in the config or via the -labels.default-time-range flag
  2. If you intended unlimited ranges, pick a sane upper bound instead of 0
  3. Re-run config validation before restarting

Example fix

// before
labels:
  default-time-range: 0s
// after
labels:
  default-time-range: 24h
Defensive patterns

Strategy: validation

Validate before calling

if cfg.DefaultTimeRange == 0 {
    return errors.New("set labels.default-time-range to a positive duration")
}

Type guard

func defaultTimeRangeSet(d time.Duration) bool { return d > 0 }

Try / catch

if err := cfg.Validate(); err != nil {
    if strings.Contains(err.Error(), "default-time-range") {
        log.Fatalf("labels.default-time-range must be > 0: %v", err)
    }
}

Prevention

When it happens

Trigger: Config.Validate is called where cfg.DefaultTimeRange == 0 — i.e. labels.default-time-range was never set in the YAML/flags or was explicitly set to 0.

Common situations: New deployments that enable the labels tripperware but forget the required labels.default-time-range flag; config files migrated from setups that did not use the labels tripperware; setting the flag to 0 assuming it means 'unlimited'.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/255d2be68ca14dfe. Report an issue: GitHub.

Appendix: source

Thrown at pkg/queryfrontend/config.go:297

	if cfg.isDynamicSplitSet() {

		if err := cfg.validateDynamicSplitParams(); err != nil {
			return err
		}
	}

	if cfg.LabelsConfig.ResultsCacheConfig != nil {
		if cfg.LabelsConfig.SplitQueriesByInterval <= 0 {
			return errors.New("split queries interval should be greater than 0  when caching is enabled")
		}
		if err := cfg.LabelsConfig.ResultsCacheConfig.Validate(querier.Config{}); err != nil {
			return errors.Wrap(err, "invalid ResultsCache config for labels tripperware")
		}
	}

	if cfg.DefaultTimeRange == 0 {
		return errors.New("labels.default-time-range cannot be set to 0")
	}

	if cfg.DownstreamURL == "" {
		return errors.New("downstream URL should be configured")
	}

	return nil
}

func (cfg *Config) validateDynamicSplitParams() error {
	if cfg.HorizontalShards <= 0 {
		return errors.New("min horizontal shards should be greater than 0 when query split threshold is enabled")
	}

	if cfg.MaxQuerySplitInterval <= 0 {
		return errors.New("max query split interval should be greater than 0 when query split threshold is enabled")
	}

View on GitHub (pinned to 35b8b99117)