{"record":{"id":"a9f8ad5599a48fe7","repo":"thanos-io/thanos","slug":"parse-prometheus-config-v","errorCode":null,"errorMessage":"parse Prometheus config: %v","messagePattern":"parse Prometheus config: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":209,"sourceCode":"\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\"`\n\tTSDBDelayCompact   string         `json:\"storage.tsdb.delay-compact-file.path\"`\n\tWebEnableAdminAPI  bool           `json:\"web.enable-admin-api\"`\n\tWebEnableLifecycle bool           `json:\"web.enable-lifecycle\"`\n}\n\n// UnmarshalJSON implements the json.Unmarshaler interface.\nfunc (f *Flags) UnmarshalJSON(b []byte) error {\n\t// TODO(bwplotka): Avoid this custom unmarshal by:","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L191-L227","documentation":"After decoding the config JSON, ExternalLabels parses the embedded Prometheus configuration YAML to extract global.external_labels. This error wraps yaml.Unmarshal failures, embedding the raw YAML text so the malformed config can be inspected.","triggerScenarios":"The YAML string inside data.yaml of the /api/v1/status/config response cannot be unmarshaled into the expected {global: {external_labels: map[string]string}} structure — e.g. YAML with anchors/templating the parser rejects, or non-string external label values.","commonSituations":"Prometheus config generated with unsupported YAML features (anchors producing exotic types); external_labels values that are not strings; corrupted config served by a proxy cache; third-party Prometheus forks emitting a different config format.","solutions":["Inspect the YAML included in the error message for syntax problems","Validate the Prometheus config with promtool check config","Ensure external_labels values are plain strings in prometheus.yml","Simplify generated config (avoid exotic YAML anchors) and reload Prometheus"],"exampleFix":"// before (prometheus.yml)\nglobal:\n  external_labels:\n    cluster: &anchor {name: prod}   # map where string expected\n// after\nglobal:\n  external_labels:\n    cluster: prod\n    name: prod","handlingStrategy":"validation","validationCode":"func externalLabelsAreStrings(cfgYAML string) error {\n    var probe struct {\n        Global struct {\n            ExternalLabels map[string]string `yaml:\"external_labels\"`\n        } `yaml:\"global\"`\n    }\n    return yaml.Unmarshal([]byte(cfgYAML), &probe)\n}","typeGuard":null,"tryCatchPattern":"labels, err := client.ExternalLabels(ctx, baseURL)\nif err != nil {\n    if strings.Contains(err.Error(), \"parse Prometheus config\") {\n        log.Printf(\"prometheus config YAML invalid: %v\", err)\n    }\n    return err\n}","preventionTips":["Run promtool check config on prometheus.yml after every change","Keep external_labels values as plain quoted strings","Avoid exotic YAML features (anchors with complex types) in generated configs"],"tags":["yaml","prometheus","config","parse"],"backgroundTag":"yaml-parse-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"}