{"record":{"id":"23fe22fb526042ff","repo":"thanos-io/thanos","slug":"retrieving-tsdb-statistics","errorCode":null,"errorMessage":"retrieving tsdb statistics","messagePattern":"retrieving tsdb statistics","errorType":"http","errorClass":"ApiError","httpStatus":500,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":1762,"sourceCode":"\t\t}\n\t}\n\n\tif limit > math.MaxInt32 {\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: errors.Errorf(\"limit %d overflows int32\", limit)}, func() {}\n\t}\n\treq := &statuspb.TSDBStatisticsRequest{\n\t\tMatchers:                matchers,\n\t\tLimit:                   int32(limit),\n\t\tPartialResponseStrategy: ps,\n\t}\n\n\tvar stats map[string]*statuspb.TSDBStatisticsEntry\n\ttracing.DoInSpan(ctx, \"retrieve_tsdb_statistics\", func(ctx context.Context) {\n\t\tstats, warnings, err = qapi.status.TSDBStatistics(ctx, req)\n\t})\n\n\tif err != nil {\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorInternal, Err: errors.Wrap(err, \"retrieving tsdb statistics\")}, func() {}\n\t}\n\n\tif tenant != \"\" {\n\t\tif stats[tenant] == nil {\n\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorInternal, Err: errors.Wrap(fmt.Errorf(\"%s tenant not found\", tenant), \"retrieving tsdb statistics\")}, func() {}\n\t\t}\n\n\t\treturn convertToTSDBSTatus(stats[tenant], limit), warnings.AsErrors(), nil, func() {}\n\t}\n\n\t// Merge statistics from all tenants.\n\taggregatedStats := &statuspb.TSDBStatisticsEntry{}\n\tfor _, v := range stats {\n\t\taggregatedStats.Merge(v)\n\t}\n\n\treturn convertToTSDBSTatus(aggregatedStats, limit), warnings.AsErrors(), nil, func() {}\n}","sourceCodeStart":1744,"sourceCodeEnd":1780,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L1744-L1780","documentation":"Wraps failures of the status service's TSDBStatistics gRPC call (cardinality analysis) into an ErrorInternal for /api/v1/tsdb/status. The RPC failed or timed out while collecting per-tenant statistics.","triggerScenarios":"Calling /api/v1/tsdb/status when the underlying status service/store RPC errors: store unreachable, context deadline exceeded during expensive cardinality scans, or store returning an internal error.","commonSituations":"Large Prometheus TSDBs causing cardinality scans to exceed timeouts; store gateway OOMs or restarts under the head-stats query; network issues between querier and stores.","solutions":["Retry with a smaller match[] selector and/or lower limit to reduce scan cost.","Check store gateway health/logs for OOM or timeouts during TSDB statistics collection.","Increase request/context timeouts and verify querier-store connectivity."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"const resp = await fetch(`${base}/api/v1/tsdb/status?limit=1000`);\nif (!resp.ok) {\n  const body = await resp.json();\n  if (body.errorType === 'internal') {\n    // narrow match[] selector and retry with backoff\n    return retryWithSmallerSelector();\n  }\n  throw new Error(body.error);\n}","preventionTips":["Keep cardinality queries selective with match[] to avoid long scans.","Set and respect client timeouts shorter than server scan limits.","Watch store gateway memory during TSDB statistics collection."],"tags":["grpc","tsdb-status","cardinality","internal-error"],"backgroundTag":"api-error-response","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"}