{"record":{"id":"726331b12eeb0e08","repo":"thanos-io/thanos","slug":"service-unavailable","errorCode":null,"errorMessage":"service unavailable","messagePattern":"service unavailable","errorType":"http","errorClass":"api.ApiError","httpStatus":500,"severity":"error","filePath":"pkg/receive/handler.go","lineNumber":450,"sourceCode":"\nfunc getStatsLimitParameter(r *http.Request) (int, error) {\n\tstatsLimitStr := r.URL.Query().Get(LimitStatsQueryParam)\n\tif statsLimitStr == \"\" {\n\t\treturn DefaultStatsLimit, nil\n\t}\n\tstatsLimit, err := strconv.ParseInt(statsLimitStr, 10, 0)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"unable to parse '%s' parameter: %w\", LimitStatsQueryParam, err)\n\t}\n\tif statsLimit > math.MaxInt {\n\t\treturn 0, fmt.Errorf(\"'%s' parameter is larger than %d\", LimitStatsQueryParam, math.MaxInt)\n\t}\n\treturn int(statsLimit), nil\n}\n\nfunc (h *Handler) getStats(r *http.Request, statsByLabelName string) ([]api.TenantStats, *api.ApiError) {\n\tif !h.isReady() {\n\t\treturn nil, &api.ApiError{Typ: api.ErrorInternal, Err: fmt.Errorf(\"service unavailable\")}\n\t}\n\n\ttenantID := r.Header.Get(h.options.TenantHeader)\n\tgetAllTenantStats := r.FormValue(AllTenantsQueryParam) == \"true\"\n\tif getAllTenantStats && tenantID != \"\" {\n\t\terr := fmt.Errorf(\"using both the %s parameter and the %s header is not supported\", AllTenantsQueryParam, h.options.TenantHeader)\n\t\treturn nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}\n\t}\n\n\tstatsLimit, err := getStatsLimitParameter(r)\n\tif err != nil {\n\t\treturn nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}\n\t}\n\n\tif getAllTenantStats {\n\t\treturn h.options.TSDBStats.TenantStats(statsLimit, statsByLabelName), nil\n\t}\n","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/receive/handler.go#L432-L468","documentation":"A readiness sentinel returned by Handler.getStats when !h.isReady(): the receive handler (its TSDB or writer) is still starting up or shutting down, so the stats endpoint cannot serve tenant statistics. It is surfaced as an api.ErrorInternal, mapped to HTTP 500, and is inherently transient.","triggerScenarios":"Thrown at pkg/receive/handler.go:450 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wait for the handler readiness endpoint before querying stats.","Check whether the process is in shutdown.","Retry once ready; this is transient."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}