@@ -33,6 +33,8 @@ import (
3333 "time"
3434
3535 "github.com/emicklei/go-restful"
36+ "github.com/prometheus/client_golang/prometheus"
37+ "github.com/prometheus/client_golang/prometheus/promhttp"
3638 cadvisormetrics "github.com/google/cadvisor/container"
3739 cadvisorapi "github.com/google/cadvisor/info/v1"
3840 cadvisorv2 "github.com/google/cadvisor/info/v2"
@@ -355,8 +357,8 @@ func (s *Server) InstallDefaultHandlers() {
355357 //lint:ignore SA1019 https://github.com/kubernetes/enhancements/issues/1206
356358 s .restfulCont .Handle (metricsPath , legacyregistry .Handler ())
357359
358- // cAdvisor metrics are exposed under the secured handler as well
359- r := compbasemetrics . NewKubeRegistry ()
360+ // cAdvisor container metrics require a blocking registry
361+ br := prometheus . NewBlockingRegistry ()
360362
361363 includedMetrics := cadvisormetrics.MetricSet {
362364 cadvisormetrics .CpuUsageMetrics : struct {}{},
@@ -375,15 +377,10 @@ func (s *Server) InstallDefaultHandlers() {
375377 includedMetrics [cadvisormetrics .AcceleratorUsageMetrics ] = struct {}{}
376378 }
377379
378- cadvisorOpts := cadvisorv2.RequestOptions {
379- IdType : cadvisorv2 .TypeName ,
380- Count : 1 ,
381- Recursive : true ,
382- }
383- r .RawMustRegister (metrics .NewPrometheusCollector (prometheusHostAdapter {s .host }, containerPrometheusLabelsFunc (s .host ), includedMetrics , clock.RealClock {}, cadvisorOpts ))
384- r .RawMustRegister (metrics .NewPrometheusMachineCollector (prometheusHostAdapter {s .host }, includedMetrics ))
380+ br .MustRegisterRaw (metrics .NewPrometheusCollector (prometheusHostAdapter {s .host }, containerPrometheusLabelsFunc (s .host ), includedMetrics , clock.RealClock {}))
381+ br .MustRegister (metrics .NewPrometheusMachineCollector (prometheusHostAdapter {s .host }, includedMetrics ))
385382 s .restfulCont .Handle (cadvisorMetricsPath ,
386- compbasemetrics . HandlerFor ( r , compbasemetrics .HandlerOpts {ErrorHandling : compbasemetrics .ContinueOnError }),
383+ promhttp . HandlerForTransactional ( br , promhttp .HandlerOpts {ErrorHandling : promhttp .ContinueOnError }),
387384 )
388385
389386 s .addMetricsBucketMatcher ("metrics/resource" )
0 commit comments