Skip to content
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

[release-1.10] sync with upstream #488

Merged
4 changes: 3 additions & 1 deletion pkg/autoscaler/metrics/http_scrape_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func statFromProto(body io.Reader) (Stat, error) {
b := pool.Get().(*bytes.Buffer)
b.Reset()
defer pool.Put(b)
_, err := b.ReadFrom(body)
// 6 8-byte fields (+2 bytes marshalling), one hostname, 20 bytes extra space
r := io.LimitedReader{R: body, N: 6*10 + 256 + 20}
_, err := b.ReadFrom(&r)
if err != nil {
return emptyStat, fmt.Errorf("reading body failed: %w", err)
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/autoscaler/metrics/http_scrape_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}}

for _, test := range testCases {
Expand Down
Loading