{"record":{"id":"7b11f878b1a252c0","repo":"thanos-io/thanos","slug":"error-retrieving-rules-v","errorCode":null,"errorMessage":"error retrieving rules: %v","messagePattern":"error retrieving rules: (.+?)","errorType":"http","errorClass":"ApiError","httpStatus":500,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":1434,"sourceCode":"\t\tspan, ctx := tracing.StartSpan(r.Context(), \"receive_http_request\")\n\t\tdefer span.Finish()\n\n\t\tvar (\n\t\t\tgroups   *rulespb.RuleGroups\n\t\t\twarnings annotations.Annotations\n\t\t\terr      error\n\t\t)\n\n\t\t// TODO(bwplotka): Allow exactly the same functionality as query API: passing replica, dedup and partial response as HTTP params as well.\n\t\treq := &rulespb.RulesRequest{\n\t\t\tType:                    rulespb.RulesRequest_ALERT,\n\t\t\tPartialResponseStrategy: ps,\n\t\t}\n\t\ttracing.DoInSpan(ctx, \"retrieve_rules\", func(ctx context.Context) {\n\t\t\tgroups, warnings, err = client.Rules(ctx, req)\n\t\t})\n\t\tif err != nil {\n\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorInternal, Err: errors.Errorf(\"error retrieving rules: %v\", err)}, func() {}\n\t\t}\n\n\t\tvar resp struct {\n\t\t\tAlerts []*rulespb.AlertInstance `json:\"alerts\"`\n\t\t}\n\t\tfor _, g := range groups.Groups {\n\t\t\tfor _, r := range g.Rules {\n\t\t\t\ta := r.GetAlert()\n\t\t\t\tif a == nil {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tresp.Alerts = append(resp.Alerts, a.Alerts...)\n\t\t\t}\n\t\t}\n\t\treturn resp, warnings.AsErrors(), nil, func() {}\n\t}\n}\n","sourceCodeStart":1416,"sourceCodeEnd":1452,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L1416-L1452","documentation":"Returned by the /api/v1/alerts endpoint when client.Rules() — the RPC that fetches rule groups from the upstream Query node — fails. The error is formatted with Errorf into an ErrorInternal (HTTP 500) response. It indicates the alert data could not be retrieved from the backing rules service, not that the HTTP request was malformed.","triggerScenarios":"Any GET /api/v1/alerts where the underlying Rules(ctx, req) gRPC call returns an error: unreachable query node, canceled request context, or RPC failure inside tracing span 'retrieve_rules'.","commonSituations":"Thanos Query node down or restarting, request timeout exceeded, network partition between query-frontend and query, rule Ruler/store RPC erroring while evaluating or serving rules.","solutions":["Read the %v-wrapped root error to identify transport vs application failure.","Check health/connectivity of the Query nodes serving the Rules API.","Retry if the cause was DeadlineExceeded or a transient network error.","Verify ruler/store-gateway components feeding rule data are healthy."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { const r = await fetch('/api/v1/alerts'); const b = await r.json(); if (b.errorType === 'internal') scheduleRetry(b.error); } catch (e) { /* network-level failure */ retry(e); }","preventionTips":["Retry GET /api/v1/alerts with backoff; it is read-only and safe to repeat.","Keep query nodes redundant so one down node doesn't fail alerts polling.","Alert on frontend->query gRPC error rates."],"tags":["grpc","network","api","internal"],"backgroundTag":"upstream-api-error","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"}