From 9abc268315a30b0b2a368b13bf55fcd946a8e89f Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Fri, 2 Feb 2024 21:28:16 +0100 Subject: [PATCH] feat: Add more logging to the metrics code --- internal/pages/metrics.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/pages/metrics.go b/internal/pages/metrics.go index 1b882e6..bcf52ee 100644 --- a/internal/pages/metrics.go +++ b/internal/pages/metrics.go @@ -2,6 +2,7 @@ package pages import ( "encoding/json" + "io/ioutil" "net/http" "strconv" "strings" @@ -45,12 +46,29 @@ func (c *LokiMetricConfig) sendMetricPing(domain, path string) { return } + log.Debugf("Sending payload %s", string(jsonData)) + // Send the ping to the Loki server go func() { - http.Post( + res, err := http.Post( c.Url, "application/json", strings.NewReader(string(jsonData)), ) + if err != nil { + log.Errorf("Failed to send payload to Loki: %v", err) + return + } + + defer res.Body.Close() + if res.StatusCode != 204 { + log.Errorf("Loki returned non-204 status code %d", res.StatusCode) + body, err := ioutil.ReadAll(res.Body) + if err != nil { + log.Warnf("Failed to read body. No more specific error message") + return + } + log.Errorf("-> %s", body) + } }() }