Skip to content

Commit 854d930

Browse files
committed
Fix convention violating names for generated collector metrics
Signed-off-by: Kemal Akkoyun <[email protected]>
1 parent 0222f88 commit 854d930

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [CHANGE] Minimum required Go version is now 1.16.
44
* [CHANGE] Added `collectors.WithGoCollections` that allows to choose what collection of Go runtime metrics user wants: Equivalent of [`MemStats` structure](https://pkg.go.dev/runtime#MemStats) configured using `GoRuntimeMemStatsCollection`, new based on dedicated [runtime/metrics](https://pkg.go.dev/runtime/metrics) metrics represented by `GoRuntimeMetricsCollection` option, or both by specifying `GoRuntimeMemStatsCollection | GoRuntimeMetricsCollection` flag.
55
* [CHANGE] :warning: Change in `collectors.NewGoCollector` metrics: Reverting addition of new ~80 runtime metrics by default. You can enable this back with `GoRuntimeMetricsCollection` option or `GoRuntimeMemStatsCollection | GoRuntimeMetricsCollection` for smooth transition.
6+
* [BUGFIX] Fix the bug that causes generated histogram metric names to end with `_total`. `go_gc_heap_allocs_by_size_bytes_total` -> `go_gc_heap_allocs_by_size_bytes`, `go_gc_heap_frees_by_size_bytes_total` -> `go_gc_heap_allocs_by_size_bytes` and`go_gc_pauses_seconds_total` -> `go_gc_pauses_seconds`.
67

78
## 1.12.1 / 2022-01-29
89

prometheus/gen_go_collector_metrics_set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ func main() {
3939
}
4040
toolVersion := runtime.Version()
4141
mtv := majorVersion(toolVersion)
42-
mv != majorVersion(os.Args[1])
42+
mv := majorVersion(os.Args[1])
4343
if mtv != mv {
4444
log.Fatalf("using Go version %q but expected Go version %q", mtv, mv)
4545
}
46-
version, err := parseVersion(os.Args[1])
46+
version, err := parseVersion(mv)
4747
if err != nil {
4848
log.Fatalf("parsing Go version: %v", err)
4949
}

prometheus/go_collector_latest_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import (
2424
"sync"
2525
"testing"
2626

27-
"github.com/prometheus/client_golang/prometheus/internal"
2827
dto "github.com/prometheus/client_model/go"
28+
29+
"github.com/prometheus/client_golang/prometheus/internal"
2930
)
3031

3132
func TestRmForMemStats(t *testing.T) {
@@ -121,7 +122,7 @@ func TestBatchHistogram(t *testing.T) {
121122

122123
var mhist Metric
123124
for _, m := range goMetrics {
124-
if m.Desc().fqName == "go_gc_heap_allocs_by_size_bytes_total" {
125+
if m.Desc().fqName == "go_gc_heap_allocs_by_size_bytes" {
125126
mhist = m
126127
break
127128
}

prometheus/go_collector_metrics_go117_test.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prometheus/go_collector_metrics_go118_test.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prometheus/internal/go_runtime_metrics.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func RuntimeMetricsToProm(d *metrics.Description) (string, string, string, bool)
6262
// other data.
6363
name = strings.ReplaceAll(name, "-", "_")
6464
name = name + "_" + unit
65-
if d.Cumulative {
65+
if d.Cumulative && d.Kind != metrics.KindFloat64Histogram {
6666
name = name + "_total"
6767
}
6868

@@ -84,12 +84,12 @@ func RuntimeMetricsToProm(d *metrics.Description) (string, string, string, bool)
8484
func RuntimeMetricsBucketsForUnit(buckets []float64, unit string) []float64 {
8585
switch unit {
8686
case "bytes":
87-
// Rebucket as powers of 2.
88-
return rebucketExp(buckets, 2)
87+
// Re-bucket as powers of 2.
88+
return reBucketExp(buckets, 2)
8989
case "seconds":
90-
// Rebucket as powers of 10 and then merge all buckets greater
90+
// Re-bucket as powers of 10 and then merge all buckets greater
9191
// than 1 second into the +Inf bucket.
92-
b := rebucketExp(buckets, 10)
92+
b := reBucketExp(buckets, 10)
9393
for i := range b {
9494
if b[i] <= 1 {
9595
continue
@@ -103,11 +103,11 @@ func RuntimeMetricsBucketsForUnit(buckets []float64, unit string) []float64 {
103103
return buckets
104104
}
105105

106-
// rebucketExp takes a list of bucket boundaries (lower bound inclusive) and
106+
// reBucketExp takes a list of bucket boundaries (lower bound inclusive) and
107107
// downsamples the buckets to those a multiple of base apart. The end result
108108
// is a roughly exponential (in many cases, perfectly exponential) bucketing
109109
// scheme.
110-
func rebucketExp(buckets []float64, base float64) []float64 {
110+
func reBucketExp(buckets []float64, base float64) []float64 {
111111
bucket := buckets[0]
112112
var newBuckets []float64
113113
// We may see a -Inf here, in which case, add it and skip it

0 commit comments

Comments
 (0)