Skip to content

Commit e8341af

Browse files
feat(metrics): add metrics from cloud-provider library (#824)
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. Besides having all data available, this will also help us with debugging #661. Co-authored-by: Lukas Metzner <lukas.metzner@hetzner-cloud.de>
1 parent 6693640 commit e8341af

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

internal/metrics/metrics.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/prometheus/client_golang/prometheus"
24-
"github.com/prometheus/client_golang/prometheus/promhttp"
24+
"k8s.io/component-base/metrics/legacyregistry"
2525
"k8s.io/klog/v2"
2626
)
2727

@@ -38,24 +38,20 @@ var (
3838
}, []string{"op"})
3939
)
4040

41-
var registry = prometheus.NewRegistry()
41+
func init() {
42+
GetRegistry().MustRegister(OperationCalled)
43+
}
4244

43-
func GetRegistry() *prometheus.Registry {
44-
return registry
45+
func GetRegistry() prometheus.Registerer {
46+
return legacyregistry.Registerer()
4547
}
4648

4749
func GetHandler() http.Handler {
48-
registry.MustRegister(OperationCalled)
49-
50-
gatherers := prometheus.Gatherers{
51-
prometheus.DefaultGatherer,
52-
registry,
53-
}
54-
55-
return promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{})
50+
return legacyregistry.Handler()
5651
}
5752

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

0 commit comments

Comments
 (0)