mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-16 09:22:21 +00:00
feat(multiplayer): export bounded API metrics
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user