From 81bea394f1f27a9b1eaeeb79d8cc46bad56026a0 Mon Sep 17 00:00:00 2001 From: Anton Bronnikov Date: Wed, 24 Jan 2024 10:28:02 +0200 Subject: [PATCH] [fix] improve error logging --- healthchecker/healthchecker.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/healthchecker/healthchecker.go b/healthchecker/healthchecker.go index 6aa61b1..8699052 100644 --- a/healthchecker/healthchecker.go +++ b/healthchecker/healthchecker.go @@ -12,6 +12,7 @@ import ( "time" "github.com/flashbots/node-healthchecker/httplogger" + "github.com/flashbots/node-healthchecker/logutils" "go.uber.org/zap" ) @@ -129,23 +130,33 @@ func (h *Healthchecker) handleHTTPRequest(w http.ResponseWriter, r *http.Request }() } - errors := []error{} + errs := []error{} for count > 0 { count-- if res := <-results; res != nil { - errors = append(errors, res) + errs = append(errs, res) } } close(results) - if len(errors) == 0 { + if len(errs) == 0 { return } + l := logutils.LoggerFromRequest(r) + w.Header().Set("Content-Type", "application/text") w.WriteHeader(http.StatusInternalServerError) - for idx, err := range errors { + for idx, err := range errs { line := fmt.Sprintf("%d: %s\n", idx, err) - w.Write([]byte(line)) + _, err := w.Write([]byte(line)) + if err != nil { + l.Error("Failed to write the response body", zap.Error(err)) + } } + + l.Warn( + "Failed the healthcheck due to upstream error(s)", + zap.Error(errors.Join(errs...)), + ) }