mirror of
https://github.com/prometheus/alertmanager
synced 2025-03-31 23:59:03 +00:00
notify: log PagerDuty v1 response on BadRequest (#1481)
Signed-off-by: Adam Shannon <adamkshannon@gmail.com>
This commit is contained in:
parent
4fff29c683
commit
77452894b8
notify
@ -503,7 +503,7 @@ func (n *PagerDuty) notifyV1(
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return n.retryV1(resp.StatusCode)
|
||||
return n.retryV1(resp)
|
||||
}
|
||||
|
||||
func (n *PagerDuty) notifyV2(
|
||||
@ -609,14 +609,23 @@ func (n *PagerDuty) Notify(ctx context.Context, as ...*types.Alert) (bool, error
|
||||
return n.notifyV2(ctx, c, eventType, key, data, details, as...)
|
||||
}
|
||||
|
||||
func (n *PagerDuty) retryV1(statusCode int) (bool, error) {
|
||||
func (n *PagerDuty) retryV1(resp *http.Response) (bool, error) {
|
||||
// Retrying can solve the issue on 403 (rate limiting) and 5xx response codes.
|
||||
// 2xx response codes indicate a successful request.
|
||||
// https://v2.developer.pagerduty.com/docs/trigger-events
|
||||
statusCode := resp.StatusCode
|
||||
|
||||
if statusCode == 400 && resp.Body != nil {
|
||||
bs, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("unexpected status code %v : problem reading response: %v", statusCode, err)
|
||||
}
|
||||
return false, fmt.Errorf("bad request (status code %v): %v", statusCode, string(bs))
|
||||
}
|
||||
|
||||
if statusCode/100 != 2 {
|
||||
return (statusCode == 403 || statusCode/100 == 5), fmt.Errorf("unexpected status code %v", statusCode)
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,10 @@ func TestPagerDutyRetryV1(t *testing.T) {
|
||||
|
||||
retryCodes := append(defaultRetryCodes(), http.StatusForbidden)
|
||||
for statusCode, expected := range retryTests(retryCodes) {
|
||||
actual, _ := notifier.retryV1(statusCode)
|
||||
resp := &http.Response{
|
||||
StatusCode: statusCode,
|
||||
}
|
||||
actual, _ := notifier.retryV1(resp)
|
||||
require.Equal(t, expected, actual, fmt.Sprintf("retryv1 - error on status %d", statusCode))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user