Skip to content

Commit 4df06d6

Browse files
committed
Put failure results on one log line
1 parent ea56b66 commit 4df06d6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

prober/http_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -920,18 +920,15 @@ func TestFailIfNotSSLLogMsg(t *testing.T) {
920920
},
921921
} {
922922
t.Run(title, func(t *testing.T) {
923-
recorder := logRecorder{next: promslog.NewNopLogger()}
924923
registry := prometheus.NewRegistry()
925924
testCTX, cancel := context.WithTimeout(context.Background(), Timeout)
926925
defer cancel()
927926

928-
logger := slog.New(&recorder)
929-
result := ProbeHTTP(testCTX, tc.URL, tc.Config, registry, logger)
930-
result.log(logger, 1)
927+
result := ProbeHTTP(testCTX, tc.URL, tc.Config, registry, promslog.NewNopLogger())
931928
if result.success != tc.Success {
932929
t.Fatalf("Expected success=%v, got=%v", tc.Success, result)
933930
}
934-
if seen := recorder.msgs[Msg]; seen != tc.MessageExpected {
931+
if seen := result.failureReason == Msg; seen != tc.MessageExpected {
935932
t.Fatalf("SSL message expected=%v, seen=%v", tc.MessageExpected, seen)
936933
}
937934
})

prober/prober.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (r *ProbeResult) failureInfoGauge() *prometheus.GaugeVec {
5858
} else if r.failureReason == "" {
5959
// Should not happen, but there theoretically might be an
6060
// inconsistent state of the struct.
61-
r.failureReason = "unknown"
61+
r.failureReason = "Unkown"
6262
}
6363

6464
labels := []string{"reason"}
@@ -85,15 +85,18 @@ func (r *ProbeResult) log(logger *slog.Logger, duration float64) {
8585
if r.failureReason == "" {
8686
// Should not happen, but there theoretically might be an
8787
// inconsistent state of the struct.
88-
r.failureReason = "unknown"
88+
r.failureReason = "Probe failed for unkown reason"
8989
}
9090
// converting the []string slice to an []any slice is a bit finicky
91-
logDetails := make([]any, 0, len(r.failureDetails)+2)
91+
logDetails := make([]any, 0, len(r.failureDetails)+4)
92+
logDetails = append(logDetails, "reason")
93+
logDetails = append(logDetails, r.failureReason)
9294
for _, d := range r.failureDetails {
9395
logDetails = append(logDetails, d)
9496
}
95-
logger.Error(r.failureReason, logDetails...)
96-
logger.Error("Probe failed", "duration_seconds", duration)
97+
logDetails = append(logDetails, "duration")
98+
logDetails = append(logDetails, duration)
99+
logger.Error("Probe failed", logDetails...)
97100
}
98101
}
99102

0 commit comments

Comments
 (0)