feat(go): expose gateway frame duration histogram

This commit is contained in:
lingniu
2026-07-03 18:54:00 +08:00
parent 71905aca3d
commit 16ee09180c
10 changed files with 182 additions and 9 deletions

View File

@@ -46,6 +46,27 @@ func TestRegistryRendersGaugesWithLabels(t *testing.T) {
}
}
func TestRegistryObservesHistogramBuckets(t *testing.T) {
registry := NewRegistry()
registry.ObserveHistogram("vehicle_gateway_frame_duration_ms", Labels{"protocol": "JT808"}, []float64{1, 5, 10}, 7)
text := registry.Render()
for _, want := range []string{
`# TYPE vehicle_gateway_frame_duration_ms histogram`,
`vehicle_gateway_frame_duration_ms_bucket{le="1",protocol="JT808"} 0`,
`vehicle_gateway_frame_duration_ms_bucket{le="5",protocol="JT808"} 0`,
`vehicle_gateway_frame_duration_ms_bucket{le="10",protocol="JT808"} 1`,
`vehicle_gateway_frame_duration_ms_bucket{le="+Inf",protocol="JT808"} 1`,
`vehicle_gateway_frame_duration_ms_count{protocol="JT808"} 1`,
`vehicle_gateway_frame_duration_ms_sum{protocol="JT808"} 7`,
} {
if !strings.Contains(text, want) {
t.Fatalf("histogram missing %s:\n%s", want, text)
}
}
}
func TestRegistryRecordsKafkaLagGauge(t *testing.T) {
registry := NewRegistry()