Skip to content

Commit cb9724d

Browse files
authored
notify/webhook: Fix crash on errors when url_file is used (prometheus#3798) (prometheus#3800)
1 parent 036eb50 commit cb9724d

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

notify/webhook/webhook.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"context"
1919
"encoding/json"
2020
"fmt"
21-
"io"
2221
"net/http"
2322
"os"
2423
"strings"
@@ -55,11 +54,7 @@ func New(conf *config.WebhookConfig, t *template.Template, l log.Logger, httpOpt
5554
client: client,
5655
// Webhooks are assumed to respond with 2xx response codes on a successful
5756
// request and 5xx response codes are assumed to be recoverable.
58-
retrier: &notify.Retrier{
59-
CustomDetailsFunc: func(_ int, body io.Reader) string {
60-
return errDetails(body, conf.URL.String())
61-
},
62-
},
57+
retrier: &notify.Retrier{},
6358
}, nil
6459
}
6560

@@ -126,14 +121,3 @@ func (n *Notifier) Notify(ctx context.Context, alerts ...*types.Alert) (bool, er
126121
}
127122
return shouldRetry, err
128123
}
129-
130-
func errDetails(body io.Reader, url string) string {
131-
if body == nil {
132-
return url
133-
}
134-
bs, err := io.ReadAll(body)
135-
if err != nil {
136-
return url
137-
}
138-
return fmt.Sprintf("%s: %s", url, string(bs))
139-
}

notify/webhook/webhook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ func TestWebhookRetry(t *testing.T) {
6868
`{"status":"invalid event"}`,
6969
)),
7070

71-
exp: fmt.Sprintf(`unexpected status code %d: %s: {"status":"invalid event"}`, http.StatusBadRequest, u.String()),
71+
exp: fmt.Sprintf(`unexpected status code %d: {"status":"invalid event"}`, http.StatusBadRequest),
7272
},
7373
{
7474
status: http.StatusBadRequest,
7575

76-
exp: fmt.Sprintf(`unexpected status code %d: %s`, http.StatusBadRequest, u.String()),
76+
exp: fmt.Sprintf(`unexpected status code %d`, http.StatusBadRequest),
7777
},
7878
} {
7979
t.Run("", func(t *testing.T) {

0 commit comments

Comments
 (0)