{"record":{"id":"198b67a3ec26a242","repo":"thanos-io/thanos","slug":"unmarshal-response-v","errorCode":null,"errorMessage":"unmarshal response: %v","messagePattern":"unmarshal response: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":201,"sourceCode":"// Note that configuration can be hot reloadable on Prometheus, so this config might change in runtime.\nfunc (c *Client) ExternalLabels(ctx context.Context, base *url.URL) (labels.Labels, error) {\n\tu := *base\n\tu.Path = path.Join(u.Path, \"/api/v1/status/config\")\n\n\tspan, ctx := tracing.StartSpan(ctx, \"/prom_config HTTP[client]\")\n\tdefer span.Finish()\n\n\tbody, _, err := c.req2xx(ctx, &u, http.MethodGet, nil)\n\tif err != nil {\n\t\treturn labels.EmptyLabels(), err\n\t}\n\tvar d struct {\n\t\tData struct {\n\t\t\tYAML string `json:\"yaml\"`\n\t\t} `json:\"data\"`\n\t}\n\tif err := json.Unmarshal(body, &d); err != nil {\n\t\treturn labels.EmptyLabels(), errors.Wrapf(err, \"unmarshal response: %v\", string(body))\n\t}\n\tvar cfg struct {\n\t\tGlobalConfig struct {\n\t\t\tExternalLabels map[string]string `yaml:\"external_labels\"`\n\t\t} `yaml:\"global\"`\n\t}\n\tif err := yaml.Unmarshal([]byte(d.Data.YAML), &cfg); err != nil {\n\t\treturn labels.EmptyLabels(), errors.Wrapf(err, \"parse Prometheus config: %v\", d.Data.YAML)\n\t}\n\n\treturn labels.FromMap(cfg.GlobalConfig.ExternalLabels), nil\n}\n\ntype Flags struct {\n\tTSDBPath           string         `json:\"storage.tsdb.path\"`\n\tTSDBRetention      model.Duration `json:\"storage.tsdb.retention\"`\n\tTSDBMinTime        model.Duration `json:\"storage.tsdb.min-block-duration\"`\n\tTSDBMaxTime        model.Duration `json:\"storage.tsdb.max-block-duration\"`","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L183-L219","documentation":"ExternalLabels fetches /api/v1/status/config from Prometheus and unmarshals the JSON response into a struct with a data.yaml field. This error wraps json.Unmarshal failures, including the offending body in the message, so a malformed or unexpected JSON payload can be diagnosed.","triggerScenarios":"The body returned by the Prometheus /api/v1/status/config endpoint is not valid JSON or has a different shape than {data:{yaml:string}} — e.g. an HTML error page from a proxy, an auth redirect, or a truncated response. Called from UpdateLabels.","commonSituations":"A reverse proxy in front of Prometheus returns an HTML login page (200 with HTML); an older/other API returns a different JSON schema; gzip/mangling of the body; hitting the wrong port where another service listens.","solutions":["Check the body printed in the error to see what was actually returned","Verify the URL points at a real Prometheus /api/v1/status/config endpoint (curl it)","Remove/fix proxies returning HTML instead of JSON","Check Prometheus version compatibility for the status/config endpoint"],"exampleFix":"// before: hard to know what came back\ncurl -s http://prometheus:9090/api/v1/status/config | head\n// after: confirm valid JSON shape\n{\"status\":\"success\",\"data\":{\"yaml\":\"global: ...\"}}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"labels, err := client.ExternalLabels(ctx, baseURL)\nif err != nil {\n    if strings.Contains(err.Error(), \"unmarshal response\") {\n        // body wasn't JSON: check for proxies/auth pages and log the body\n        log.Printf(\"non-JSON response from status/config: %v\", err)\n    }\n    return err\n}","preventionTips":["curl the /api/v1/status/config endpoint to confirm JSON output","Ensure no proxy intercepts and returns HTML for API paths","Pin compatible Prometheus versions in your deployment"],"tags":["json","prometheus","unmarshal","http-response"],"backgroundTag":"json-unmarshal-failed","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"}