Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.62.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
Expand Down
22 changes: 11 additions & 11 deletions metrics/metric_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ var _ async.RoutinesObserver = (*metricObserver)(nil)
type metricObserver struct{}

var (
runningManagedRoutinesCount = prometheus.NewGauge(
runningRoutines = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "async_routine_manager_routines_total",
Help: "The total number of running manager routines.",
Name: "async_routine_manager_routines",
Help: "Number of running routines.",
},
)

runningManagedRoutinesByNameCount = prometheus.NewGaugeVec(
runningRoutinesByName = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "async_routine_manager_routines_instances_count",
Help: "The total number of running instance of a given routine.",
Name: "async_routine_manager_routine_instances",
Help: "Number of running instances of a given routine.",
},
[]string{"routine_name", "data"},
)
)

func init() {
prometheus.MustRegister(runningManagedRoutinesCount)
prometheus.MustRegister(runningManagedRoutinesByNameCount)
prometheus.MustRegister(runningRoutines)
prometheus.MustRegister(runningRoutinesByName)
}

func mapToString(m map[string]string) string {
Expand All @@ -55,13 +55,13 @@ func mapToString(m map[string]string) string {
}

func (m *metricObserver) RoutineStarted(routine async.AsyncRoutine) {
runningManagedRoutinesByNameCount.
runningRoutinesByName.
With(prometheus.Labels{"routine_name": routine.Name(), "data": mapToString(routine.GetData())}).
Inc()
}

func (m *metricObserver) RoutineFinished(routine async.AsyncRoutine) {
runningManagedRoutinesByNameCount.
runningRoutinesByName.
With(prometheus.Labels{"routine_name": routine.Name(), "data": mapToString(routine.GetData())}).
Dec()
}
Expand All @@ -70,7 +70,7 @@ func (m *metricObserver) RoutineExceededTimebox(routine async.AsyncRoutine) {
}

func (m *metricObserver) RunningRoutineCount(count int) {
runningManagedRoutinesCount.Set(float64(count))
runningRoutines.Set(float64(count))
}

func (m *metricObserver) RunningRoutineByNameCount(name string, count int) {
Expand Down
19 changes: 19 additions & 0 deletions metrics/metric_observer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package metrics

import (
"testing"

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

func TestPrometheusMetrics(t *testing.T) {
problems, err := testutil.GatherAndLint(prometheus.DefaultGatherer)
if err != nil {
t.Fatal(err)
}

for _, p := range problems {
t.Errorf("found linting issue: %s: %s", p.Metric, p.Text)
}
}