{"record":{"id":"b27eccf42d351776","repo":"thanos-io/thanos","slug":"invalid-label-name-q","errorCode":null,"errorMessage":"invalid label name: %q","messagePattern":"invalid label name: %q","errorType":"http","errorClass":"ApiError","httpStatus":400,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":1080,"sourceCode":"\t// Optional stats field in response if parameter \"stats\" is not empty.\n\tvar qs stats.QueryStats\n\tif r.FormValue(Stats) != \"\" {\n\t\tqs = stats.NewQueryStats(qry.Stats())\n\t}\n\treturn &queryData{\n\t\tResultType:    res.Value.Type(),\n\t\tResult:        res.Value,\n\t\tStats:         qs,\n\t\tQueryAnalysis: analysis,\n\t}, warnings, nil, qry.Close\n}\n\nfunc (qapi *QueryAPI) labelValues(r *http.Request) (any, []error, *api.ApiError, func()) {\n\tctx := r.Context()\n\tname := route.Param(ctx, \"name\")\n\n\tif !model.UTF8Validation.IsValidLabelName(name) {\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: errors.Errorf(\"invalid label name: %q\", name)}, func() {}\n\t}\n\n\tstart, end, err := parseMetadataTimeRange(r, qapi.defaultMetadataTimeRange)\n\tif err != nil {\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}, func() {}\n\t}\n\n\tenablePartialResponse, apiErr := qapi.parsePartialResponseParam(r, qapi.enableQueryPartialResponse)\n\tif apiErr != nil {\n\t\treturn nil, nil, apiErr, func() {}\n\t}\n\n\tstoreDebugMatchers, apiErr := qapi.parseStoreDebugMatchersParam(r)\n\tif apiErr != nil {\n\t\treturn nil, nil, apiErr, func() {}\n\t}\n\n\tlimit, err := parseLimitParam(r.FormValue(\"limit\"))","sourceCodeStart":1062,"sourceCodeEnd":1098,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L1062-L1098","documentation":"The label values endpoint validates the label name from the URL path against Prometheus' model.UTF8Validation.IsValidLabelName rules and returns ErrorBadData (HTTP 400) if it fails. Label names must match the Prometheus label-name syntax (legacy [a-zA-Z_][a-zA-Z0-9_]* or UTF-8 quoted form).","triggerScenarios":"GET /api/v1/label/<name>/values with a name containing invalid characters (dots, dashes, spaces, empty name), or a UTF-8 name sent unquoted to an endpoint expecting legacy validation.","commonSituations":"Typos in dashboard label selectors; querying metric-name-like strings with slashes; newer UTF-8 label names used against tooling that doesn't quote them.","solutions":["Use a label name matching the legacy pattern ^[a-zA-Z_][a-zA-Z0-9_]*$","If using UTF-8 label names, ensure the client quotes/escapes them per the UTF-8 naming scheme and the server supports it","URL-encode the label name correctly in the path"],"exampleFix":"// before\nGET /api/v1/label/my.label/values\n// after\nGET /api/v1/label/my_label/values","handlingStrategy":"validation","validationCode":"func validLegacyLabelName(s string) bool {\n    if s == \"\" { return false }\n    for i, r := range s {\n        ok := r == '_' || (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (i > 0 && r >= '0' && r <= '9')\n        if !ok { return false }\n    }\n    return true\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reuse prometheus/model/labels validation client-side instead of hand-rolling patterns","URL-encode label names placed in the path","For UTF-8 label names, verify server version supports them and quote per spec"],"tags":["http-api","labels","validation"],"backgroundTag":"invalid-identifier-format","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"}