Merge pull request #1389 from prometheus/fix-lint-issue
gocollector: Add regex option to allow collection of debug runtime metrics
This commit is contained in:
commit
e133e49029
|
@ -128,7 +128,7 @@ func rm2prom(d metrics.Description) string {
|
||||||
func groupMetrics(metricsList []string) []metricGroup {
|
func groupMetrics(metricsList []string) []metricGroup {
|
||||||
var groupedMetrics []metricGroup
|
var groupedMetrics []metricGroup
|
||||||
for _, group := range metricGroups {
|
for _, group := range metricGroups {
|
||||||
var matchedMetrics []string
|
matchedMetrics := make([]string, 0)
|
||||||
for _, metric := range metricsList {
|
for _, metric := range metricsList {
|
||||||
if group.Regex == nil || group.Regex.MatchString(metric) {
|
if group.Regex == nil || group.Regex.MatchString(metric) {
|
||||||
matchedMetrics = append(matchedMetrics, metric)
|
matchedMetrics = append(matchedMetrics, metric)
|
||||||
|
@ -136,14 +136,12 @@ func groupMetrics(metricsList []string) []metricGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(matchedMetrics)
|
sort.Strings(matchedMetrics)
|
||||||
if len(matchedMetrics) > 0 {
|
|
||||||
groupedMetrics = append(groupedMetrics, metricGroup{
|
groupedMetrics = append(groupedMetrics, metricGroup{
|
||||||
Name: group.Name,
|
Name: group.Name,
|
||||||
Regex: group.Regex,
|
Regex: group.Regex,
|
||||||
Metrics: matchedMetrics,
|
Metrics: matchedMetrics,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return groupedMetrics
|
return groupedMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,3 +98,7 @@ func withSchedulerMetrics() []string {
|
||||||
"go_threads",
|
"go_threads",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func withDebugMetrics() []string {
|
||||||
|
return withBaseMetrics([]string{})
|
||||||
|
}
|
||||||
|
|
|
@ -105,3 +105,7 @@ func withSchedulerMetrics() []string {
|
||||||
"go_threads",
|
"go_threads",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func withDebugMetrics() []string {
|
||||||
|
return withBaseMetrics([]string{})
|
||||||
|
}
|
||||||
|
|
|
@ -112,3 +112,7 @@ func withSchedulerMetrics() []string {
|
||||||
"go_sched_latencies_seconds",
|
"go_sched_latencies_seconds",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func withDebugMetrics() []string {
|
||||||
|
return withBaseMetrics([]string{})
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,9 @@ var (
|
||||||
// MetricsScheduler allows only scheduler metrics to be collected from Go runtime.
|
// MetricsScheduler allows only scheduler metrics to be collected from Go runtime.
|
||||||
// e.g. go_sched_goroutines_goroutines
|
// e.g. go_sched_goroutines_goroutines
|
||||||
MetricsScheduler = GoRuntimeMetricsRule{regexp.MustCompile(`^/sched/.*`)}
|
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:
|
// WithGoCollectorMemStatsMetricsDisabled disables metrics that is gathered in runtime.MemStats structure such as:
|
||||||
|
|
|
@ -105,6 +105,11 @@ func TestGoCollectorAllowList(t *testing.T) {
|
||||||
rules: []GoRuntimeMetricsRule{MetricsScheduler},
|
rules: []GoRuntimeMetricsRule{MetricsScheduler},
|
||||||
expected: withSchedulerMetrics(),
|
expected: withSchedulerMetrics(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "allow debug",
|
||||||
|
rules: []GoRuntimeMetricsRule{MetricsDebug},
|
||||||
|
expected: withDebugMetrics(),
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
reg := prometheus.NewRegistry()
|
reg := prometheus.NewRegistry()
|
||||||
|
|
Loading…
Reference in New Issue