metrics: Add canceled requests (#11881)

Add metric for canceled requests
This commit is contained in:
Klaus Post 2021-03-24 18:25:27 +01:00 committed by GitHub
parent 410e84d273
commit 749e9c5771
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 1 deletions

View File

@ -263,6 +263,7 @@ type ServerHTTPStats struct {
CurrentS3Requests ServerHTTPAPIStats `json:"currentS3Requests"`
TotalS3Requests ServerHTTPAPIStats `json:"totalS3Requests"`
TotalS3Errors ServerHTTPAPIStats `json:"totalS3Errors"`
TotalS3Canceled ServerHTTPAPIStats `json:"totalS3Canceled"`
}
// ServerInfoData holds storage, connections and other

View File

@ -17,6 +17,7 @@
package cmd
import (
"context"
"net/http"
"strings"
"sync"
@ -141,6 +142,7 @@ type HTTPStats struct {
currentS3Requests HTTPAPIStats
totalS3Requests HTTPAPIStats
totalS3Errors HTTPAPIStats
totalS3Canceled HTTPAPIStats
}
func (st *HTTPStats) addRequestsInQueue(i int32) {
@ -160,6 +162,9 @@ func (st *HTTPStats) toServerHTTPStats() ServerHTTPStats {
serverStats.TotalS3Errors = ServerHTTPAPIStats{
APIStats: st.totalS3Errors.Load(),
}
serverStats.TotalS3Canceled = ServerHTTPAPIStats{
APIStats: st.totalS3Canceled.Load(),
}
return serverStats
}
@ -175,6 +180,13 @@ func (st *HTTPStats) updateStats(api string, r *http.Request, w *logger.Response
if !successReq && w.StatusCode != 0 {
st.totalS3Errors.Inc(api)
}
select {
case <-r.Context().Done():
if err := r.Context().Err(); err == context.Canceled {
st.totalS3Canceled.Inc(api)
}
default:
}
}
// Increment the prometheus http request response histogram with appropriate label

View File

@ -49,7 +49,7 @@ type ResponseWriter struct {
}
// NewResponseWriter - returns a wrapped response writer to trap
// http status codes for auditiing purposes.
// http status codes for auditing purposes.
func NewResponseWriter(w http.ResponseWriter) *ResponseWriter {
return &ResponseWriter{
ResponseWriter: w,

View File

@ -74,6 +74,7 @@ type MetricName string
const (
total MetricName = "total"
errorsTotal MetricName = "error_total"
canceledTotal MetricName = "canceled_total"
healTotal MetricName = "heal_total"
hitsTotal MetricName = "hits_total"
inflightTotal MetricName = "inflight_total"
@ -495,6 +496,15 @@ func getS3RequestsErrorsMD() MetricDescription {
Type: counterMetric,
}
}
func getS3RequestsCanceledMD() MetricDescription {
return MetricDescription{
Namespace: s3MetricNamespace,
Subsystem: requestsSubsystem,
Name: canceledTotal,
Help: "Total number S3 requests that were canceled from the client while processing",
Type: counterMetric,
}
}
func getCacheHitsTotalMD() MetricDescription {
return MetricDescription{
Namespace: minioNamespace,
@ -576,6 +586,7 @@ func getHealObjectsHealTotalMD() MetricDescription {
Type: gaugeMetric,
}
}
func getHealObjectsFailTotalMD() MetricDescription {
return MetricDescription{
Namespace: healMetricNamespace,
@ -1077,6 +1088,13 @@ func getHTTPMetrics() MetricsGroup {
VariableLabels: map[string]string{"api": api},
})
}
for api, value := range httpStats.TotalS3Canceled.APIStats {
metrics = append(metrics, Metric{
Description: getS3RequestsCanceledMD(),
Value: float64(value),
VariableLabels: map[string]string{"api": api},
})
}
return
},
}

View File

@ -372,6 +372,18 @@ func httpMetricsPrometheus(ch chan<- prometheus.Metric) {
api,
)
}
for api, value := range httpStats.TotalS3Canceled.APIStats {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(s3Namespace, "canceled", "total"),
"Total number of client canceled s3 request in current MinIO server instance",
[]string{"api"}, nil),
prometheus.CounterValue,
float64(value),
api,
)
}
}
// collects network metrics for MinIO server in Prometheus specific format