{"record":{"id":"c887ced3d684c6d4","repo":"thanos-io/thanos","slug":"retrieving-targets","errorCode":null,"errorMessage":"retrieving targets","messagePattern":"retrieving targets","errorType":"http","errorClass":"ApiError","httpStatus":500,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":1400,"sourceCode":"\n\treturn func(r *http.Request) (any, []error, *api.ApiError, func()) {\n\t\tstateParam := r.URL.Query().Get(\"state\")\n\t\tstate, ok := targetspb.TargetsRequest_State_value[strings.ToUpper(stateParam)]\n\t\tif !ok {\n\t\t\tif stateParam != \"\" {\n\t\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: errors.Errorf(\"invalid targets parameter state='%v'\", stateParam)}, func() {}\n\t\t\t}\n\t\t\tstate = int32(targetspb.TargetsRequest_ANY)\n\t\t}\n\n\t\treq := &targetspb.TargetsRequest{\n\t\t\tState:                   targetspb.TargetsRequest_State(state),\n\t\t\tPartialResponseStrategy: ps,\n\t\t}\n\n\t\tt, warnings, err := client.Targets(r.Context(), req)\n\t\tif err != nil {\n\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorInternal, Err: errors.Wrap(err, \"retrieving targets\")}, func() {}\n\t\t}\n\n\t\treturn t, warnings.AsErrors(), nil, func() {}\n\t}\n}\n\n// NewAlertsHandler created handler compatible with HTTP /api/v1/alerts https://prometheus.io/docs/prometheus/latest/querying/api/#alerts\n// which uses gRPC Unary Rules API (Rules API works for both /alerts and /rules).\nfunc NewAlertsHandler(client rules.UnaryClient, enablePartialResponse bool) func(*http.Request) (any, []error, *api.ApiError, func()) {\n\tps := storepb.PartialResponseStrategy_ABORT\n\tif enablePartialResponse {\n\t\tps = storepb.PartialResponseStrategy_WARN\n\t}\n\n\treturn func(r *http.Request) (any, []error, *api.ApiError, func()) {\n\t\tspan, ctx := tracing.StartSpan(r.Context(), \"receive_http_request\")\n\t\tdefer span.Finish()\n","sourceCodeStart":1382,"sourceCodeEnd":1418,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L1382-L1418","documentation":"This error wraps a failure from client.Targets() — the Query API's call to the Query Frontend/upstream store-gateway Targets RPC used by the /api/v1/targets endpoint. The underlying error is whatever the gRPC client or downstream Thanos Query node reported, wrapped as ErrorInternal (HTTP 500). The handler itself is fine; the failure is in retrieving target data from the cluster.","triggerScenarios":"The proxied Targets(ctx, req) gRPC call returns a non-nil err — e.g. the query node is unreachable, the context deadline/r.Context() was canceled, or the store-gateway Targets API returns an RPC error.","commonSituations":"Query node down or DNS resolvable but gRPC port unreachable, client request canceled/timed out mid-call, TLS or auth misconfiguration between query-frontend and query, or the downstream query node returning 'no store matched' style RPC failures.","solutions":["Inspect the wrapped err message for the root cause (connection refused, DeadlineExceeded, canceled, etc.).","Verify the Thanos Query nodes behind the frontend are healthy and reachable (grpc port, --query addresses).","Retry the request if the error was a timeout or transient network issue.","Check frontend-to-query TLS/cert configuration if the error indicates TLS handshake failure."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"await Promise.race([fetch(url, {signal: AbortSignal.timeout(30000)}), ...]) // enforce client timeout below server deadline","typeGuard":null,"tryCatchPattern":"try { const r = await fetch('/api/v1/targets'); const b = await r.json(); if (b.status === 'error') handleApiError(b.error); } catch (e) { if (isTimeout(e)) retryWithBackoff(); else throw e; }","preventionTips":["Set client timeouts longer than the server's deadline.","Monitor query node health before bulk target polls.","Retry idempotent GETs with exponential backoff on transient gRPC errors."],"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"}