forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package fiber
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// TestMetricsBoundUnknownMethods keeps arbitrary client methods out of metric labels.
|
||||
func TestMetricsBoundUnknownMethods(t *testing.T) {
|
||||
ctrl := testController(t, nil)
|
||||
raw := &fasthttp.RequestCtx{}
|
||||
raw.Request.Header.SetMethod("CUSTOM_RANDOM_METHOD")
|
||||
raw.Response.SetStatusCode(http.StatusTemporaryRedirect)
|
||||
ctx := ctrl.server.AcquireCtx(raw)
|
||||
defer ctrl.server.ReleaseCtx(ctx)
|
||||
ctrl.metrics.observe(ctx, time.Millisecond)
|
||||
families, err := ctrl.metrics.registry.Gather()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
found := false
|
||||
for _, family := range families {
|
||||
for _, metric := range family.Metric {
|
||||
for _, label := range metric.Label {
|
||||
if label.GetValue() == "CUSTOM_RANDOM_METHOD" {
|
||||
t.Fatal("unbounded method label")
|
||||
}
|
||||
found = found || label.GetValue() == "other"
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("unknown method was not grouped")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user