chore: establish local platform baseline
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package observability
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var (
|
||||
dependencyUp = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: "voice_platform", Subsystem: "dependency", Name: "up",
|
||||
Help: "Whether the last dependency check succeeded.",
|
||||
}, []string{"service", "dependency"})
|
||||
dependencyCheckDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: "voice_platform", Subsystem: "dependency", Name: "check_duration_seconds",
|
||||
Help: "Dependency check duration.",
|
||||
Buckets: []float64{0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2},
|
||||
}, []string{"service", "dependency"})
|
||||
)
|
||||
|
||||
func InstrumentDependencyCheck(serviceName, dependency string, check func(context.Context) error) func(context.Context) error {
|
||||
return func(ctx context.Context) error {
|
||||
startedAt := time.Now()
|
||||
err := check(ctx)
|
||||
dependencyCheckDuration.WithLabelValues(serviceName, dependency).Observe(time.Since(startedAt).Seconds())
|
||||
if err != nil {
|
||||
dependencyUp.WithLabelValues(serviceName, dependency).Set(0)
|
||||
return err
|
||||
}
|
||||
dependencyUp.WithLabelValues(serviceName, dependency).Set(1)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user