Skip to content

Commit 79042c6

Browse files
authored
Fix bug unit cpu-seconds not a suffix of metric go_cpu_classes_gc_mark_assist_cpu_seconds (#1991)
Signed-off-by: Arianna Vespri <arianna.vespri@yahoo.it>
1 parent 773db0a commit 79042c6

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

prometheus/go_collector_latest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,13 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector {
211211
sampleMap[d.Name] = &sampleBuf[len(sampleBuf)-1]
212212

213213
// Extract unit from the runtime/metrics name (e.g., "/gc/heap/allocs:bytes" -> "bytes")
214+
// and sanitize to match Prometheus naming conventions (e.g., "cpu-seconds" -> "cpu_seconds")
214215
var unit string
215216
if idx := strings.IndexRune(d.Name, ':'); idx >= 0 {
216217
unit = d.Name[idx+1:]
218+
unit = strings.ReplaceAll(unit, "-", "_")
219+
unit = strings.ReplaceAll(unit, "*", "_")
220+
unit = strings.ReplaceAll(unit, "/", "_per_")
217221
}
218222

219223
var m collectorMetric

prometheus/go_collector_latest_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ func TestGoCollectorRuntimeMetricsUnit(t *testing.T) {
434434
{"go_gc_heap_frees_bytes_total", "bytes"},
435435
{"go_sched_goroutines_goroutines", "goroutines"},
436436
{"go_gc_gomemlimit_bytes", "bytes"},
437+
{"go_cpu_classes_gc_mark_assist_cpu_seconds_total", "cpu_seconds"},
438+
{"go_gc_cycles_total_gc_cycles_total", "gc_cycles"},
437439
}
438440

439441
for _, tc := range testCases {

0 commit comments

Comments
 (0)