落地结构化日志与基础监控告警
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package observability
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCollectorSnapshot(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
c := NewCollector()
|
||||
c.Observe(200, 100*time.Millisecond)
|
||||
c.Observe(404, 300*time.Millisecond)
|
||||
c.Observe(500, 500*time.Millisecond)
|
||||
|
||||
s := c.Snapshot()
|
||||
if s.TotalRequests != 3 {
|
||||
t.Fatalf("total_requests=%d, want=3", s.TotalRequests)
|
||||
}
|
||||
if s.ClientErrors != 1 {
|
||||
t.Fatalf("client_errors=%d, want=1", s.ClientErrors)
|
||||
}
|
||||
if s.ServerErrors != 1 {
|
||||
t.Fatalf("server_errors=%d, want=1", s.ServerErrors)
|
||||
}
|
||||
if s.ServerErrorRatePct <= 0 {
|
||||
t.Fatalf("server_error_rate_pct=%f, want>0", s.ServerErrorRatePct)
|
||||
}
|
||||
if s.AvgLatencyMs <= 0 {
|
||||
t.Fatalf("avg_latency_ms=%f, want>0", s.AvgLatencyMs)
|
||||
}
|
||||
if s.MaxLatencyMs < 500 {
|
||||
t.Fatalf("max_latency_ms=%f, want>=500", s.MaxLatencyMs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user