Skip to content

Commit

Permalink
feat(metrics): add metrics from cloud-provider library
Browse files Browse the repository at this point in the history
This includes metrics about internal operations from
`k8s.io/cloud-provider` like the workqueue depth and requests to the
Kubernetes API.

This metrics were already exposed on `:8233/metrics` but this was not
documented or scraped.

This commit now uses the same registry for our metrics and the
kubernetes libraries, and also exposes them on both ports for backwards
compatibility.
  • Loading branch information
apricote committed Dec 12, 2024
1 parent a7c46f2 commit 86fdae8
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/klog/v2"
)

Expand All @@ -38,24 +38,20 @@ var (
}, []string{"op"})
)

var registry = prometheus.NewRegistry()
func init() {
GetRegistry().MustRegister(OperationCalled)
}

func GetRegistry() *prometheus.Registry {
return registry
func GetRegistry() prometheus.Registerer {
return legacyregistry.Registerer()
}

func GetHandler() http.Handler {
registry.MustRegister(OperationCalled)

gatherers := prometheus.Gatherers{
prometheus.DefaultGatherer,
registry,
}

return promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{})
return legacyregistry.Handler()
}

func Serve(address string) {
// The metrics are also served by k8s.io/cloud-provider on the secure serving port.
mux := http.NewServeMux()
mux.Handle("/metrics", GetHandler())

Expand Down

0 comments on commit 86fdae8

Please sign in to comment.