Skip to content

Commit

Permalink
Merge pull request #1389 from prometheus/fix-lint-issue
Browse files Browse the repository at this point in the history
gocollector: Add regex option to allow collection of debug runtime metrics
  • Loading branch information
ArthurSens committed Apr 8, 2024
2 parents c586fcc + 0f50003 commit e133e49
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
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

0 comments on commit e133e49

Please sign in to comment.