Skip to content

Commit 414a7c9

Browse files
Improve Jira logging (opensearch-project#5351)
Improve Jira logging Signed-off-by: Maxwell Brown <mxwelwbr@amazon.com>
1 parent 49c6a2b commit 414a7c9

7 files changed

Lines changed: 21 additions & 14 deletions

File tree

data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private StringBuilder createIssueFilterCriteria(JiraSourceConfig configuration,
166166
.collect(Collectors.joining(DELIMITER, PREFIX, SUFFIX)))
167167
.append(CLOSING_ROUND_BRACKET);
168168
}
169-
log.error("Created issue filter criteria JiraQl query: {}", jiraQl);
169+
log.info("Created issue filter criteria JiraQl query: {}", jiraQl);
170170
return jiraQl;
171171
}
172172

data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.fasterxml.jackson.annotation.JsonProperty;
1414
import jakarta.validation.Valid;
15+
import jakarta.validation.constraints.AssertTrue;
1516
import lombok.Getter;
1617
import org.opensearch.dataprepper.plugins.source.jira.configuration.AuthenticationConfig;
1718
import org.opensearch.dataprepper.plugins.source.jira.configuration.FilterConfig;
@@ -30,6 +31,11 @@ public class JiraSourceConfig implements CrawlerSourceConfig {
3031
@JsonProperty("hosts")
3132
private List<String> hosts;
3233

34+
@AssertTrue(message = "Jira hosts must be a list of length 1")
35+
boolean isValidHosts() {
36+
return hosts != null && hosts.size() == 1;
37+
}
38+
3339
/**
3440
* Authentication Config to Access Jira
3541
*/

data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/JiraRestClient.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ public class JiraRestClient {
5151
public static final List<Integer> RETRY_ATTEMPT_SLEEP_TIME = List.of(1, 2, 5, 10, 20, 40);
5252
private static final String TICKET_FETCH_LATENCY_TIMER = "ticketFetchLatency";
5353
private static final String SEARCH_CALL_LATENCY_TIMER = "searchCallLatency";
54-
private static final String PROJECTS_FETCH_LATENCY_TIMER = "projectFetchLatency";
5554
private static final String ISSUES_REQUESTED = "issuesRequested";
5655
private final RestTemplate restTemplate;
5756
private final JiraAuthConfig authConfig;
5857
private final Timer ticketFetchLatencyTimer;
5958
private final Timer searchCallLatencyTimer;
60-
private final Timer projectFetchLatencyTimer;
6159
private final Counter issuesRequestedCounter;
6260
private final PluginMetrics jiraPluginMetrics = PluginMetrics.fromNames("jiraRestClient", "aws");
6361
private int sleepTimeMultiplier = 1000;
@@ -68,8 +66,6 @@ public JiraRestClient(RestTemplate restTemplate, JiraAuthConfig authConfig) {
6866

6967
ticketFetchLatencyTimer = jiraPluginMetrics.timer(TICKET_FETCH_LATENCY_TIMER);
7068
searchCallLatencyTimer = jiraPluginMetrics.timer(SEARCH_CALL_LATENCY_TIMER);
71-
projectFetchLatencyTimer = jiraPluginMetrics.timer(PROJECTS_FETCH_LATENCY_TIMER);
72-
7369
issuesRequestedCounter = jiraPluginMetrics.counter(ISSUES_REQUESTED);
7470
}
7571

@@ -119,20 +115,24 @@ private <T> ResponseEntity<T> invokeRestApi(URI uri, Class<T> responseType) thro
119115
} catch (HttpClientErrorException ex) {
120116
HttpStatus statusCode = ex.getStatusCode();
121117
String statusMessage = ex.getMessage();
122-
log.error("An exception has occurred while getting response from Jira search API {}", ex.getMessage());
118+
log.error(NOISY, "An exception has occurred while getting response from Jira search API with statusCode {} and error message: {}", statusCode, statusMessage);
123119
if (statusCode == HttpStatus.FORBIDDEN) {
124120
throw new UnAuthorizedException(statusMessage);
125121
} else if (statusCode == HttpStatus.UNAUTHORIZED) {
126-
log.error(NOISY, "Token expired. We will try to renew the tokens now", ex);
122+
log.warn(NOISY, "Token expired. We will try to renew the tokens now.");
127123
authConfig.renewCredentials();
128-
} else if (statusCode == HttpStatus.TOO_MANY_REQUESTS) {
129-
log.error(NOISY, "Hitting API rate limit. Backing off with sleep timer.", ex);
124+
} else if (statusCode == HttpStatus.TOO_MANY_REQUESTS || statusCode == HttpStatus.SERVICE_UNAVAILABLE || statusCode == HttpStatus.GATEWAY_TIMEOUT) {
125+
log.error(NOISY, "Received {}. Backing off with sleep timer for {} seconds.", statusCode, RETRY_ATTEMPT_SLEEP_TIME.get(retryCount));
126+
} else {
127+
log.error(NOISY, "Received an unexpected status code {} response from Jira.", statusCode, ex);
130128
}
131129
try {
132130
Thread.sleep((long) RETRY_ATTEMPT_SLEEP_TIME.get(retryCount) * sleepTimeMultiplier);
133131
} catch (InterruptedException e) {
134-
throw new RuntimeException("Sleep in the retry attempt got interrupted", e);
132+
throw new RuntimeException("Sleep in the retry attempt got interrupted.");
135133
}
134+
} catch (Exception ex) {
135+
log.error(NOISY, "An exception has occurred while getting a response from the Jira search API", ex);
136136
}
137137
retryCount++;
138138
}

