Skip to content

fix(distributor): relax content-type check #10916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
* [BUGFIX] MQE: Fix deriv with histograms #10383
* [BUGFIX] PromQL: Fix <aggr_over_time> functions with histograms https://github.com/prometheus/prometheus/pull/15711 #10400
* [BUGFIX] MQE: Fix <aggr_over_time> functions with histograms #10400
* [BUGFIX] Distributor: return HTTP status 415 Unsupported Media Type instead of 200 Success for Remote Write 2.0 until we support it. #10423
* [BUGFIX] Distributor: return HTTP status 415 Unsupported Media Type instead of 200 Success for Remote Write 2.0 until we support it. #10423 #10916
* [BUGFIX] Query-frontend: Add flag `-query-frontend.prom2-range-compat` and corresponding YAML to rewrite queries with ranges that worked in Prometheus 2 but are invalid in Prometheus 3. #10445 #10461 #10502
* [BUGFIX] Distributor: Fix edge case at the HA-tracker with memberlist as KVStore, where when a replica in the KVStore is marked as deleted but not yet removed, it fails to update the KVStore. #10443
* [BUGFIX] Distributor: Fix panics in `DurationWithJitter` util functions when computed variance is zero. #10507
Expand Down
4 changes: 3 additions & 1 deletion pkg/distributor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ func isRemoteWrite2(r *http.Request) (bool, error) {
}
parts := strings.Split(contentType, ";")
if parts[0] != appProtoContentType {
return false, fmt.Errorf("expected %v as the first (media) part, got %v content-type", appProtoContentType, contentType)
// We didn't use to check the content type so if someone wrote for
// example text/plain here, we'll accept and assume it is v1.
return false, nil
}

// Parse potential https://www.rfc-editor.org/rfc/rfc9110#parameter
Expand Down
24 changes: 24 additions & 0 deletions pkg/distributor/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ func TestHandler_remoteWrite(t *testing.T) {
assert.Equal(t, 200, resp.Code)
}

func TestHandler_remoteWriteWithMalformedRequest(t *testing.T) {
req := createMalformedRW1Request(t, createPrometheusRemoteWriteProtobuf(t))
resp := httptest.NewRecorder()
handler := Handler(100000, nil, nil, false, false, validation.MockDefaultOverrides(), RetryConfig{}, verifyWritePushFunc(t, mimirpb.API), nil, log.NewNopLogger())
handler.ServeHTTP(resp, req)
assert.Equal(t, 200, resp.Code)
}

func TestOTelMetricsToMetadata(t *testing.T) {
otelMetrics := pmetric.NewMetrics()
rs := otelMetrics.ResourceMetrics().AppendEmpty()
Expand Down Expand Up @@ -525,6 +533,22 @@ func createRequest(t testing.TB, protobuf []byte) *http.Request {
return req
}

func createMalformedRW1Request(t testing.TB, protobuf []byte) *http.Request {
t.Helper()
inoutBytes := snappy.Encode(nil, protobuf)
req, err := http.NewRequest("POST", "http://localhost/", bytes.NewReader(inoutBytes))
require.NoError(t, err)
req.Header.Add("Content-Encoding", "snappy")
req.Header.Set("Content-Type", "text/plain")

const tenantID = "test"
req.Header.Set("X-Scope-OrgID", tenantID)
ctx := user.InjectOrgID(context.Background(), tenantID)
req = req.WithContext(ctx)

return req
}

func createPrometheusRemoteWriteProtobuf(t testing.TB) []byte {
t.Helper()
input := prompb.WriteRequest{
Expand Down
Loading