thanos-io/thanos · error
create results cache middleware
Error message
create results cache middleware
What it means
newQueryRangeTripperware builds the results-cache middleware for query_range endpoints by calling queryrange.NewResultsCacheMiddleware. If that construction fails (invalid cache backend config, extractor/codec issues), the error is wrapped with 'create results cache middleware'. Startup of the query-frontend aborts.
Solutions
- Read the wrapped inner error from NewResultsCacheMiddleware for the specific backend problem
- Fix the query_range results_cache backend configuration (addresses, client timeouts, provider options)
- Temporarily disable the query_range cache (remove results_cache block) to confirm the rest of the tripperware starts
- Ensure all cache client dependencies (memcached/redis endpoints, DNS records) are reachable and correctly formatted
Example fix
// before
query_range:
results_cache:
backend: redis
redis:
# endpoints empty
// after
query_range:
results_cache:
backend: redis
redis:
endpoints: [redis:6379]
ttl: 12h Defensive patterns
Strategy: try-catch
Validate before calling
if err := cfg.ResultsCacheConfig.Validate(querier.Config{}); err != nil {
return fmt.Errorf("query range cache config invalid: %w", err)
} Type guard
func cacheEnabled(c Config) bool { return c.ResultsCacheConfig != nil } Try / catch
tw, err := NewTripperware(config, ...
if err != nil && strings.Contains(err.Error(), "create results cache middleware") {
log.Fatalf("fix query_range results_cache backend: %v", err)
} Prevention
- Ensure cache backend endpoints (memcached/redis) are valid and reachable before rollout
- Test cache client construction in an integration smoke test
- Keep backend TTL and client timeout values within supported ranges
When it happens
Trigger: NewTripperware -> newQueryRangeTripperware with caching enabled; queryrange.NewResultsCacheMiddleware returns an error because the ResultsCacheConfig (backend selection, memcached/redis client settings) is invalid or its client cannot be built.
Common situations: Cache backend configured with unsupported/invalid options; memcached client config errors (bad addresses, invalid timeouts); passing an unregistered registerer or nil dependency in custom builds; cache config validated at Validate time but backend client construction still failing.
Related errors
- parsing config YAML file
- marshal content of cache backend configuration
- response cache with type
- invalid ResultsCache config for labels tripperware
- initialize query range limits
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/8c8c971ccb50d261.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/queryfrontend/roundtrip.go:229
queryRangeMiddleware,
PromQLShardingMiddleware(analyzer, numShards, limits, codec, reg),
)
}
if config.ResultsCacheConfig != nil {
queryCacheMiddleware, _, err := queryrange.NewResultsCacheMiddleware(
logger,
*config.ResultsCacheConfig,
newThanosCacheKeyGenerator(),
limits,
codec,
queryrange.PrometheusResponseExtractor{},
nil,
shouldCache,
reg,
)
if err != nil {
return nil, errors.Wrap(err, "create results cache middleware")
}
queryRangeMiddleware = append(
queryRangeMiddleware,
queryrange.InstrumentMiddleware("results_cache", m),
queryCacheMiddleware,
)
}
if config.MaxRetries > 0 {
queryRangeMiddleware = append(
queryRangeMiddleware,
queryrange.InstrumentMiddleware("retry", m),
queryrange.NewRetryMiddleware(logger, config.MaxRetries, queryrange.NewRetryMiddlewareMetrics(reg)),
)
}
return func(next http.RoundTripper) http.RoundTripper {View on GitHub (pinned to 35b8b99117)