{"record":{"id":"83a20f5d5086b9f8","repo":"thanos-io/thanos","slug":"read-query-instant-response","errorCode":null,"errorMessage":"read query instant response","messagePattern":"read query instant response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":456,"sourceCode":"\t}\n\n\tu := *base\n\tu.Path = path.Join(u.Path, \"/api/v1/query\")\n\tu.RawQuery = params.Encode()\n\n\tlevel.Debug(c.logger).Log(\"msg\", \"querying instant\", \"url\", u.String())\n\n\tspan, ctx := tracing.StartSpan(ctx, \"/prom_query_instant HTTP[client]\")\n\tdefer span.Finish()\n\n\tmethod := opts.Method\n\tif method == \"\" {\n\t\tmethod = http.MethodGet\n\t}\n\n\tbody, _, err := c.req2xx(ctx, &u, method, opts.HTTPHeaders)\n\tif err != nil {\n\t\treturn nil, nil, nil, errors.Wrap(err, \"read query instant response\")\n\t}\n\n\t// Decode only ResultType and load Result only as RawJson since we don't know\n\t// structure of the Result yet.\n\tvar m struct {\n\t\tData struct {\n\t\t\tResultType  string          `json:\"resultType\"`\n\t\t\tResult      json.RawMessage `json:\"result\"`\n\t\t\tExplanation *Explanation    `json:\"explanation,omitempty\"`\n\t\t} `json:\"data\"`\n\n\t\tError     string `json:\"error,omitempty\"`\n\t\tErrorType string `json:\"errorType,omitempty\"`\n\t\t// Extra fields supported by Thanos Querier.\n\t\tWarnings []string `json:\"warnings\"`\n\t}\n\n\tif err = json.Unmarshal(body, &m); err != nil {","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L438-L474","documentation":"This error wraps any non-2xx failure from the HTTP request Prometheus makes to the /api/v1/query endpoint during QueryInstant. The req2xx helper only returns a body when the server responds with a 2xx status, so any 4xx/5xx response (bad PromQL, bad auth, server error) or transport failure surfaces here wrapped with the message 'read query instant response'. It indicates the query request itself failed before any response body could be decoded.","triggerScenarios":"PromqlQueryInstant issues an instant query whose HTTP response status is not 2xx: invalid PromQL (400), wrong credentials (401/403), nonexistent endpoint/proxy path (404), timeouts or gateway errors (502/503/504), or connection errors to the Prometheus server.","commonSituations":"Misconfigured Prometheus URL or reverse-proxy path; malformed PromQL expression rejected by the server; missing auth token/headers; Prometheus temporarily down or overloaded; network egress blocked in the cluster.","solutions":["Log the wrapped error's cause (errors.Cause) to see the underlying HTTP status and Prometheus 'error' message, then fix the query or URL it points to","Verify the base URL/host points at a reachable Prometheus /api/v1 endpoint (curl the same query manually)","Check that required auth headers are set via opts.HTTPHeaders or client configuration","Validate the PromQL expression (e.g. with promtool check or parser) before sending","Add retry with backoff for transient 5xx/timeouts"],"exampleFix":"// before\nresult, _, warn, err := client.PromqlQueryInstant(ctx, opts) // err: read query instant response: ...\n// after\nif err != nil {\n    if cause := errors.Cause(err); cause != nil {\n        log.Printf(\"instant query failed: %v\", cause) // inspect real HTTP status/error\n    }\n    // validate query first:\n    if _, err := parser.ParseExpr(opts.Query); err != nil {\n        return fmt.Errorf(\"invalid PromQL %q: %w\", opts.Query, err)\n    }\n}","handlingStrategy":"try-catch","validationCode":"// validate reachability and query before calling\nif u, err := url.Parse(baseURL); err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid prometheus baseURL: %q\", baseURL)\n}\nif _, err := parser.ParseExpr(query); err != nil {\n    return fmt.Errorf(\"invalid PromQL: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"result, _, warn, err := client.PromqlQueryInstant(ctx, opts)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) || isServerError(errors.Cause(err)) {\n        // retry with backoff\n    }\n    return fmt.Errorf(\"instant query failed: %w\", errors.Cause(err))\n}","preventionTips":["Validate PromQL syntax with promtool/parser before sending","Health-check the Prometheus endpoint at startup","Set explicit auth headers and confirm them with a manual curl","Use context timeouts so failures surface quickly","Implement bounded retries for 5xx and transport errors"],"tags":["http","prometheus","network","query"],"backgroundTag":"http-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"}