-
Notifications
You must be signed in to change notification settings - Fork 214
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
Improve Jira logging #5351
Improve Jira logging #5351
Changes from 7 commits
1618d8f
f7fa348
813d53e
7edf388
e9f389e
a8b00f1
9a7c8f0
275309a
ff1dce8
70411df
aa7947f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,13 +51,11 @@ public class JiraRestClient { | |
public static final List<Integer> RETRY_ATTEMPT_SLEEP_TIME = List.of(1, 2, 5, 10, 20, 40); | ||
private static final String TICKET_FETCH_LATENCY_TIMER = "ticketFetchLatency"; | ||
private static final String SEARCH_CALL_LATENCY_TIMER = "searchCallLatency"; | ||
private static final String PROJECTS_FETCH_LATENCY_TIMER = "projectFetchLatency"; | ||
private static final String ISSUES_REQUESTED = "issuesRequested"; | ||
private final RestTemplate restTemplate; | ||
private final JiraAuthConfig authConfig; | ||
private final Timer ticketFetchLatencyTimer; | ||
private final Timer searchCallLatencyTimer; | ||
private final Timer projectFetchLatencyTimer; | ||
private final Counter issuesRequestedCounter; | ||
private final PluginMetrics jiraPluginMetrics = PluginMetrics.fromNames("jiraRestClient", "aws"); | ||
private int sleepTimeMultiplier = 1000; | ||
|
@@ -68,8 +66,6 @@ public JiraRestClient(RestTemplate restTemplate, JiraAuthConfig authConfig) { | |
|
||
ticketFetchLatencyTimer = jiraPluginMetrics.timer(TICKET_FETCH_LATENCY_TIMER); | ||
searchCallLatencyTimer = jiraPluginMetrics.timer(SEARCH_CALL_LATENCY_TIMER); | ||
projectFetchLatencyTimer = jiraPluginMetrics.timer(PROJECTS_FETCH_LATENCY_TIMER); | ||
|
||
issuesRequestedCounter = jiraPluginMetrics.counter(ISSUES_REQUESTED); | ||
} | ||
|
||
|
@@ -119,20 +115,28 @@ private <T> ResponseEntity<T> invokeRestApi(URI uri, Class<T> responseType) thro | |
} catch (HttpClientErrorException ex) { | ||
HttpStatus statusCode = ex.getStatusCode(); | ||
String statusMessage = ex.getMessage(); | ||
log.error("An exception has occurred while getting response from Jira search API {}", ex.getMessage()); | ||
log.error("An exception has occurred while getting response from Jira search API with statusCode {} and error message: {}", statusCode, statusMessage); | ||
if (statusCode == HttpStatus.FORBIDDEN) { | ||
throw new UnAuthorizedException(statusMessage); | ||
} else if (statusCode == HttpStatus.UNAUTHORIZED) { | ||
log.error(NOISY, "Token expired. We will try to renew the tokens now", ex); | ||
log.error("Token expired. We will try to renew the tokens now."); | ||
authConfig.renewCredentials(); | ||
} else if (statusCode == HttpStatus.TOO_MANY_REQUESTS) { | ||
log.error(NOISY, "Hitting API rate limit. Backing off with sleep timer.", ex); | ||
log.error("Hitting API rate limit. Backing off with sleep timer."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be noisy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its not needed because it's only one line and retries are capped at 6 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, will make noisy |
||
} else if (statusCode == HttpStatus.SERVICE_UNAVAILABLE) { | ||
log.error("Service unavailable. Will retry after backing off with sleep timer."); | ||
} else if (statusCode == HttpStatus.GATEWAY_TIMEOUT) { | ||
log.error("Gateway timeout. Will retry after backing off with sleep timer."); | ||
} else { | ||
log.error(NOISY, "Received an unexpected status code {} response from Jira.", statusCode, ex); | ||
} | ||
try { | ||
Thread.sleep((long) RETRY_ATTEMPT_SLEEP_TIME.get(retryCount) * sleepTimeMultiplier); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException("Sleep in the retry attempt got interrupted", e); | ||
throw new RuntimeException("Sleep in the retry attempt got interrupted."); | ||
} | ||
} catch (Exception ex) { | ||
log.error(NOISY, "An exception has occurred while getting a response from the Jira search API", ex); | ||
} | ||
retryCount++; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if another type of exception is thrown here? This will throw it back. Do we have other error handling for that?
Also, we appear to not have error handling for 5xx errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added error logging for unknown exception, added error handling for some 5xx errors