Skip to content
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
14 changes: 6 additions & 8 deletions prometheus/collectors/gen_go_collector_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,19 @@ func rm2prom(d metrics.Description) string {
func groupMetrics(metricsList []string) []metricGroup {
var groupedMetrics []metricGroup
for _, group := range metricGroups {
var matchedMetrics []string
matchedMetrics := make([]string, 0)
for _, metric := range metricsList {
if group.Regex == nil || group.Regex.MatchString(metric) {
matchedMetrics = append(matchedMetrics, metric)
}
}

sort.Strings(matchedMetrics)
if len(matchedMetrics) > 0 {
groupedMetrics = append(groupedMetrics, metricGroup{
Name: group.Name,
Regex: group.Regex,
Metrics: matchedMetrics,
})
}
groupedMetrics = append(groupedMetrics, metricGroup{
Name: group.Name,
Regex: group.Regex,
Metrics: matchedMetrics,
})
}
return groupedMetrics
}
Expand Down
4 changes: 4 additions & 0 deletions prometheus/collectors/go_collector_go117_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,7 @@ func withSchedulerMetrics() []string {
"go_threads",
}
}

func withDebugMetrics() []string {
return withBaseMetrics([]string{})
}
4 changes: 4 additions & 0 deletions prometheus/collectors/go_collector_go119_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ func withSchedulerMetrics() []string {
"go_threads",
}
}

func withDebugMetrics() []string {
return withBaseMetrics([]string{})
}
4 changes: 4 additions & 0 deletions prometheus/collectors/go_collector_go120_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ func withSchedulerMetrics() []string {
"go_sched_latencies_seconds",
})
}

func withDebugMetrics() []string {
return withBaseMetrics([]string{})
}
3 changes: 3 additions & 0 deletions prometheus/collectors/go_collector_latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ var (
// MetricsScheduler allows only scheduler metrics to be collected from Go runtime.
// e.g. go_sched_goroutines_goroutines
MetricsScheduler = GoRuntimeMetricsRule{regexp.MustCompile(`^/sched/.*`)}
// MetricsDebug allows only debug metrics to be collected from Go runtime.
// e.g. go_godebug_non_default_behavior_gocachetest_events_total
MetricsDebug = GoRuntimeMetricsRule{regexp.MustCompile(`^/godebug/.*`)}
)

// WithGoCollectorMemStatsMetricsDisabled disables metrics that is gathered in runtime.MemStats structure such as:
Expand Down
5 changes: 5 additions & 0 deletions prometheus/collectors/go_collector_latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func TestGoCollectorAllowList(t *testing.T) {
rules: []GoRuntimeMetricsRule{MetricsScheduler},
expected: withSchedulerMetrics(),
},
{
name: "allow debug",
rules: []GoRuntimeMetricsRule{MetricsDebug},
expected: withDebugMetrics(),
},
} {
t.Run(test.name, func(t *testing.T) {
reg := prometheus.NewRegistry()
Expand Down