data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraOauthConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public String getJiraAccountCloudId() {
100100
if (e.getRawStatusCode() == HttpStatus.UNAUTHORIZED.value()) {
101101
renewCredentials();
102102
}
103-
log.error("Error occurred while accessing resources: ", e);
103+
log.error("Error occurred while accessing resources. Status code: {}. Error message: {}", e.getStatusCode(), e.getMessage());
104104
}
105105
}
106106
throw new UnAuthorizedException(String.format("Access token expired. Unable to renew even after %s attempts", RETRY_ATTEMPT));
@@ -153,6 +153,7 @@ public void renewCredentials() {
153153
this.accessToken = (String) oauth2Config.getAccessToken().getValue();
154154
this.refreshToken = (String) oauth2Config.getRefreshToken().getValue();
155155
this.expireTime = Instant.now().plusSeconds(10);
156+
log.info("Access Token and Refresh Token pair is now refreshed.");
156157
}
157158
throw new RuntimeException("Failed to renew access token message:" + ex.getMessage(), ex);
158159
}

data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/AddressValidation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static InetAddress getInetAddress(String url) {
3838
try {
3939
return InetAddress.getByName(new URL(url).getHost());
4040
} catch (UnknownHostException | MalformedURLException e) {
41-
log.error(INVALID_URL, e);
41+
log.error("{}: {}", INVALID_URL, url);
4242
throw new BadRequestException(e.getMessage(), e);
4343
}
4444
}

data-prepper-plugins/saas-source-plugins/source-crawler/src/main/java/org/opensearch/dataprepper/plugins/source/source_crawler/coordination/partition/LeaderPartition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public LeaderProgressState convertToPartitionState(final String serializedPartit
7575
try {
7676
return objectMapper.readValue(serializedPartitionProgressState, LeaderProgressState.class);
7777
} catch (final JsonProcessingException e) {
78-
LOG.error("Unable to convert string to partition progress state class ", e);
78+
LOG.error("Unable to convert string to partition progress state class due to {}. Partition progress state string: {}.", e.getMessage(), serializedPartitionProgressState);
7979
return null;
8080
}
8181
}

data-prepper-plugins/saas-source-plugins/source-crawler/src/main/java/org/opensearch/dataprepper/plugins/source/source_crawler/coordination/scheduler/WorkerScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void run() {
8989
try {
9090
Thread.sleep(RETRY_BACKOFF_ON_EXCEPTION_MILLIS);
9191
} catch (InterruptedException ex) {
92-
log.warn("Thread interrupted while waiting to retry", ex);
92+
log.warn("Thread interrupted while waiting to retry due to {}", ex.getMessage());
9393
}
9494
}
9595
}

0 commit comments

Comments
 (0)