From 869b34ddeb4175df2b08cdc3d6cd9a350ec81059 Mon Sep 17 00:00:00 2001 From: Anton Tolchanov Date: Tue, 12 Dec 2023 19:14:25 +0000 Subject: [PATCH] prober: log HTTP response body on failure Signed-off-by: Anton Tolchanov --- prober/http.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prober/http.go b/prober/http.go index c3172a132..5c3355e46 100644 --- a/prober/http.go +++ b/prober/http.go @@ -53,7 +53,12 @@ func probeHTTP(ctx context.Context, url string, want []byte) error { } if !bytes.Contains(bs, want) { - return fmt.Errorf("body of %q does not contain %q", url, want) + // Log response body, but truncate it if it's too large; the limit + // has been chosen arbitrarily. + if maxlen := 300; len(bs) > maxlen { + bs = bs[:maxlen] + } + return fmt.Errorf("body of %q does not contain %q (got: %q)", url, want, string(bs)) } return nil