mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
fix: erroneous high value for gateway received bytes metrics (#8978)
http.Request.ContentLength can be negative, which affects the gateway_s3_bytes_received value in Prometheus output. The commit only increases the value of the total received bytes in gateway mode when r.ContentLength is greater than zero.
This commit is contained in:
parent
c56c2f5fd3
commit
7d6766adc6
@ -434,7 +434,9 @@ func (m MetricsTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||||||
metered := shouldMeterRequest(r)
|
metered := shouldMeterRequest(r)
|
||||||
if metered && (r.Method == http.MethodGet || r.Method == http.MethodHead) {
|
if metered && (r.Method == http.MethodGet || r.Method == http.MethodHead) {
|
||||||
m.Metrics.IncRequests(r.Method)
|
m.Metrics.IncRequests(r.Method)
|
||||||
m.Metrics.IncBytesSent(r.ContentLength)
|
if r.ContentLength > 0 {
|
||||||
|
m.Metrics.IncBytesSent(uint64(r.ContentLength))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Make the request to the server.
|
// Make the request to the server.
|
||||||
resp, err := m.Transport.RoundTrip(r)
|
resp, err := m.Transport.RoundTrip(r)
|
||||||
@ -442,7 +444,9 @@ func (m MetricsTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if metered && (r.Method == http.MethodGet || r.Method == http.MethodHead) {
|
if metered && (r.Method == http.MethodGet || r.Method == http.MethodHead) {
|
||||||
m.Metrics.IncBytesReceived(resp.ContentLength)
|
if r.ContentLength > 0 {
|
||||||
|
m.Metrics.IncBytesReceived(uint64(resp.ContentLength))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,8 @@ type Metrics struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IncBytesReceived - Increase total bytes received from gateway backend
|
// IncBytesReceived - Increase total bytes received from gateway backend
|
||||||
func (s *Metrics) IncBytesReceived(n int64) {
|
func (s *Metrics) IncBytesReceived(n uint64) {
|
||||||
s.bytesReceived.Add(uint64(n))
|
s.bytesReceived.Add(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBytesReceived - Get total bytes received from gateway backend
|
// GetBytesReceived - Get total bytes received from gateway backend
|
||||||
@ -47,8 +47,8 @@ func (s *Metrics) GetBytesReceived() uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IncBytesSent - Increase total bytes sent to gateway backend
|
// IncBytesSent - Increase total bytes sent to gateway backend
|
||||||
func (s *Metrics) IncBytesSent(n int64) {
|
func (s *Metrics) IncBytesSent(n uint64) {
|
||||||
s.bytesSent.Add(uint64(n))
|
s.bytesSent.Add(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBytesSent - Get total bytes received from gateway backend
|
// GetBytesSent - Get total bytes received from gateway backend
|
||||||
|
Loading…
Reference in New Issue
Block a user