Skip to content

Commit c586fcc

Browse files
author
Arthur Silva Sens
authored
Merge pull request #1483 from prometheus/simplify-basemetrics
chore: Refactor how base metrics are added to Sched metrics
2 parents 6fdffbf + ec6ba13 commit c586fcc

File tree

4 files changed

+13
-51
lines changed

4 files changed

+13
-51
lines changed

prometheus/collectors/gen_go_collector_set.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ func groupMetrics(metricsList []string) []metricGroup {
135135
}
136136
}
137137

138-
// Scheduler metrics is `sched` regex plus base metrics
139-
// List of base metrics are taken from here: https://github.com/prometheus/client_golang/blob/26e3055e5133a9d64e8e5a07a7cf026875d5f55d/prometheus/go_collector.go#L208
140-
if group.Name == "withSchedulerMetrics" {
141-
baseMatrices := []string{
142-
"go_gc_duration_seconds",
143-
"go_goroutines",
144-
"go_info",
145-
"go_memstats_last_gc_time_seconds",
146-
"go_threads",
147-
}
148-
matchedMetrics = append(matchedMetrics, baseMatrices...)
149-
}
150138
sort.Strings(matchedMetrics)
151139
if len(matchedMetrics) > 0 {
152140
groupedMetrics = append(groupedMetrics, metricGroup{
@@ -173,9 +161,6 @@ var testFile = template.Must(template.New("testFile").Funcs(map[string]interface
173161
"nextVersion": func(version goVersion) string {
174162
return (version + goVersion(1)).String()
175163
},
176-
"needsBaseMetrics": func(groupName string) bool {
177-
return groupName == "withAllMetrics" || groupName == "withGCMetrics" || groupName == "withMemoryMetrics"
178-
},
179164
}).Parse(`// Copyright 2022 The Prometheus Authors
180165
// Licensed under the Apache License, Version 2.0 (the "License");
181166
// you may not use this file except in compliance with the License.
@@ -196,19 +181,11 @@ package collectors
196181
197182
{{- range .Groups }}
198183
func {{ .Name }}() []string {
199-
{{- if needsBaseMetrics .Name }}
200184
return withBaseMetrics([]string{
201185
{{- range $metric := .Metrics }}
202186
{{ $metric | printf "%q" }},
203187
{{- end }}
204188
})
205-
{{- else }}
206-
return []string{
207-
{{- range $metric := .Metrics }}
208-
{{ $metric | printf "%q" }},
209-
{{- end }}
210-
}
211-
{{- end }}
212189
}
213190
{{ end }}
214191
`))

prometheus/collectors/go_collector_go120_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ package collectors
1919
func withAllMetrics() []string {
2020
return withBaseMetrics([]string{
2121
"go_cgo_go_to_c_calls_calls_total",
22-
"go_gc_cycles_automatic_gc_cycles_total",
23-
"go_gc_cycles_forced_gc_cycles_total",
24-
"go_gc_cycles_total_gc_cycles_total",
2522
"go_cpu_classes_gc_mark_assist_cpu_seconds_total",
2623
"go_cpu_classes_gc_mark_dedicated_cpu_seconds_total",
2724
"go_cpu_classes_gc_mark_idle_cpu_seconds_total",
@@ -33,6 +30,9 @@ func withAllMetrics() []string {
3330
"go_cpu_classes_scavenge_total_cpu_seconds_total",
3431
"go_cpu_classes_total_cpu_seconds_total",
3532
"go_cpu_classes_user_cpu_seconds_total",
33+
"go_gc_cycles_automatic_gc_cycles_total",
34+
"go_gc_cycles_forced_gc_cycles_total",
35+
"go_gc_cycles_total_gc_cycles_total",
3636
"go_gc_heap_allocs_by_size_bytes",
3737
"go_gc_heap_allocs_bytes_total",
3838
"go_gc_heap_allocs_objects_total",
@@ -106,14 +106,9 @@ func withMemoryMetrics() []string {
106106
}
107107

108108
func withSchedulerMetrics() []string {
109-
return []string{
110-
"go_gc_duration_seconds",
111-
"go_goroutines",
112-
"go_info",
113-
"go_memstats_last_gc_time_seconds",
109+
return withBaseMetrics([]string{
114110
"go_sched_gomaxprocs_threads",
115111
"go_sched_goroutines_goroutines",
116112
"go_sched_latencies_seconds",
117-
"go_threads",
118-
}
113+
})
119114
}

prometheus/collectors/go_collector_go121_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,15 @@ func withMemoryMetrics() []string {
138138
}
139139

140140
func withSchedulerMetrics() []string {
141-
return []string{
142-
"go_gc_duration_seconds",
143-
"go_goroutines",
144-
"go_info",
145-
"go_memstats_last_gc_time_seconds",
141+
return withBaseMetrics([]string{
146142
"go_sched_gomaxprocs_threads",
147143
"go_sched_goroutines_goroutines",
148144
"go_sched_latencies_seconds",
149-
"go_threads",
150-
}
145+
})
151146
}
152147

153148
func withDebugMetrics() []string {
154-
return []string{
149+
return withBaseMetrics([]string{
155150
"go_godebug_non_default_behavior_execerrdot_events_total",
156151
"go_godebug_non_default_behavior_gocachehash_events_total",
157152
"go_godebug_non_default_behavior_gocachetest_events_total",
@@ -170,5 +165,5 @@ func withDebugMetrics() []string {
170165
"go_godebug_non_default_behavior_x509sha1_events_total",
171166
"go_godebug_non_default_behavior_x509usefallbackroots_events_total",
172167
"go_godebug_non_default_behavior_zipinsecurepath_events_total",
173-
}
168+
})
174169
}

prometheus/collectors/go_collector_go122_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,19 @@ func withMemoryMetrics() []string {
149149
}
150150

151151
func withSchedulerMetrics() []string {
152-
return []string{
153-
"go_gc_duration_seconds",
154-
"go_goroutines",
155-
"go_info",
156-
"go_memstats_last_gc_time_seconds",
152+
return withBaseMetrics([]string{
157153
"go_sched_gomaxprocs_threads",
158154
"go_sched_goroutines_goroutines",
159155
"go_sched_latencies_seconds",
160156
"go_sched_pauses_stopping_gc_seconds",
161157
"go_sched_pauses_stopping_other_seconds",
162158
"go_sched_pauses_total_gc_seconds",
163159
"go_sched_pauses_total_other_seconds",
164-
"go_threads",
165-
}
160+
})
166161
}
167162

168163
func withDebugMetrics() []string {
169-
return []string{
164+
return withBaseMetrics([]string{
170165
"go_godebug_non_default_behavior_execerrdot_events_total",
171166
"go_godebug_non_default_behavior_gocachehash_events_total",
172167
"go_godebug_non_default_behavior_gocachetest_events_total",
@@ -192,5 +187,5 @@ func withDebugMetrics() []string {
192187
"go_godebug_non_default_behavior_x509usefallbackroots_events_total",
193188
"go_godebug_non_default_behavior_x509usepolicies_events_total",
194189
"go_godebug_non_default_behavior_zipinsecurepath_events_total",
195-
}
190+
})
196191
}

0 commit comments

Comments
 (0)