Skip to content

Commit

Permalink
feat(healthchecks): Generate a run ID
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Nov 12, 2024
1 parent bd7a127 commit 33364dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions internal/notifier/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strconv"
"strings"
"time"

"github.com/google/uuid"
)

var _ Logs = &Healthchecks{}
Expand All @@ -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}

Expand Down

0 comments on commit 33364dc

Please sign in to comment.