8000 Merge pull request #6966 from mindw/mindw/add_proc_go_build_metrics · cert-manager/cert-manager@9c28f4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c28f4d

Browse files
Merge pull request #6966 from mindw/mindw/add_proc_go_build_metrics
Add process and go runtime metrics for controller
2 parents f7100f3 + 52be4c0 commit 9c28f4d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pkg/metrics/metrics.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232

3333
"github.com/go-logr/logr"
3434
"github.com/prometheus/client_golang/prometheus"
35+
"github.com/prometheus/client_golang/prometheus/collectors"
3536
"github.com/prometheus/client_golang/prometheus/promhttp"
3637
"k8s.io/utils/clock"
3738

@@ -186,10 +187,16 @@ func New(log logr.Logger, c clock.Clock) *Metrics {
186187
)
187188
)
188189

190+
// Create Registry and register the recommended collectors
191+
registry := prometheus.NewRegistry()
192+
registry.MustRegister(
193+
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
194+
collectors.NewGoCollector(),
195+
)
189196
// Create server and register Prometheus metrics handler
190197
m := &Metrics{
191198
log: log.WithName("metrics"),
192-
registry: prometheus.NewRegistry(),
199+
registry: registry,
193200

194201
clockTimeSeconds: clockTimeSeconds,
195202
clockTimeSecondsGauge: clockTimeSecondsGauge,

test/integration/certificates/metrics_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ func TestMetricsController(t *testing.T) {
145145
return err
146146
}
147147

148-
if strings.TrimSpace(string(output)) != strings.< 5651 span class=pl-c1>TrimSpace(expectedOutput) {
148+
trimmedOutput := strings.SplitN(string(output), "# HELP go_gc_duration_seconds", 2)[0]
149+
if strings.TrimSpace(trimmedOutput) != strings.TrimSpace(expectedOutput) {
149150
return fmt.Errorf("got unexpected metrics output\nexp:\n%s\ngot:\n%s\n",
150151
expectedOutput, output)
151152
}

0 commit comments

Comments
 (0)
0