rename metric for apiserver request terminations and reword corresponding documentation

Change-Id: I47a9c7b10614afe85bb652fa61984f91848d6d65
This commit is contained in:
Han Kang 2019-10-21 13:26:31 -07:00
parent 5e652fe126
commit f8f1def5f1
4 changed files with 14 additions and 12 deletions

View File

@ -189,10 +189,10 @@ var (
[]string{"requestKind"}, []string{"requestKind"},
) )
requestErrorsTotal = compbasemetrics.NewCounterVec( requestTerminationsTotal = compbasemetrics.NewCounterVec(
&compbasemetrics.CounterOpts{ &compbasemetrics.CounterOpts{
Name: "apiserver_request_errors_total", Name: "apiserver_request_terminations_total",
Help: "Number of requests which have resulted in an apiserver response error.", Help: "Number of requests which apiserver terminated in self-defense.",
StabilityLevel: compbasemetrics.ALPHA, StabilityLevel: compbasemetrics.ALPHA,
}, },
[]string{"verb", "group", "version", "resource", "subresource", "scope", "component", "code"}, []string{"verb", "group", "version", "resource", "subresource", "scope", "component", "code"},
@ -213,7 +213,7 @@ var (
WatchEvents, WatchEvents,
WatchEventsSizes, WatchEventsSizes,
currentInflightRequests, currentInflightRequests,
requestErrorsTotal, requestTerminationsTotal,
} }
) )
@ -247,9 +247,11 @@ func UpdateInflightRequestMetrics(nonmutating, mutating int) {
currentInflightRequests.WithLabelValues(MutatingKind).Set(float64(mutating)) currentInflightRequests.WithLabelValues(MutatingKind).Set(float64(mutating))
} }
// RecordRequestError records the occurrence of a request error during apiserver handling (e.g. timeouts, // RecordRequestTermination records that the request was terminated early as part of a resource
// maxinflight throttling, proxyHandler errors). // preservation or apiserver self-defense mechanism (e.g. timeouts, maxinflight throttling,
func RecordRequestError(req *http.Request, requestInfo *request.RequestInfo, component string, code int) { // 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 { if requestInfo == nil {
requestInfo = &request.RequestInfo{Verb: req.Method, Path: req.URL.Path} requestInfo = &request.RequestInfo{Verb: req.Method, Path: req.URL.Path}
} }
@ -261,9 +263,9 @@ func RecordRequestError(req *http.Request, requestInfo *request.RequestInfo, com
// However, we need to tweak it e.g. to differentiate GET from LIST. // However, we need to tweak it e.g. to differentiate GET from LIST.
verb := canonicalVerb(strings.ToUpper(req.Method), scope) verb := canonicalVerb(strings.ToUpper(req.Method), scope)
if requestInfo.IsResourceRequest { 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 { } 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) tooManyRequests(r, w)
} }
} }

View File

@ -59,7 +59,7 @@ func WithTimeoutForNonLongRunningRequests(handler http.Handler, longRunning apir
postTimeoutFn := func() { postTimeoutFn := func() {
cancel() 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) return req, time.After(timeout), postTimeoutFn, apierrors.NewTimeoutError(fmt.Sprintf("request did not complete within %s", timeout), 0)
} }

View File

@ -98,7 +98,7 @@ func proxyError(w http.ResponseWriter, req *http.Request, error string, code int
return return
} }
// TODO: record long-running request differently? The long-running check func does not necessarily match the one of the aggregated apiserver // TODO: record long-running request differently? The long-running check func does not necessarily match the one of the aggregated apiserver
endpointmetrics.RecordRequestError(req, info, aggregatorComponent, code) endpointmetrics.RecordRequestTermination(req, info, aggregatorComponent, code)
} }
func (r *proxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { func (r *proxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {