-
Notifications
You must be signed in to change notification settings - Fork 647
distributor: Report correct size in "message too big" error #12799
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
base: main
Are you sure you want to change the base?
Changes from all commits
2037b01
9127973
8250a2f
bc9db5d
3f160a1
b50cf44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1164,9 +1164,9 @@ func TestHandlerOTLPPush(t *testing.T) { | |
}, | ||
responseCode: http.StatusRequestEntityTooLarge, | ||
responseContentType: pbContentType, | ||
responseContentLength: 292, | ||
errMessage: "the incoming OTLP request has been rejected because its message size of 89 bytes is larger", | ||
expectedLogs: []string{`level=warn user=test msg="detected an error while ingesting OTLP metrics request (the request may have been partially ingested)" httpCode=413 err="rpc error: code = Code(413) desc = the incoming OTLP request has been rejected because its message size of 89 bytes is larger than the allowed limit of 30 bytes (err-mimir-distributor-max-otlp-request-size). To adjust the related limit, configure -distributor.max-otlp-request-size, or contact your service administrator." insight=true`}, | ||
responseContentLength: 307, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that this isn't new but this seems very fragile. Where does this number come from? Can we verify it some other way? |
||
errMessage: "the incoming OTLP request has been rejected because its message size of 89 bytes (uncompressed) is larger", | ||
expectedLogs: []string{`level=warn user=test msg="detected an error while ingesting OTLP metrics request (the request may have been partially ingested)" httpCode=413 err="rpc error: code = Code(413) desc = the incoming OTLP request has been rejected because its message size of 89 bytes (uncompressed) is larger than the allowed limit of 30 bytes (err-mimir-distributor-max-otlp-request-size). To adjust the related limit, configure -distributor.max-otlp-request-size, or contact your service administrator." insight=true`}, | ||
}, | ||
{ | ||
name: "Write samples. Unsupported compression", | ||
|
@@ -1213,9 +1213,9 @@ func TestHandlerOTLPPush(t *testing.T) { | |
}, | ||
responseCode: http.StatusRequestEntityTooLarge, | ||
responseContentType: pbContentType, | ||
responseContentLength: 293, | ||
errMessage: "the incoming OTLP request has been rejected because its message size of 104 bytes is larger", | ||
expectedLogs: []string{`level=warn user=test msg="detected an error while ingesting OTLP metrics request (the request may have been partially ingested)" httpCode=413 err="rpc error: code = Code(413) desc = the incoming OTLP request has been rejected because its message size of 104 bytes is larger than the allowed limit of 30 bytes (err-mimir-distributor-max-otlp-request-size). To adjust the related limit, configure -distributor.max-otlp-request-size, or contact your service administrator." insight=true`}, | ||
responseContentLength: 308, | ||
errMessage: "the incoming OTLP request has been rejected because its message size of 104 bytes (uncompressed) is larger", | ||
expectedLogs: []string{`level=warn user=test msg="detected an error while ingesting OTLP metrics request (the request may have been partially ingested)" httpCode=413 err="rpc error: code = Code(413) desc = the incoming OTLP request has been rejected because its message size of 104 bytes (uncompressed) is larger than the allowed limit of 30 bytes (err-mimir-distributor-max-otlp-request-size). To adjust the related limit, configure -distributor.max-otlp-request-size, or contact your service administrator." insight=true`}, | ||
}, | ||
{ | ||
name: "Write samples. With lz4 compression, request too big", | ||
|
@@ -1229,9 +1229,9 @@ func TestHandlerOTLPPush(t *testing.T) { | |
}, | ||
responseCode: http.StatusRequestEntityTooLarge, | ||
responseContentType: pbContentType, | ||
responseContentLength: 293, | ||
errMessage: "the incoming OTLP request has been rejected because its message size of 106 bytes is larger", | ||
expectedLogs: []string{`level=warn user=test msg="detected an error while ingesting OTLP metrics request (the request may have been partially ingested)" httpCode=413 err="rpc error: code = Code(413) desc = the incoming OTLP request has been rejected because its message size of 106 bytes is larger than the allowed limit of 30 bytes (err-mimir-distributor-max-otlp-request-size). To adjust the related limit, configure -distributor.max-otlp-request-size, or contact your service administrator." insight=true`}, | ||
responseContentLength: 308, | ||
errMessage: "the incoming OTLP request has been rejected because its message size of 106 bytes (uncompressed) is larger", | ||
expectedLogs: []string{`level=warn user=test msg="detected an error while ingesting OTLP metrics request (the request may have been partially ingested)" httpCode=413 err="rpc error: code = Code(413) desc = the incoming OTLP request has been rejected because its message size of 106 bytes (uncompressed) is larger than the allowed limit of 30 bytes (err-mimir-distributor-max-otlp-request-size). To adjust the related limit, configure -distributor.max-otlp-request-size, or contact your service administrator." insight=true`}, | ||
}, | ||
{ | ||
name: "Rate limited request", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,8 +98,8 @@ func Handler( | |
) http.Handler { | ||
return handler(maxRecvMsgSize, newRequestBuffers, sourceIPs, allowSkipLabelNameValidation, allowSkipLabelCountValidation, limits, retryCfg, push, logger, func(ctx context.Context, r *http.Request, maxRecvMsgSize int, buffers *util.RequestBuffers, req *mimirpb.PreallocWriteRequest, _ log.Logger) error { | ||
protoBodySize, err := util.ParseProtoReader(ctx, r.Body, int(r.ContentLength), maxRecvMsgSize, buffers, req, util.RawSnappy) | ||
if errors.Is(err, util.MsgSizeTooLargeErr{}) { | ||
err = distributorMaxWriteMessageSizeErr{actual: int(r.ContentLength), limit: maxRecvMsgSize} | ||
if e := (util.MsgSizeTooLargeErr{}); errors.As(err, &e) { | ||
err = distributorMaxWriteMessageSizeErr{compressed: e.Compressed, actual: e.Actual, limit: e.Limit} | ||
} | ||
if err != nil { | ||
return err | ||
|
@@ -115,25 +115,29 @@ func Handler( | |
} | ||
|
||
type distributorMaxWriteMessageSizeErr struct { | ||
actual, limit int | ||
compressed, actual, limit int | ||
} | ||
|
||
func (e distributorMaxWriteMessageSizeErr) Error() string { | ||
msgSizeDesc := fmt.Sprintf(" of %d bytes", e.actual) | ||
if e.actual < 0 { | ||
msgSizeDesc = "" | ||
msgSizeDesc := "" | ||
if e.actual > 0 { | ||
msgSizeDesc = fmt.Sprintf(" of %d bytes (uncompressed)", e.actual) | ||
} else if e.compressed > 0 { | ||
msgSizeDesc = fmt.Sprintf(" of %d bytes (compressed)", e.compressed) | ||
} | ||
return globalerror.DistributorMaxWriteMessageSize.MessageWithPerInstanceLimitConfig(fmt.Sprintf("the incoming push request has been rejected because its message size%s is larger than the allowed limit of %d bytes", msgSizeDesc, e.limit), "distributor.max-recv-msg-size") | ||
} | ||
|
||
type distributorMaxOTLPRequestSizeErr struct { | ||
actual, limit int | ||
compressed, actual, limit int | ||
} | ||
|
||
func (e distributorMaxOTLPRequestSizeErr) Error() string { | ||
msgSizeDesc := fmt.Sprintf(" of %d bytes", e.actual) | ||
if e.actual < 0 { | ||
msgSizeDesc = "" | ||
msgSizeDesc := "" | ||
if e.actual > 0 { | ||
msgSizeDesc = fmt.Sprintf(" of %d bytes (uncompressed)", e.actual) | ||
} else if e.compressed > 0 { | ||
msgSizeDesc = fmt.Sprintf(" of %d bytes (compressed)", e.compressed) | ||
} | ||
return globalerror.DistributorMaxOTLPRequestSize.MessageWithPerInstanceLimitConfig(fmt.Sprintf("the incoming OTLP request has been rejected because its message size%s is larger than the allowed limit of %d bytes", msgSizeDesc, e.limit), maxOTLPRequestSizeFlag) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to not have either the compressed or actual size? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because we only decompress requests until reaching the limit, so we don't exactly know by how much a compressed request is over the limit after decompression. I added a specific constructor for this case at 8250a2f. |
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.