{"record":{"id":"8c8c971ccb50d261","repo":"thanos-io/thanos","slug":"create-results-cache-middleware","errorCode":null,"errorMessage":"create results cache middleware","messagePattern":"create results cache middleware","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/queryfrontend/roundtrip.go","lineNumber":229,"sourceCode":"\t\t\tqueryRangeMiddleware,\n\t\t\tPromQLShardingMiddleware(analyzer, numShards, limits, codec, reg),\n\t\t)\n\t}\n\n\tif config.ResultsCacheConfig != nil {\n\t\tqueryCacheMiddleware, _, err := queryrange.NewResultsCacheMiddleware(\n\t\t\tlogger,\n\t\t\t*config.ResultsCacheConfig,\n\t\t\tnewThanosCacheKeyGenerator(),\n\t\t\tlimits,\n\t\t\tcodec,\n\t\t\tqueryrange.PrometheusResponseExtractor{},\n\t\t\tnil,\n\t\t\tshouldCache,\n\t\t\treg,\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"create results cache middleware\")\n\t\t}\n\n\t\tqueryRangeMiddleware = append(\n\t\t\tqueryRangeMiddleware,\n\t\t\tqueryrange.InstrumentMiddleware(\"results_cache\", m),\n\t\t\tqueryCacheMiddleware,\n\t\t)\n\t}\n\n\tif config.MaxRetries > 0 {\n\t\tqueryRangeMiddleware = append(\n\t\t\tqueryRangeMiddleware,\n\t\t\tqueryrange.InstrumentMiddleware(\"retry\", m),\n\t\t\tqueryrange.NewRetryMiddleware(logger, config.MaxRetries, queryrange.NewRetryMiddlewareMetrics(reg)),\n\t\t)\n\t}\n\n\treturn func(next http.RoundTripper) http.RoundTripper {","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/queryfrontend/roundtrip.go#L211-L247","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nquery_range:\n  results_cache:\n    backend: redis\n    redis:\n      # endpoints empty\n// after\nquery_range:\n  results_cache:\n    backend: redis\n    redis:\n      endpoints: [redis:6379]\n      ttl: 12h","handlingStrategy":"try-catch","validationCode":"if err := cfg.ResultsCacheConfig.Validate(querier.Config{}); err != nil {\n    return fmt.Errorf(\"query range cache config invalid: %w\", err)\n}","typeGuard":"func cacheEnabled(c Config) bool { return c.ResultsCacheConfig != nil }","tryCatchPattern":"tw, err := NewTripperware(config, ...\nif err != nil && strings.Contains(err.Error(), \"create results cache middleware\") {\n    log.Fatalf(\"fix query_range results_cache backend: %v\", err)\n}","preventionTips":["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"],"tags":["query-frontend","cache","middleware","initialization"],"backgroundTag":"module-init-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}