diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index e3032375ed9..4464809d5fb 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -32,6 +32,7 @@ import ( "github.com/go-logr/logr" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/promhttp" "k8s.io/utils/clock" @@ -186,10 +187,16 @@ func New(log logr.Logger, c clock.Clock) *Metrics { ) ) + // Create Registry and register the recommended collectors + registry := prometheus.NewRegistry() + registry.MustRegister( + collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}), + collectors.NewGoCollector(), + ) // Create server and register Prometheus metrics handler m := &Metrics{ log: log.WithName("metrics"), - registry: prometheus.NewRegistry(), + registry: registry, clockTimeSeconds: clockTimeSeconds, clockTimeSecondsGauge: clockTimeSecondsGauge, diff --git a/test/integration/certificates/metrics_controller_test.go b/test/integration/certificates/metrics_controller_test.go index b351bd80d00..43784251fea 100644 --- a/test/integration/certificates/metrics_controller_test.go +++ b/test/integration/certificates/metrics_controller_test.go @@ -145,7 +145,8 @@ func TestMetricsController(t *testing.T) { return err } - if strings.TrimSpace(string(output)) != strings.TrimSpace(expectedOutput) { + trimmedOutput := strings.SplitN(string(output), "# HELP go_gc_duration_seconds", 2)[0] + if strings.TrimSpace(trimmedOutput) != strings.TrimSpace(expectedOutput) { return fmt.Errorf("got unexpected metrics output\nexp:\n%s\ngot:\n%s\n", expectedOutput, output) }