rename metric for apiserver request terminations and reword corresponding documentation

Change-Id: I47a9c7b10614afe85bb652fa61984f91848d6d65

Kubernetes-commit: f8f1def5f1d92a588f48ebc01293e142f8dd63fd
This commit is contained in:
Han Kang 2019-10-21 13:26:31 -07:00 committed by Kubernetes Publisher
parent a5356f425d
commit 00d376192a
3 changed files with 13 additions and 11 deletions

View File

@ -188,10 +188,10 @@ var (
[]string{"requestKind"},
)
requestErrorsTotal = compbasemetrics.NewCounterVec(
requestTerminationsTotal = compbasemetrics.NewCounterVec(
&compbasemetrics.CounterOpts{
Name: "apiserver_request_errors_total",
Help: "Number of requests which have resulted in an apiserver response error.",
Name: "apiserver_request_terminations_total",
Help: "Number of requests which apiserver terminated in self-defense.",
StabilityLevel: compbasemetrics.ALPHA,
},
[]string{"verb", "group", "version", "resource", "subresource", "scope", "component", "code"},
@ -212,7 +212,7 @@ var (
WatchEvents,
WatchEventsSizes,
currentInflightRequests,
requestErrorsTotal,
requestTerminationsTotal,
}
)
@ -246,9 +246,11 @@ func UpdateInflightRequestMetrics(nonmutating, mutating int) {
currentInflightRequests.WithLabelValues(MutatingKind).Set(float64(mutating))
}
// RecordRequestError records the occurrence of a request error during apiserver handling (e.g. timeouts,
// maxinflight throttling, proxyHandler errors).
func RecordRequestError(req *http.Request, requestInfo *request.RequestInfo, component string, code int) {
// RecordRequestTermination records that the request was terminated early as part of a resource
// preservation or apiserver self-defense mechanism (e.g. timeouts, maxinflight throttling,
// proxyHandler errors). RecordRequestTermination should only be called zero or one times
// per request.
func RecordRequestTermination(req *http.Request, requestInfo *request.RequestInfo, component string, code int) {
if requestInfo == nil {
requestInfo = &request.RequestInfo{Verb: req.Method, Path: req.URL.Path}
}
@ -260,9 +262,9 @@ func RecordRequestError(req *http.Request, requestInfo *request.RequestInfo, com
// However, we need to tweak it e.g. to differentiate GET from LIST.
verb := canonicalVerb(strings.ToUpper(req.Method), scope)
if requestInfo.IsResourceRequest {
requestErrorsTotal.WithLabelValues(cleanVerb(verb, req), requestInfo.APIGroup, requestInfo.APIVersion, requestInfo.Resource, requestInfo.Subresource, scope, component, codeToString(code)).Inc()
requestTerminationsTotal.WithLabelValues(cleanVerb(verb, req), requestInfo.APIGroup, requestInfo.APIVersion, requestInfo.Resource, requestInfo.Subresource, scope, component, codeToString(code)).Inc()
} else {
requestErrorsTotal.WithLabelValues(cleanVerb(verb, req), "", "", "", requestInfo.Path, scope, component, codeToString(code)).Inc()
requestTerminationsTotal.WithLabelValues(cleanVerb(verb, req), "", "", "", requestInfo.Path, scope, component, codeToString(code)).Inc()
}
}

View File

@ -178,7 +178,7 @@ func WithMaxInFlightLimit(
}
}
}
metrics.RecordRequestError(r, requestInfo, metrics.APIServerComponent, http.StatusTooManyRequests)
metrics.RecordRequestTermination(r, requestInfo, metrics.APIServerComponent, http.StatusTooManyRequests)
tooManyRequests(r, w)
}
}

View File

@ -59,7 +59,7 @@ func WithTimeoutForNonLongRunningRequests(handler http.Handler, longRunning apir
postTimeoutFn := func() {
cancel()
metrics.RecordRequestError(req, requestInfo, metrics.APIServerComponent, http.StatusGatewayTimeout)
metrics.RecordRequestTermination(req, requestInfo, metrics.APIServerComponent, http.StatusGatewayTimeout)
}
return req, time.After(timeout), postTimeoutFn, apierrors.NewTimeoutError(fmt.Sprintf("request did not complete within %s", timeout), 0)
}