Skip to content
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

chore: Refactor how base metrics are added to Sched metrics #1483

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions prometheus/collectors/gen_go_collector_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

@SachinSahu431 SachinSahu431 Mar 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be optional now. We can remove the import as well in line 28.

if len(matchedMetrics) > 0 {
groupedMetrics = append(groupedMetrics, metricGroup{
Expand All @@ -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.
Expand All @@ -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 }}
`))
15 changes: 5 additions & 10 deletions prometheus/collectors/go_collector_go120_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Comment on lines -22 to -24
Copy link
Contributor

@SachinSahu431 SachinSahu431 Mar 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we look at original file, the metrics were not sorted.

"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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
}
})
}
13 changes: 4 additions & 9 deletions prometheus/collectors/go_collector_go121_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
}
})
}
13 changes: 4 additions & 9 deletions prometheus/collectors/go_collector_go122_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,19 @@ 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_sched_pauses_stopping_gc_seconds",
"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",
Expand All @@ -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",
}
})
}
Loading