Skip to content

Commit 0f50003

Browse files
author
Arthur Silva Sens
committed
gocollector: Add regex option to allow collection of debug runtime metrics
Signed-off-by: Arthur Silva Sens <[email protected]>
1 parent c586fcc commit 0f50003

6 files changed

+26
-8
lines changed

prometheus/collectors/gen_go_collector_set.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,19 @@ func rm2prom(d metrics.Description) string {
128128
func groupMetrics(metricsList []string) []metricGroup {
129129
var groupedMetrics []metricGroup
130130
for _, group := range metricGroups {
131-
var matchedMetrics []string
131+
matchedMetrics := make([]string, 0)
132132
for _, metric := range metricsList {
133133
if group.Regex == nil || group.Regex.MatchString(metric) {
134134
matchedMetrics = append(matchedMetrics, metric)
135135
}
136136
}
137137

138138
sort.Strings(matchedMetrics)
139-
if len(matchedMetrics) > 0 {
140-
groupedMetrics = append(groupedMetrics, metricGroup{
141-
Name: group.Name,
142-
Regex: group.Regex,
143-
Metrics: matchedMetrics,
144-
})
145-
}
139+
groupedMetrics = append(groupedMetrics, metricGroup{
140+
Name: group.Name,
141+
Regex: group.Regex,
142+
Metrics: matchedMetrics,
143+
})
146144
}
147145
return groupedMetrics
148146
}

prometheus/collectors/go_collector_go117_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ func withSchedulerMetrics() []string {
9898
"go_threads",
9999
}
100100
}
101+
102+
func withDebugMetrics() []string {
103+
return withBaseMetrics([]string{})
104+
}

prometheus/collectors/go_collector_go119_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ func withSchedulerMetrics() []string {
105105
"go_threads",
106106
}
107107
}
108+
109+
func withDebugMetrics() []string {
110+
return withBaseMetrics([]string{})
111+
}

prometheus/collectors/go_collector_go120_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ func withSchedulerMetrics() []string {
112112
"go_sched_latencies_seconds",
113113
})
114114
}
115+
116+
func withDebugMetrics() []string {
117+
return withBaseMetrics([]string{})
118+
}

prometheus/collectors/go_collector_latest.go

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ var (
3737
// MetricsScheduler allows only scheduler metrics to be collected from Go runtime.
3838
// e.g. go_sched_goroutines_goroutines
3939
MetricsScheduler = GoRuntimeMetricsRule{regexp.MustCompile(`^/sched/.*`)}
40+
// MetricsDebug allows only debug metrics to be collected from Go runtime.
41+
// e.g. go_godebug_non_default_behavior_gocachetest_events_total
42+
MetricsDebug = GoRuntimeMetricsRule{regexp.MustCompile(`^/godebug/.*`)}
4043
)
4144

4245
// WithGoCollectorMemStatsMetricsDisabled disables metrics that is gathered in runtime.MemStats structure such as:

prometheus/collectors/go_collector_latest_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ func TestGoCollectorAllowList(t *testing.T) {
105105
rules: []GoRuntimeMetricsRule{MetricsScheduler},
106106
expected: withSchedulerMetrics(),
107107
},
108+
{
109+
name: "allow debug",
110+
rules: []GoRuntimeMetricsRule{MetricsDebug},
111+
expected: withDebugMetrics(),
112+
},
108113
} {
109114
t.Run(test.name, func(t *testing.T) {
110115
reg := prometheus.NewRegistry()

0 commit comments

Comments
 (0)