diff --git a/prober/http_test.go b/prober/http_test.go index 2d28d4ff..4c67dde7 100644 --- a/prober/http_test.go +++ b/prober/http_test.go @@ -920,18 +920,15 @@ func TestFailIfNotSSLLogMsg(t *testing.T) { }, } { t.Run(title, func(t *testing.T) { - recorder := logRecorder{next: promslog.NewNopLogger()} registry := prometheus.NewRegistry() testCTX, cancel := context.WithTimeout(context.Background(), Timeout) defer cancel() - logger := slog.New(&recorder) - result := ProbeHTTP(testCTX, tc.URL, tc.Config, registry, logger) - result.log(logger, 1) + result := ProbeHTTP(testCTX, tc.URL, tc.Config, registry, promslog.NewNopLogger()) if result.success != tc.Success { t.Fatalf("Expected success=%v, got=%v", tc.Success, result) } - if seen := recorder.msgs[Msg]; seen != tc.MessageExpected { + if seen := result.failureReason == Msg; seen != tc.MessageExpected { t.Fatalf("SSL message expected=%v, seen=%v", tc.MessageExpected, seen) } }) diff --git a/prober/prober.go b/prober/prober.go index 5e8abf97..e62d4fa5 100644 --- a/prober/prober.go +++ b/prober/prober.go @@ -58,7 +58,7 @@ func (r *ProbeResult) failureInfoGauge() *prometheus.GaugeVec { } else if r.failureReason == "" { // Should not happen, but there theoretically might be an // inconsistent state of the struct. - r.failureReason = "unknown" + r.failureReason = "Unkown" } labels := []string{"reason"} @@ -85,15 +85,18 @@ func (r *ProbeResult) log(logger *slog.Logger, duration float64) { if r.failureReason == "" { // Should not happen, but there theoretically might be an // inconsistent state of the struct. - r.failureReason = "unknown" + r.failureReason = "Probe failed for unkown reason" } // converting the []string slice to an []any slice is a bit finicky - logDetails := make([]any, 0, len(r.failureDetails)+2) + logDetails := make([]any, 0, len(r.failureDetails)+4) + logDetails = append(logDetails, "reason") + logDetails = append(logDetails, r.failureReason) for _, d := range r.failureDetails { logDetails = append(logDetails, d) } - logger.Error(r.failureReason, logDetails...) - logger.Error("Probe failed", "duration_seconds", duration) + logDetails = append(logDetails, "duration") + logDetails = append(logDetails, duration) + logger.Error("Probe failed", logDetails...) } }