Browse Source

prober: log HTTP response body on failure

Signed-off-by: Anton Tolchanov <[email protected]>
Anton Tolchanov 2 years ago
parent
commit
869b34ddeb
1 changed files with 6 additions and 1 deletions
  1. 6 1
      prober/http.go

+ 6 - 1
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