prometheus: track errors during REST read/write calls (#15678)

minio_inter_node_traffic_errors_total currently does not track
requests body write/read errors of internode REST communications.

This commit fixes this by wrapping resp.Body.
This commit is contained in:
Anis Elleuch 2022-09-12 20:40:51 +01:00 committed by GitHub
parent 6b9fd256e1
commit 4a92134235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,6 +211,26 @@ func (c *Client) newRequest(ctx context.Context, u *url.URL, body io.Reader) (*h
return req, nil
}
type respBodyMonitor struct {
io.ReadCloser
}
func (r respBodyMonitor) Read(p []byte) (n int, err error) {
n, err = r.ReadCloser.Read(p)
if err != nil && err != io.EOF {
atomic.AddUint64(&networkErrsCounter, 1)
}
return
}
func (r respBodyMonitor) Close() (err error) {
err = r.ReadCloser.Close()
if err != nil {
atomic.AddUint64(&networkErrsCounter, 1)
}
return
}
// Call - make a REST call with context.
func (c *Client) Call(ctx context.Context, method string, values url.Values, body io.Reader, length int64) (reply io.ReadCloser, err error) {
urlStr := c.url.String()
@ -286,6 +306,9 @@ func (c *Client) Call(ctx context.Context, method string, values url.Values, bod
}
return nil, errors.New(resp.Status)
}
if !c.NoMetrics && !c.ExpectTimeouts {
resp.Body = &respBodyMonitor{resp.Body}
}
return resp.Body, nil
}