{"record":{"id":"b7c4b3783e2ae502","repo":"grafana/k6","slug":"got-status-code-d-instead-expected-a-2xx-success","errorCode":null,"errorMessage":"got status code: %d instead expected a 2xx successful status code","messagePattern":"got status code: (.+?) instead expected a 2xx successful status code","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/prometheusrw/remote/client.go","lineNumber":141,"sourceCode":"\tb, err := proto.Marshal(&prompb.WriteRequest{\n\t\tTimeseries: series,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"encoding series as protobuf write request failed: %w\", err)\n\t}\n\tif snappy.MaxEncodedLen(len(b)) < 0 {\n\t\treturn nil, fmt.Errorf(\"the protobuf message is too large to be handled by Snappy encoder; \"+\n\t\t\t\"size: %d, limit: %d\", len(b), uint64(math.MaxUint32))\n\t}\n\treturn snappy.Encode(nil, b), nil\n}\n\nfunc validateResponseStatus(code int) error {\n\tif code >= http.StatusOK && code < 300 {\n\t\treturn nil\n\t}\n\n\treturn fmt.Errorf(\"got status code: %d instead expected a 2xx successful status code\", code)\n}\n","sourceCodeStart":123,"sourceCodeEnd":143,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/output/prometheusrw/remote/client.go#L123-L143","documentation":"The Prometheus remote write endpoint answered the POST with a non-2xx HTTP status. validateResponseStatus treats anything outside 200–299 as a failed write; the code indicates the server's rejection reason (400 bad payload, 401 auth, 5xx server error, etc.).","triggerScenarios":"Thrown at internal/output/prometheusrw/remote/client.go:141 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Look up the status code: 401/403 means fix basic auth credentials; 400 means payload/labels rejected; 5xx means check Prometheus health","Verify remote_write receiver is enabled on the Prometheus server","Check for invalid label names/values produced by the script"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}