Skip to content

Commit 80821a5

Browse files
authored
Merge pull request #6 from simonpasquier/fix-metric-namees
Update metric names to match Prometheus conventions
2 parents 4c2d577 + 890562f commit 80821a5

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
github.com/google/go-cmp v0.6.0 // indirect
2424
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
2525
github.com/kr/text v0.2.0 // indirect
26+
github.com/kylelemons/godebug v1.1.0 // indirect
2627
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
2728
github.com/prometheus/client_model v0.6.1 // indirect
2829
github.com/prometheus/common v0.62.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
2323
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
2424
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2525
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
26+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
27+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
2628
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
2729
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
2830
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=

metrics/metric_observer.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ var _ async.RoutinesObserver = (*metricObserver)(nil)
1313
type metricObserver struct{}
1414

1515
var (
16-
runningManagedRoutinesCount = prometheus.NewGauge(
16+
runningRoutines = prometheus.NewGauge(
1717
prometheus.GaugeOpts{
18-
Name: "async_routine_manager_routines_total",
19-
Help: "The total number of running manager routines.",
18+
Name: "async_routine_manager_routines",
19+
Help: "Number of running routines.",
2020
},
2121
)
2222

23-
runningManagedRoutinesByNameCount = prometheus.NewGaugeVec(
23+
runningRoutinesByName = prometheus.NewGaugeVec(
2424
prometheus.GaugeOpts{
25-
Name: "async_routine_manager_routines_instances_count",
26-
Help: "The total number of running instance of a given routine.",
25+
Name: "async_routine_manager_routine_instances",
26+
Help: "Number of running instances of a given routine.",
2727
},
2828
[]string{"routine_name", "data"},
2929
)
3030
)
3131

3232
func init() {
33-
prometheus.MustRegister(runningManagedRoutinesCount)
34-
prometheus.MustRegister(runningManagedRoutinesByNameCount)
33+
prometheus.MustRegister(runningRoutines)
34+
prometheus.MustRegister(runningRoutinesByName)
3535
}
3636

3737
func mapToString(m map[string]string) string {
@@ -55,13 +55,13 @@ func mapToString(m map[string]string) string {
5555
}
5656

5757
func (m *metricObserver) RoutineStarted(routine async.AsyncRoutine) {
58-
runningManagedRoutinesByNameCount.
58+
runningRoutinesByName.
5959
With(prometheus.Labels{"routine_name": routine.Name(), "data": mapToString(routine.GetData())}).
6060
Inc()
6161
}
6262

6363
func (m *metricObserver) RoutineFinished(routine async.AsyncRoutine) {
64-
runningManagedRoutinesByNameCount.
64+
runningRoutinesByName.
6565
With(prometheus.Labels{"routine_name": routine.Name(), "data": mapToString(routine.GetData())}).
6666
Dec()
6767
}
@@ -70,7 +70,7 @@ func (m *metricObserver) RoutineExceededTimebox(routine async.AsyncRoutine) {
7070
}
7171

7272
func (m *metricObserver) RunningRoutineCount(count int) {
73-
runningManagedRoutinesCount.Set(float64(count))
73+
runningRoutines.Set(float64(count))
7474
}
7575

7676
func (m *metricObserver) RunningRoutineByNameCount(name string, count int) {

metrics/metric_observer_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package metrics
2+
3+
import (
4+
"testing"
5+
6+
"github.com/prometheus/client_golang/prometheus"
7+
"github.com/prometheus/client_golang/prometheus/testutil"
8+
)
9+
10+
func TestPrometheusMetrics(t *testing.T) {
11+
problems, err := testutil.GatherAndLint(prometheus.DefaultGatherer)
12+
if err != nil {
13+
t.Fatal(err)
14+
}
15+
16+
for _, p := range problems {
17+
t.Errorf("found linting issue: %s: %s", p.Metric, p.Text)
18+
}
19+
}

0 commit comments

Comments
 (0)