mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #63779 from wojtek-t/number_of_watchers_metrics
Automatic merge from submit-queue (batch tested with PRs 63792, 63495, 63742, 63332, 63779). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Track a metrics of number of registered watchers in apiserver
This commit is contained in:
commit
bd0d093701
@ -30,6 +30,7 @@ import (
|
|||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/apiserver/pkg/endpoints/handlers/negotiation"
|
"k8s.io/apiserver/pkg/endpoints/handlers/negotiation"
|
||||||
|
"k8s.io/apiserver/pkg/endpoints/metrics"
|
||||||
"k8s.io/apiserver/pkg/endpoints/request"
|
"k8s.io/apiserver/pkg/endpoints/request"
|
||||||
"k8s.io/apiserver/pkg/server/httplog"
|
"k8s.io/apiserver/pkg/server/httplog"
|
||||||
"k8s.io/apiserver/pkg/util/wsstream"
|
"k8s.io/apiserver/pkg/util/wsstream"
|
||||||
@ -140,6 +141,10 @@ type WatchServer struct {
|
|||||||
// ServeHTTP serves a series of encoded events via HTTP with Transfer-Encoding: chunked
|
// ServeHTTP serves a series of encoded events via HTTP with Transfer-Encoding: chunked
|
||||||
// or over a websocket connection.
|
// or over a websocket connection.
|
||||||
func (s *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (s *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
kind := s.Scope.Kind
|
||||||
|
metrics.RegisteredWatchers.WithLabelValues(kind.Group, kind.Version, kind.Kind).Inc()
|
||||||
|
defer metrics.RegisteredWatchers.WithLabelValues(kind.Group, kind.Version, kind.Kind).Dec()
|
||||||
|
|
||||||
w = httplog.Unlogged(w)
|
w = httplog.Unlogged(w)
|
||||||
|
|
||||||
if wsstream.IsWebSocketRequest(req) {
|
if wsstream.IsWebSocketRequest(req) {
|
||||||
|
@ -93,6 +93,14 @@ var (
|
|||||||
},
|
},
|
||||||
[]string{"requestKind"},
|
[]string{"requestKind"},
|
||||||
)
|
)
|
||||||
|
// RegisteredWatchers is a number of currently registered watchers splitted by resource.
|
||||||
|
RegisteredWatchers = prometheus.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "apiserver_registered_watchers",
|
||||||
|
Help: "Number of currently registered watchers for a given resources",
|
||||||
|
},
|
||||||
|
[]string{"group", "version", "kind"},
|
||||||
|
)
|
||||||
// Because of volatality of the base metric this is pre-aggregated one. Instead of reporing current usage all the time
|
// Because of volatality of the base metric this is pre-aggregated one. Instead of reporing current usage all the time
|
||||||
// it reports maximal usage during the last second.
|
// it reports maximal usage during the last second.
|
||||||
currentInflightRequests = prometheus.NewGaugeVec(
|
currentInflightRequests = prometheus.NewGaugeVec(
|
||||||
@ -111,6 +119,7 @@ var (
|
|||||||
requestLatenciesSummary,
|
requestLatenciesSummary,
|
||||||
responseSizes,
|
responseSizes,
|
||||||
DroppedRequests,
|
DroppedRequests,
|
||||||
|
RegisteredWatchers,
|
||||||
currentInflightRequests,
|
currentInflightRequests,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user