{"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), 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/01ffac6f245854c1b8adc6a69857c76a15f90022/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":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}