Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main.go: Add http request metric for kube-state-metrics main /metrics #1218

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ const (
healthzPath = "/healthz"
)

var (
durationVec = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Help: "A histogram of requests for kube-state-metrics metrics handler.",
Buckets: prometheus.DefBuckets,
ConstLabels: prometheus.Labels{"handler": "metrics"},
},
[]string{"method"},
)
)

// promLogger implements promhttp.Logger
type promLogger struct{}

Expand Down Expand Up @@ -79,6 +91,7 @@ func main() {
storeBuilder := store.NewBuilder()

ksmMetricsRegistry := prometheus.NewRegistry()
ksmMetricsRegistry.MustRegister(durationVec)
storeBuilder.WithMetrics(ksmMetricsRegistry)

var resources []string
Expand Down Expand Up @@ -264,7 +277,7 @@ func buildMetricsServer(kubeClient clientset.Interface, storeBuilder *store.Buil
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))

mux.Handle(metricsPath, m)
mux.Handle(metricsPath, promhttp.InstrumentHandlerDuration(durationVec, m))

// Add healthzPath
mux.HandleFunc(healthzPath, func(w http.ResponseWriter, r *http.Request) {
Expand Down