mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-07 12:11:43 +00:00
Consolidate the prometheus Counters into a shared CounterVec and remove
the "code" label from the latencies SummaryVec.
This commit is contained in:
@@ -19,7 +19,6 @@ package apiserver
|
||||
import (
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
|
||||
@@ -29,23 +28,8 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
restCounter = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "apiserver_rest_count",
|
||||
Help: "Counter of REST requests broken out for each verb, apiserver resource, and HTTP response code.",
|
||||
},
|
||||
[]string{"verb", "resource", "code"},
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(restCounter)
|
||||
}
|
||||
|
||||
// RESTHandler implements HTTP verbs on a set of RESTful resources identified by name.
|
||||
type RESTHandler struct {
|
||||
storage map[string]RESTStorage
|
||||
@@ -59,14 +43,11 @@ type RESTHandler struct {
|
||||
|
||||
// ServeHTTP handles requests to all RESTStorage objects.
|
||||
func (h *RESTHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
verb := ""
|
||||
apiResource := ""
|
||||
var verb string
|
||||
var apiResource string
|
||||
var httpCode int
|
||||
reqStart := time.Now()
|
||||
defer func() {
|
||||
restCounter.WithLabelValues(verb, apiResource, strconv.Itoa(httpCode)).Inc()
|
||||
apiserverLatencies.WithLabelValues("rest", verb, strconv.Itoa(httpCode)).Observe(float64((time.Since(reqStart)) / time.Microsecond))
|
||||
}()
|
||||
defer func() { monitor("rest", verb, apiResource, httpCode, reqStart) }()
|
||||
|
||||
requestInfo, err := h.apiRequestInfoResolver.GetAPIRequestInfo(req)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user