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 18bef18
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
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 18bef18

Please sign in to comment.