xiaohui-sun commented on a change in pull request #4748: [TE][notification]
Ability to reopen and reuse existing Jira tickets for alerts
URL: https://github.com/apache/incubator-pinot/pull/4748#discussion_r340301261
##########
File path:
thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/alert/scheme/DetectionJiraAlerter.java
##########
@@ -76,43 +78,81 @@ public DetectionJiraAlerter(ADContentFormatterContext
adContext, ThirdEyeAnomaly
super(adContext, result);
this.teConfig = thirdeyeConfig;
- init();
+ this.jiraAdminConfig =
JiraConfiguration.createFromProperties(this.teConfig.getAlerterConfiguration().get(JIRA_CONFIG_KEY));
+ this.jiraClient = new ThirdEyeJiraClient(this.jiraAdminConfig);
}
- private void init() {
- this.jiraAdminConfig =
JiraConfiguration.createFromProperties(this.teConfig.getAlerterConfiguration().get(JIRA_CONFIG_KEY));
- this.jiraRestClient = new
AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(
- URI.create(jiraAdminConfig.getJiraHost()),
- jiraAdminConfig.getJiraUser(),
- jiraAdminConfig.getJiraPassword());
+ private void updateJiraAlert(Issue issue, JiraEntity jiraEntity) {
+ // Append labels
+ jiraEntity.getLabels().addAll(issue.getLabels());
+
jiraEntity.setLabels(jiraEntity.getLabels().stream().distinct().collect(Collectors.toList()));
+
+ jiraClient.reopenIssue(issue);
+ jiraClient.updateIssue(issue, jiraEntity);
+
+ try {
+ jiraClient.addComment(issue, jiraEntity.getDescription());
+ } catch (Exception e) {
+ // Jira has a upper limit on the number of characters. In such cases we
will only share a link in the comment.
+ StringBuilder sb = new StringBuilder();
+ sb.append("*<Truncating details due to jira limit! Please use the below
link to view all the anomalies.>*");
+ sb.append(System.getProperty("line.separator"));
+
+ String desc = jiraEntity.getDescription().replaceAll("listed below", "");
+
+ // Print only the first line with the redirection link to ThirdEye
+ sb.append(desc, 0, desc.indexOf("\n"));
+ jiraClient.addComment(issue, sb.toString());
+ }
}
- private String createIssue(IssueInput issueInput) {
- return
jiraRestClient.getIssueClient().createIssue(issueInput).claim().getKey();
+ private JiraEntity buildJiraEntity(DetectionAlertFilterNotification
notification, Set<MergedAnomalyResultDTO> anomalies) {
+ Map<String, Object> notificationSchemeProps =
notification.getNotificationSchemeProps();
+ if (notificationSchemeProps == null ||
notificationSchemeProps.get(PROP_JIRA_SCHEME) == null) {
+ throw new IllegalArgumentException("Invalid jira settings in
subscription group " + this.adContext.getNotificationConfig().getId());
Review comment:
Let's put the error message more specific.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]