forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestTelemetryConfiguration validates bounded sampling and credential-free Collector addresses.
|
||||
func TestTelemetryConfiguration(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
endpoint string
|
||||
ratio string
|
||||
wantError bool
|
||||
}{
|
||||
{"disabled", "", "", false},
|
||||
{"enabled", "http://collector:4318", "0.5", false},
|
||||
{"bad ratio", "", "bad", true},
|
||||
{"NaN", "", "NaN", true},
|
||||
{"negative", "", "-0.1", true},
|
||||
{"over one", "", "1.1", true},
|
||||
{"credentials", "http://user:pass@collector:4318", "", true},
|
||||
{"query", "http://collector:4318?token=x", "", true},
|
||||
{"bad scheme", "ftp://collector", "", true},
|
||||
{"relative", "collector:4318", "", true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", tc.endpoint)
|
||||
t.Setenv("OTEL_SAMPLE_RATIO", tc.ratio)
|
||||
cfg, err := NewTelemetry("messenger-api")
|
||||
if (err != nil) != tc.wantError {
|
||||
t.Fatalf("configuration: %v", err)
|
||||
}
|
||||
if err == nil && (cfg.Instance == "" || cfg.Version == "" || cfg.Service != "messenger-api") {
|
||||
t.Fatal("resource identity missing")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user