Skip to content

Commit

Permalink
feat(healthchecks): Respect Healthchecks ping body limit
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Nov 11, 2024
1 parent ff91f0f commit bd7a127
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/notifier/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"path"
"strconv"
"strings"
"time"
)
Expand All @@ -23,6 +24,8 @@ func NewHealthchecks(url string) (Notifier, error) {
}

type Healthchecks struct {
PingBodyLimit int

url string
log string
}
Expand Down Expand Up @@ -50,6 +53,10 @@ func (h *Healthchecks) SendStatus(ctx context.Context, status Status, log string
method = http.MethodPost
}

if h.PingBodyLimit != 0 && len(log) > h.PingBodyLimit {
log = log[len(log)-h.PingBodyLimit:]
}

req, err := http.NewRequestWithContext(ctx, method, u.String(), strings.NewReader(log))
if err != nil {
return err
Expand All @@ -62,6 +69,13 @@ func (h *Healthchecks) SendStatus(ctx context.Context, status Status, log string
_ = resp.Body.Close()

if err == nil && resp.StatusCode < 300 {
if h.PingBodyLimit == 0 {
if limitStr := resp.Header.Get("Ping-Body-Limit"); limitStr != "" {
if limit, err := strconv.Atoi(limitStr); err == nil {
h.PingBodyLimit = limit
}
}
}
return nil
}

Expand Down

0 comments on commit bd7a127

Please sign in to comment.