feat(multiplayer): export bounded API metrics

This commit is contained in:
Josh Creek
2026-09-01 17:06:38 +01:00
parent d85c8b8194
commit f1b8366531
7 changed files with 217 additions and 5 deletions
+24
View File
@@ -0,0 +1,24 @@
package observability
import (
"strings"
"testing"
"time"
)
func TestMetricsNormalizesOperationsAndExportsBoundedLabels(t *testing.T) {
m := NewMetrics()
m.ObserveAPI("queue", 201, 10*time.Millisecond)
m.ObserveAPI("/crafted/path/with-secret", 500, time.Second)
var output strings.Builder
if err := m.WritePrometheus(&output); err != nil {
t.Fatal(err)
}
text := output.String()
if !strings.Contains(text, `operation="queue",status="2xx"`) || !strings.Contains(text, `operation="other",status="5xx"`) {
t.Fatalf("metrics output = %s", text)
}
if strings.Contains(text, "crafted") || strings.Contains(text, "secret") {
t.Fatalf("unbounded operation label leaked: %s", text)
}
}