chore: Refactor how base metrics are added to Sched metrics

Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
This commit is contained in:
Arthur Silva Sens 2024-03-30 17:17:09 -03:00
parent 93cf5d4f5f
commit ec6ba13cc3
No known key found for this signature in database
4 changed files with 13 additions and 51 deletions

View File

@ -135,18 +135,6 @@ func groupMetrics(metricsList []string) []metricGroup {
}
}
// Scheduler metrics is `sched` regex plus base metrics
// List of base metrics are taken from here: https://github.com/prometheus/client_golang/blob/26e3055e5133a9d64e8e5a07a7cf026875d5f55d/prometheus/go_collector.go#L208
if group.Name == "withSchedulerMetrics" {
baseMatrices := []string{
"go_gc_duration_seconds",
"go_goroutines",
"go_info",
"go_memstats_last_gc_time_seconds",
"go_threads",
}
matchedMetrics = append(matchedMetrics, baseMatrices...)
}
sort.Strings(matchedMetrics)
if len(matchedMetrics) > 0 {
groupedMetrics = append(groupedMetrics, metricGroup{
@ -173,9 +161,6 @@ var testFile = template.Must(template.New("testFile").Funcs(map[string]interface
"nextVersion": func(version goVersion) string {
return (version + goVersion(1)).String()
},
"needsBaseMetrics": func(groupName string) bool {
return groupName == "withAllMetrics" || groupName == "withGCMetrics" || groupName == "withMemoryMetrics"
},
}).Parse(`// Copyright 2022 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -196,19 +181,11 @@ package collectors
{{- range .Groups }}
func {{ .Name }}() []string {
{{- if needsBaseMetrics .Name }}
return withBaseMetrics([]string{
{{- range $metric := .Metrics }}
{{ $metric | printf "%q" }},
{{- end }}
})
{{- else }}
return []string{
{{- range $metric := .Metrics }}
{{ $metric | printf "%q" }},
{{- end }}
}
{{- end }}
}
{{ end }}
`))

View File

@ -19,9 +19,6 @@ package collectors
func withAllMetrics() []string {
return withBaseMetrics([]string{
"go_cgo_go_to_c_calls_calls_total",
"go_gc_cycles_automatic_gc_cycles_total",
"go_gc_cycles_forced_gc_cycles_total",
"go_gc_cycles_total_gc_cycles_total",
"go_cpu_classes_gc_mark_assist_cpu_seconds_total",
"go_cpu_classes_gc_mark_dedicated_cpu_seconds_total",
"go_cpu_classes_gc_mark_idle_cpu_seconds_total",
@ -33,6 +30,9 @@ func withAllMetrics() []string {
"go_cpu_classes_scavenge_total_cpu_seconds_total",
"go_cpu_classes_total_cpu_seconds_total",
"go_cpu_classes_user_cpu_seconds_total",
"go_gc_cycles_automatic_gc_cycles_total",
"go_gc_cycles_forced_gc_cycles_total",
"go_gc_cycles_total_gc_cycles_total",
"go_gc_heap_allocs_by_size_bytes",
"go_gc_heap_allocs_bytes_total",
"go_gc_heap_allocs_objects_total",
@ -106,14 +106,9 @@ func withMemoryMetrics() []string {
}
func withSchedulerMetrics() []string {
return []string{
"go_gc_duration_seconds",
"go_goroutines",
"go_info",
"go_memstats_last_gc_time_seconds",
return withBaseMetrics([]string{
"go_sched_gomaxprocs_threads",
"go_sched_goroutines_goroutines",
"go_sched_latencies_seconds",
"go_threads",
}
})
}

View File

@ -138,20 +138,15 @@ func withMemoryMetrics() []string {
}
func withSchedulerMetrics() []string {
return []string{
"go_gc_duration_seconds",
"go_goroutines",
"go_info",
"go_memstats_last_gc_time_seconds",
return withBaseMetrics([]string{
"go_sched_gomaxprocs_threads",
"go_sched_goroutines_goroutines",
"go_sched_latencies_seconds",
"go_threads",
}
})
}
func withDebugMetrics() []string {
return []string{
return withBaseMetrics([]string{
"go_godebug_non_default_behavior_execerrdot_events_total",
"go_godebug_non_default_behavior_gocachehash_events_total",
"go_godebug_non_default_behavior_gocachetest_events_total",
@ -170,5 +165,5 @@ func withDebugMetrics() []string {
"go_godebug_non_default_behavior_x509sha1_events_total",
"go_godebug_non_default_behavior_x509usefallbackroots_events_total",
"go_godebug_non_default_behavior_zipinsecurepath_events_total",
}
})
}

View File

@ -149,11 +149,7 @@ func withMemoryMetrics() []string {
}
func withSchedulerMetrics() []string {
return []string{
"go_gc_duration_seconds",
"go_goroutines",
"go_info",
"go_memstats_last_gc_time_seconds",
return withBaseMetrics([]string{
"go_sched_gomaxprocs_threads",
"go_sched_goroutines_goroutines",
"go_sched_latencies_seconds",
@ -161,12 +157,11 @@ func withSchedulerMetrics() []string {
"go_sched_pauses_stopping_other_seconds",
"go_sched_pauses_total_gc_seconds",
"go_sched_pauses_total_other_seconds",
"go_threads",
}
})
}
func withDebugMetrics() []string {
return []string{
return withBaseMetrics([]string{
"go_godebug_non_default_behavior_execerrdot_events_total",
"go_godebug_non_default_behavior_gocachehash_events_total",
"go_godebug_non_default_behavior_gocachetest_events_total",
@ -192,5 +187,5 @@ func withDebugMetrics() []string {
"go_godebug_non_default_behavior_x509usefallbackroots_events_total",
"go_godebug_non_default_behavior_x509usepolicies_events_total",
"go_godebug_non_default_behavior_zipinsecurepath_events_total",
}
})
}