-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add process and go runtime metrics for controller #6966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(), | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must have been confused in my last review. We can add the debug metrics in a later PR if people call for it. |
||
// Create server and register Prometheus metrics handler | ||
m := &Metrics{ | ||
log: log.WithName("metrics"), | ||
registry: prometheus.NewRegistry(), | ||
registry: registry, | ||
|
||
clockTimeSeconds: clockTimeSeconds, | ||
clockTimeSecondsGauge: clockTimeSecondsGauge, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this splits the metrics in two, on the first line of $ kubectl get --raw /api/v1/namespaces/cert-manager/pods/cert-manager-5844947869-zn7jg:9402/proxy/metrics | fgrep -C 3 '# HELP go_gc_duration_seconds'
certmanager_controller_sync_error_count{controller="certificates-key-manager"} 713
certmanager_controller_sync_error_count{controller="certificates-readiness"} 23
certmanager_controller_sync_error_count{controller="certificates-trigger"} 21
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 6.8496e-05
go_gc_duration_seconds{quantile="0.25"} 0.000419895 |
||
return fmt.Errorf("got unexpected metrics output\nexp:\n%s\ngot:\n%s\n", | ||
expectedOutput, output) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest rewording this comment to explain why rather than what the following code does.
Perhaps: