From 33364dc5152b3db2486d672fe2be39d21f115a60 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 11 Nov 2024 18:12:48 -0600 Subject: [PATCH] feat(healthchecks): Generate a run ID --- go.mod | 2 +- internal/notifier/healthchecks.go | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 8bc9cb5..f73ebbe 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/charmbracelet/lipgloss v0.13.0 github.com/dmarkham/enumer v1.5.10 github.com/dustin/go-humanize v1.0.1 + github.com/google/uuid v1.6.0 github.com/lmittmann/tint v1.0.5 github.com/muesli/termenv v0.15.3-0.20240912151726-82936c5ea257 github.com/schollz/progressbar/v3 v3.16.1 @@ -90,7 +91,6 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/s2a-go v0.1.8 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect github.com/googleapis/gax-go/v2 v2.13.0 // indirect github.com/gorilla/websocket v1.5.1 // indirect diff --git a/internal/notifier/healthchecks.go b/internal/notifier/healthchecks.go index 60039e4..c862922 100644 --- a/internal/notifier/healthchecks.go +++ b/internal/notifier/healthchecks.go @@ -11,6 +11,8 @@ import ( "strconv" "strings" "time" + + "github.com/google/uuid" ) var _ Logs = &Healthchecks{} @@ -25,26 +27,33 @@ func NewHealthchecks(url string) (Notifier, error) { type Healthchecks struct { PingBodyLimit int + RunID string url string log string } func (h *Healthchecks) SendStatus(ctx context.Context, status Status, log string) error { - var statusStr string + u, err := url.Parse(h.url) + if err != nil { + return err + } + switch status { case StatusStart: - statusStr = "start" + u.Path = path.Join(u.Path, "start") case StatusFailure: - statusStr = "fail" + u.Path = path.Join(u.Path, "fail") } - u, err := url.Parse(h.url) - if err != nil { - return err + if h.RunID == "" { + if u, err := uuid.NewRandom(); err == nil { + h.RunID = u.String() + } } - - u.Path = path.Join(u.Path, statusStr) + q := u.Query() + q.Set("rid", h.RunID) + u.RawQuery = q.Encode() client := &http.Client{Timeout: 10 * time.Second}