Skip to content

Commit

Permalink
add reason code to notifiers (#3307)
Browse files Browse the repository at this point in the history
* add reason code to notifiers

Signed-off-by: Yijie Qin <qinyijie@amazon.com>
  • Loading branch information
qinxx108 authored Apr 7, 2023
1 parent bb1c123 commit 9a8d1f9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion notify/opsgenie/opsgenie.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
shouldRetry, err := n.retrier.Check(resp.StatusCode, resp.Body)
notify.Drain(resp)
if err != nil {
return shouldRetry, err
return shouldRetry, notify.NewErrorWithReason(notify.GetFailureReasonFromStatusCode(resp.StatusCode), err)
}
}
return true, nil
Expand Down
6 changes: 5 additions & 1 deletion notify/pagerduty/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ func (n *Notifier) notifyV2(
}
defer notify.Drain(resp)

return n.retrier.Check(resp.StatusCode, resp.Body)
retry, err := n.retrier.Check(resp.StatusCode, resp.Body)
if err != nil {
return retry, notify.NewErrorWithReason(notify.GetFailureReasonFromStatusCode(resp.StatusCode), err)
}
return retry, err
}

// Notify implements the Notifier interface.
Expand Down
6 changes: 5 additions & 1 deletion notify/pushover/pushover.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,9 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
}
defer notify.Drain(resp)

return n.retrier.Check(resp.StatusCode, resp.Body)
shouldRetry, err := n.retrier.Check(resp.StatusCode, resp.Body)
if err != nil {
return shouldRetry, notify.NewErrorWithReason(notify.GetFailureReasonFromStatusCode(resp.StatusCode), err)
}
return shouldRetry, err
}
6 changes: 5 additions & 1 deletion notify/victorops/victorops.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
}
defer notify.Drain(resp)

return n.retrier.Check(resp.StatusCode, resp.Body)
shouldRetry, err := n.retrier.Check(resp.StatusCode, resp.Body)
if err != nil {
return shouldRetry, notify.NewErrorWithReason(notify.GetFailureReasonFromStatusCode(resp.StatusCode), err)
}
return shouldRetry, err
}

// Create the JSON payload to be sent to the VictorOps API.
Expand Down
6 changes: 5 additions & 1 deletion notify/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ func (n *Notifier) Notify(ctx context.Context, alerts ...*types.Alert) (bool, er
}
defer notify.Drain(resp)

return n.retrier.Check(resp.StatusCode, resp.Body)
shouldRetry, err := n.retrier.Check(resp.StatusCode, resp.Body)
if err != nil {
return shouldRetry, notify.NewErrorWithReason(notify.GetFailureReasonFromStatusCode(resp.StatusCode), err)
}
return shouldRetry, err
}

func errDetails(body io.Reader, url string) string {
Expand Down
2 changes: 1 addition & 1 deletion notify/wechat/wechat.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
defer notify.Drain(resp)

if resp.StatusCode != 200 {
return true, fmt.Errorf("unexpected status code %v", resp.StatusCode)
return true, notify.NewErrorWithReason(notify.GetFailureReasonFromStatusCode(resp.StatusCode), fmt.Errorf("unexpected status code %v", resp.StatusCode))
}

body, err := io.ReadAll(resp.Body)
Expand Down

0 comments on commit 9a8d1f9

Please sign in to comment.