mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
Merge pull request #5147 from a-robinson/func
Re-add the defer statements around the monitor() calls in the apiserver.
This commit is contained in:
commit
05ea93f985
@ -70,9 +70,9 @@ func init() {
|
|||||||
|
|
||||||
// monitor is a helper function for each HTTP request handler to use for
|
// monitor is a helper function for each HTTP request handler to use for
|
||||||
// instrumenting basic request counter and latency metrics.
|
// instrumenting basic request counter and latency metrics.
|
||||||
func monitor(handler, verb, resource string, httpCode int, reqStart time.Time) {
|
func monitor(handler string, verb, resource *string, httpCode *int, reqStart time.Time) {
|
||||||
requestCounter.WithLabelValues(handler, verb, resource, strconv.Itoa(httpCode)).Inc()
|
requestCounter.WithLabelValues(handler, *verb, *resource, strconv.Itoa(*httpCode)).Inc()
|
||||||
requestLatencies.WithLabelValues(handler, verb).Observe(float64((time.Since(reqStart)) / time.Microsecond))
|
requestLatencies.WithLabelValues(handler, *verb).Observe(float64((time.Since(reqStart)) / time.Microsecond))
|
||||||
}
|
}
|
||||||
|
|
||||||
// monitorFilter creates a filter that reports the metrics for a given resource and action.
|
// monitorFilter creates a filter that reports the metrics for a given resource and action.
|
||||||
@ -80,7 +80,8 @@ func monitorFilter(action, resource string) restful.FilterFunction {
|
|||||||
return func(req *restful.Request, res *restful.Response, chain *restful.FilterChain) {
|
return func(req *restful.Request, res *restful.Response, chain *restful.FilterChain) {
|
||||||
reqStart := time.Now()
|
reqStart := time.Now()
|
||||||
chain.ProcessFilter(req, res)
|
chain.ProcessFilter(req, res)
|
||||||
monitor("rest", action, resource, res.StatusCode(), reqStart)
|
httpCode := res.StatusCode()
|
||||||
|
monitor("rest", &action, &resource, &httpCode, reqStart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
var apiResource string
|
var apiResource string
|
||||||
var httpCode int
|
var httpCode int
|
||||||
reqStart := time.Now()
|
reqStart := time.Now()
|
||||||
defer monitor("proxy", verb, apiResource, httpCode, reqStart)
|
defer monitor("proxy", &verb, &apiResource, &httpCode, reqStart)
|
||||||
|
|
||||||
requestInfo, err := r.apiRequestInfoResolver.GetAPIRequestInfo(req)
|
requestInfo, err := r.apiRequestInfoResolver.GetAPIRequestInfo(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -39,7 +39,7 @@ func (r *RedirectHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
var apiResource string
|
var apiResource string
|
||||||
var httpCode int
|
var httpCode int
|
||||||
reqStart := time.Now()
|
reqStart := time.Now()
|
||||||
defer monitor("redirect", verb, apiResource, httpCode, reqStart)
|
defer monitor("redirect", &verb, &apiResource, &httpCode, reqStart)
|
||||||
|
|
||||||
requestInfo, err := r.apiRequestInfoResolver.GetAPIRequestInfo(req)
|
requestInfo, err := r.apiRequestInfoResolver.GetAPIRequestInfo(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -73,9 +73,11 @@ type ServerStatus struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *validator) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (v *validator) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
verb := "get"
|
||||||
|
apiResource := ""
|
||||||
var httpCode int
|
var httpCode int
|
||||||
reqStart := time.Now()
|
reqStart := time.Now()
|
||||||
defer monitor("validate", "get", "", httpCode, reqStart)
|
defer monitor("validate", &verb, &apiResource, &httpCode, reqStart)
|
||||||
|
|
||||||
reply := []ServerStatus{}
|
reply := []ServerStatus{}
|
||||||
for name, server := range v.servers() {
|
for name, server := range v.servers() {
|
||||||
|
@ -66,7 +66,7 @@ func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
var apiResource string
|
var apiResource string
|
||||||
var httpCode int
|
var httpCode int
|
||||||
reqStart := time.Now()
|
reqStart := time.Now()
|
||||||
defer monitor("watch", verb, apiResource, httpCode, reqStart)
|
defer monitor("watch", &verb, &apiResource, &httpCode, reqStart)
|
||||||
|
|
||||||
if req.Method != "GET" {
|
if req.Method != "GET" {
|
||||||
notFound(w, req)
|
notFound(w, req)
|
||||||
|
Loading…
Reference in New Issue
Block a user