feat: Add more logging to the metrics code
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
PapaTutuWawa 2024-02-02 21:28:16 +01:00
parent 8f09aa959b
commit 9abc268315

View File

@ -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)
}
}()
}