feat: add bounded operational metrics
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHealthHandlerReadinessAndMetrics_HP_OPS_01(t *testing.T) {
|
||||
@@ -35,8 +36,36 @@ func TestHealthMetricNamesAreBounded_BH_OPS_01(t *testing.T) {
|
||||
t.Parallel()
|
||||
health := New()
|
||||
health.Inc("bad name")
|
||||
health.Inc("1bad_name")
|
||||
_, _, counters := health.Snapshot()
|
||||
if len(counters) != 0 {
|
||||
t.Fatalf("invalid metric name recorded: %#v", counters)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthRendersBoundedGaugesAndDurationHistograms_HP_OPS_02(t *testing.T) {
|
||||
t.Parallel()
|
||||
health := New()
|
||||
health.SetGauge("client_spool_bytes", 4096)
|
||||
health.SetGauge("bad gauge", 1)
|
||||
health.ObserveDuration("dispatch_latency", 12*time.Millisecond)
|
||||
health.ObserveDuration("bad latency", time.Second)
|
||||
|
||||
metrics := httptest.NewRecorder()
|
||||
health.Handler(Paths{}).ServeHTTP(metrics, httptest.NewRequest(http.MethodGet, "/metrics", nil))
|
||||
body := metrics.Body.String()
|
||||
for _, want := range []string{
|
||||
"rvbox_client_spool_bytes 4096",
|
||||
"rvbox_dispatch_latency_seconds_bucket{le=\"0.05\"} 1",
|
||||
"rvbox_dispatch_latency_seconds_bucket{le=\"+Inf\"} 1",
|
||||
"rvbox_dispatch_latency_seconds_sum 0.012",
|
||||
"rvbox_dispatch_latency_seconds_count 1",
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Fatalf("metrics missing %q:\n%s", want, body)
|
||||
}
|
||||
}
|
||||
if strings.Contains(body, "bad gauge") || strings.Contains(body, "bad latency") {
|
||||
t.Fatalf("unbounded metric name rendered: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user