Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Jira error handling #140

Merged
merged 3 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/jiralert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/andygrunwald/go-jira"
"net/http"
"os"
"runtime"
"strconv"

"github.com/andygrunwald/go-jira"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus-community/jiralert/pkg/alertmanager"
Expand Down Expand Up @@ -127,7 +127,8 @@ func main() {
// Instruct Alertmanager to retry.
status = http.StatusServiceUnavailable
} else {
status = http.StatusInternalServerError
// Inaccurate, just letting Alertmanager know that it should not retry.
status = http.StatusBadRequest
}
errorHandler(w, status, err, conf.Name, &data, logger)
return
Expand Down
9 changes: 5 additions & 4 deletions pkg/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
"bytes"
"crypto/sha512"
"fmt"
"github.com/andygrunwald/go-jira"
"io"
"reflect"
"strings"
"time"

"github.com/andygrunwald/go-jira"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"
Expand Down Expand Up @@ -376,10 +376,11 @@ func handleJiraErrResponse(api string, resp *jira.Response, err error, logger lo
}

if resp != nil && resp.StatusCode/100 != 2 {
retry := resp.StatusCode == 500 || resp.StatusCode == 503
retry := resp.StatusCode == 500 || resp.StatusCode == 503 || resp.StatusCode == 429
// Sometimes go-jira consumes the body (e.g. in `Search`) and includes it in the error message;
// sometimes (e.g. in `Create`) it doesn't. Include both the error and the body, just in case.
body, _ := io.ReadAll(resp.Body)
// go-jira error message is not particularly helpful, replace it
return retry, errors.Errorf("JIRA request %s returned status %s, body %q", resp.Request.URL, resp.Status, string(body))
return retry, errors.Errorf("JIRA request %s returned status %s, error %q, body %q", resp.Request.URL, resp.Status, err, body)
}
return false, errors.Wrapf(err, "JIRA request %s failed", api)
}
Expand Down