gocollector: Add regex option to allow collection of debug runtime metrics

Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
This commit is contained in:
Arthur Silva Sens 2023-11-29 16:10:53 -03:00
parent c586fcc216
commit 0f500036fc
No known key found for this signature in database
6 changed files with 26 additions and 8 deletions

View File

@ -128,7 +128,7 @@ 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)
@ -136,13 +136,11 @@ func groupMetrics(metricsList []string) []metricGroup {
}
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
}

View File

@ -98,3 +98,7 @@ func withSchedulerMetrics() []string {
"go_threads",
}
}
func withDebugMetrics() []string {
return withBaseMetrics([]string{})
}

View File

@ -105,3 +105,7 @@ func withSchedulerMetrics() []string {
"go_threads",
}
}
func withDebugMetrics() []string {
return withBaseMetrics([]string{})
}

View File

@ -112,3 +112,7 @@ func withSchedulerMetrics() []string {
"go_sched_latencies_seconds",
})
}
func withDebugMetrics() []string {
return withBaseMetrics([]string{})
}

View File

@ -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:

View File

@ -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()