-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bound buffer for reading stats #14523
Changes from all commits
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 |
---|---|---|
|
@@ -95,6 +95,21 @@ func TestHTTPScrapeClientScrapeProtoErrorCases(t *testing.T) { | |
responseCode: http.StatusOK, | ||
responseType: "text/html", | ||
expectedErr: errUnsupportedMetricType.Error(), | ||
}, { | ||
name: "LongStat", | ||
responseCode: http.StatusOK, | ||
responseType: "application/protobuf", | ||
stat: Stat{ | ||
// We don't expect PodName to be 600 characters long | ||
PodName: strings.Repeat("a123456789", 60), | ||
AverageConcurrentRequests: 1.1, | ||
AverageProxiedConcurrentRequests: 1.1, | ||
RequestCount: 33.2, | ||
ProxiedRequestCount: 33.2, | ||
ProcessUptime: 12345.678, | ||
Timestamp: 1697431278, | ||
}, | ||
expectedErr: "unmarshalling failed: unexpected EOF", | ||
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. nit: any way to distinguish we hit the limit vs EOF on the wire? 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. Not easily. Technically, we could also end up skipping a bunch of extra garbage after a valid proto, but since the proto contains a length at the start, we can tell whether we read the whole proto or not just by reading the beginning. (In fact, it would be nice if the generated proto code had a method that read from an |
||
}} | ||
|
||
for _, test := range testCases { | ||
|
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.
nit: Should not this be 255 for the max hostname? 🤔
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.
Extra-nit: you might need two bytes for the tag + length if the string is actually 256 bytes long, plus another possible tag + length for the entire message.
Proto doesn't have a way to express / enforce that a string is less than a certain size. The goal here is simply to avoid accidentally reading e.g. 5MB or more into an in-memory buffer when we know the actual report should be less than 1KB.
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.
Out of curiosity (haven't checked), what about using grpc instead?