feat(go): expose realtime store latency histogram
This commit is contained in:
@@ -249,6 +249,8 @@ type storeMetricUpdater struct {
|
||||
registry *metrics.Registry
|
||||
}
|
||||
|
||||
var realtimeStoreUpdateDurationBucketsMS = []float64{1, 5, 10, 25, 50, 100, 250, 500, 1000, 5000}
|
||||
|
||||
func (u storeMetricUpdater) Update(ctx context.Context, env envelope.FrameEnvelope) error {
|
||||
if u.delegate == nil {
|
||||
return nil
|
||||
@@ -261,16 +263,15 @@ func (u storeMetricUpdater) Update(ctx context.Context, env envelope.FrameEnvelo
|
||||
status = "error"
|
||||
}
|
||||
if u.registry != nil {
|
||||
u.registry.IncCounter("vehicle_realtime_store_updates_total", metrics.Labels{
|
||||
labels := metrics.Labels{
|
||||
"store": u.store,
|
||||
"protocol": string(env.Protocol),
|
||||
"status": status,
|
||||
})
|
||||
u.registry.SetGauge("vehicle_realtime_store_update_duration_ms", metrics.Labels{
|
||||
"store": u.store,
|
||||
"protocol": string(env.Protocol),
|
||||
"status": status,
|
||||
}, float64(elapsed.Milliseconds()))
|
||||
}
|
||||
elapsedMS := float64(elapsed.Milliseconds())
|
||||
u.registry.IncCounter("vehicle_realtime_store_updates_total", labels)
|
||||
u.registry.SetGauge("vehicle_realtime_store_update_duration_ms", labels, elapsedMS)
|
||||
u.registry.ObserveHistogram("vehicle_realtime_store_update_duration_ms_histogram", labels, realtimeStoreUpdateDurationBucketsMS, elapsedMS)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -179,6 +179,9 @@ func TestStoreMetricUpdaterRecordsStoreUpdateResults(t *testing.T) {
|
||||
for _, want := range []string{
|
||||
`vehicle_realtime_store_updates_total{protocol="JT808",status="ok",store="redis"} 1`,
|
||||
`vehicle_realtime_store_update_duration_ms{protocol="JT808",status="ok",store="redis"}`,
|
||||
`vehicle_realtime_store_update_duration_ms_histogram_bucket{le="+Inf",protocol="JT808",status="ok",store="redis"} 1`,
|
||||
`vehicle_realtime_store_update_duration_ms_histogram_count{protocol="JT808",status="ok",store="redis"} 1`,
|
||||
`vehicle_realtime_store_update_duration_ms_histogram_sum{protocol="JT808",status="ok",store="redis"}`,
|
||||
} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Fatalf("store update metric missing %s:\n%s", want, text)
|
||||
|
||||
Reference in New Issue
Block a user