Skip to content

Commit

Permalink
Fix convention violating names for generated collector metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
  • Loading branch information
kakkoyun committed May 6, 2022
1 parent 0222f88 commit 854d930
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
* [CHANGE] Minimum required Go version is now 1.16.
* [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.
* [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.
* [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`.

## 1.12.1 / 2022-01-29

Expand Down
4 changes: 2 additions & 2 deletions prometheus/gen_go_collector_metrics_set.go
Expand Up @@ -39,11 +39,11 @@ func main() {
}
toolVersion := runtime.Version()
mtv := majorVersion(toolVersion)
mv != majorVersion(os.Args[1])
mv := majorVersion(os.Args[1])
if mtv != mv {
log.Fatalf("using Go version %q but expected Go version %q", mtv, mv)
}
version, err := parseVersion(os.Args[1])
version, err := parseVersion(mv)
if err != nil {
log.Fatalf("parsing Go version: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions prometheus/go_collector_latest_test.go
Expand Up @@ -24,8 +24,9 @@ import (
"sync"
"testing"

"github.com/prometheus/client_golang/prometheus/internal"
dto "github.com/prometheus/client_model/go"

"github.com/prometheus/client_golang/prometheus/internal"
)

func TestRmForMemStats(t *testing.T) {
Expand Down Expand Up @@ -121,7 +122,7 @@ func TestBatchHistogram(t *testing.T) {

var mhist Metric
for _, m := range goMetrics {
if m.Desc().fqName == "go_gc_heap_allocs_by_size_bytes_total" {
if m.Desc().fqName == "go_gc_heap_allocs_by_size_bytes" {
mhist = m
break
}
Expand Down
6 changes: 3 additions & 3 deletions prometheus/go_collector_metrics_go117_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions prometheus/go_collector_metrics_go118_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions prometheus/internal/go_runtime_metrics.go
Expand Up @@ -62,7 +62,7 @@ func RuntimeMetricsToProm(d *metrics.Description) (string, string, string, bool)
// other data.
name = strings.ReplaceAll(name, "-", "_")
name = name + "_" + unit
if d.Cumulative {
if d.Cumulative && d.Kind != metrics.KindFloat64Histogram {
name = name + "_total"
}

Expand All @@ -84,12 +84,12 @@ func RuntimeMetricsToProm(d *metrics.Description) (string, string, string, bool)
func RuntimeMetricsBucketsForUnit(buckets []float64, unit string) []float64 {
switch unit {
case "bytes":
// Rebucket as powers of 2.
return rebucketExp(buckets, 2)
// Re-bucket as powers of 2.
return reBucketExp(buckets, 2)
case "seconds":
// Rebucket as powers of 10 and then merge all buckets greater
// Re-bucket as powers of 10 and then merge all buckets greater
// than 1 second into the +Inf bucket.
b := rebucketExp(buckets, 10)
b := reBucketExp(buckets, 10)
for i := range b {
if b[i] <= 1 {
continue
Expand All @@ -103,11 +103,11 @@ func RuntimeMetricsBucketsForUnit(buckets []float64, unit string) []float64 {
return buckets
}

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

0 comments on commit 854d930

Please sign in to comment.