Skip to content

Commit 1317a61

Browse files
akawalskyrodireich
authored andcommitted
Include jobId in webhook messages (#15704)
1 parent 571af0b commit 1317a61

File tree

8 files changed

+27
-18
lines changed

8 files changed

+27
-18
lines changed

airbyte-notification/src/main/java/io/airbyte/notification/CustomerioNotificationClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ public CustomerioNotificationClient(final Notification notification,
6363
}
6464

6565
@Override
66-
public boolean notifyJobFailure(final String sourceConnector, final String destinationConnector, final String jobDescription, final String logUrl)
66+
public boolean notifyJobFailure(final String sourceConnector, final String destinationConnector, final String jobDescription, final String logUrl, final Long jobId)
6767
throws IOException, InterruptedException {
6868
throw new NotImplementedException();
6969
}
7070

7171
@Override
72-
public boolean notifyJobSuccess(final String sourceConnector, final String destinationConnector, final String jobDescription, final String logUrl)
72+
public boolean notifyJobSuccess(final String sourceConnector, final String destinationConnector, final String jobDescription, final String logUrl, final Long jobId)
7373
throws IOException, InterruptedException {
7474
throw new NotImplementedException();
7575
}

airbyte-notification/src/main/java/io/airbyte/notification/NotificationClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ public abstract boolean notifyJobFailure(
2323
String sourceConnector,
2424
String destinationConnector,
2525
String jobDescription,
26-
String logUrl)
26+
String logUrl,
27+
Long jobId)
2728
throws IOException, InterruptedException;
2829

2930
public abstract boolean notifyJobSuccess(
3031
String sourceConnector,
3132
String destinationConnector,
3233
String jobDescription,
33-
String logUrl)
34+
String logUrl,
35+
Long jobId)
3436
throws IOException, InterruptedException;
3537

3638
public abstract boolean notifyConnectionDisabled(String receiverEmail,

airbyte-notification/src/main/java/io/airbyte/notification/SlackNotificationClient.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,27 @@ public SlackNotificationClient(final Notification notification) {
4444
}
4545

4646
@Override
47-
public boolean notifyJobFailure(final String sourceConnector, final String destinationConnector, final String jobDescription, final String logUrl)
47+
public boolean notifyJobFailure(final String sourceConnector, final String destinationConnector, final String jobDescription, final String logUrl, final Long jobId)
4848
throws IOException, InterruptedException {
4949
return notifyFailure(renderTemplate(
5050
"slack/failure_slack_notification_template.txt",
5151
sourceConnector,
5252
destinationConnector,
5353
jobDescription,
54-
logUrl));
54+
logUrl,
55+
String.valueOf(jobId)));
5556
}
5657

5758
@Override
58-
public boolean notifyJobSuccess(final String sourceConnector, final String destinationConnector, final String jobDescription, final String logUrl)
59+
public boolean notifyJobSuccess(final String sourceConnector, final String destinationConnector, final String jobDescription, final String logUrl, final Long jobId)
5960
throws IOException, InterruptedException {
6061
return notifySuccess(renderTemplate(
6162
"slack/success_slack_notification_template.txt",
6263
sourceConnector,
6364
destinationConnector,
6465
jobDescription,
65-
logUrl));
66+
logUrl,
67+
String.valueOf(jobId)));
6668
}
6769

6870
@Override

airbyte-notification/src/main/resources/slack/failure_slack_notification_template.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ Your connection from %s to %s just failed...
22
This happened with %s
33

44
You can access its logs here: %s
5+
6+
Job ID: %s

airbyte-notification/src/main/resources/slack/success_slack_notification_template.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ Your connection from %s to %s succeeded
22
This was for %s
33

44
You can access its logs here: %s
5+
6+
Job ID: %s

airbyte-notification/src/test/java/io/airbyte/notification/SlackNotificationClientTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SlackNotificationClientTest {
4040
private static final String JOB_DESCRIPTION = "job description";
4141
private static final String LOG_URL = "logUrl";
4242
private static final String SOURCE_TEST = "source-test";
43+
private static final Long JOB_ID = 1L;
4344

4445
public static final String WEBHOOK_URL = "http://localhost:";
4546
private static final String EXPECTED_FAIL_MESSAGE = "Your connection from source-test to destination-test just failed...\n"
@@ -81,15 +82,15 @@ void testBadWebhookUrl() {
8182
new SlackNotificationClient(new Notification()
8283
.withNotificationType(NotificationType.SLACK)
8384
.withSlackConfiguration(new SlackNotificationConfiguration().withWebhook(WEBHOOK_URL + server.getAddress().getPort() + "/bad")));
84-
assertThrows(IOException.class, () -> client.notifyJobFailure(SOURCE_TEST, DESTINATION_TEST, JOB_DESCRIPTION, LOG_URL));
85+
assertThrows(IOException.class, () -> client.notifyJobFailure(SOURCE_TEST, DESTINATION_TEST, JOB_DESCRIPTION, LOG_URL, JOB_ID));
8586
}
8687

8788
@Test
8889
void testEmptyWebhookUrl() throws IOException, InterruptedException {
8990
final SlackNotificationClient client =
9091
new SlackNotificationClient(
9192
new Notification().withNotificationType(NotificationType.SLACK).withSlackConfiguration(new SlackNotificationConfiguration()));
92-
assertFalse(client.notifyJobFailure(SOURCE_TEST, DESTINATION_TEST, JOB_DESCRIPTION, LOG_URL));
93+
assertFalse(client.notifyJobFailure(SOURCE_TEST, DESTINATION_TEST, JOB_DESCRIPTION, LOG_URL, JOB_ID));
9394
}
9495

9596
@Test
@@ -111,7 +112,7 @@ void testNotifyJobFailure() throws IOException, InterruptedException {
111112
new SlackNotificationClient(new Notification()
112113
.withNotificationType(NotificationType.SLACK)
113114
.withSlackConfiguration(new SlackNotificationConfiguration().withWebhook(WEBHOOK_URL + server.getAddress().getPort() + TEST_PATH)));
114-
assertTrue(client.notifyJobFailure(SOURCE_TEST, DESTINATION_TEST, JOB_DESCRIPTION, LOG_URL));
115+
assertTrue(client.notifyJobFailure(SOURCE_TEST, DESTINATION_TEST, JOB_DESCRIPTION, LOG_URL, JOB_ID));
115116
}
116117

117118
@Test
@@ -122,7 +123,7 @@ void testNotifyJobSuccess() throws IOException, InterruptedException {
122123
.withNotificationType(NotificationType.SLACK)
123124
.withSendOnSuccess(true)
124125
.withSlackConfiguration(new SlackNotificationConfiguration().withWebhook(WEBHOOK_URL + server.getAddress().getPort() + TEST_PATH)));
125-
assertTrue(client.notifyJobSuccess(SOURCE_TEST, DESTINATION_TEST, JOB_DESCRIPTION, LOG_URL));
126+
assertTrue(client.notifyJobSuccess(SOURCE_TEST, DESTINATION_TEST, JOB_DESCRIPTION, LOG_URL, JOB_ID));
126127
}
127128

128129
@Test

airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/JobNotifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ private void notifyJob(final String reason,
103103
MoreMaps.merge(jobMetadata, sourceMetadata, destinationMetadata, notificationMetadata.build()));
104104

105105
if (FAILURE_NOTIFICATION == action) {
106-
if (!notificationClient.notifyJobFailure(sourceConnector, destinationConnector, jobDescription, logUrl)) {
106+
if (!notificationClient.notifyJobFailure(sourceConnector, destinationConnector, jobDescription, logUrl, job.getId())) {
107107
LOGGER.warn("Failed to successfully notify failure: {}", notification);
108108
}
109109
break;
110110
} else if (SUCCESS_NOTIFICATION == action) {
111-
if (!notificationClient.notifyJobSuccess(sourceConnector, destinationConnector, jobDescription, logUrl)) {
111+
if (!notificationClient.notifyJobSuccess(sourceConnector, destinationConnector, jobDescription, logUrl, job.getId())) {
112112
LOGGER.warn("Failed to successfully notify success: {}", notification);
113113
}
114114
break;

airbyte-scheduler/scheduler-persistence/src/test/java/io/airbyte/scheduler/persistence/JobNotifierTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
package io.airbyte.scheduler.persistence;
66

7-
import static org.mockito.ArgumentMatchers.any;
8-
import static org.mockito.ArgumentMatchers.anyString;
7+
import static org.mockito.ArgumentMatchers.*;
98
import static org.mockito.Mockito.mock;
109
import static org.mockito.Mockito.spy;
1110
import static org.mockito.Mockito.verify;
@@ -85,7 +84,7 @@ void testFailJob() throws IOException, InterruptedException, JsonValidationExcep
8584
when(configRepository.getStandardDestinationDefinition(any())).thenReturn(destinationDefinition);
8685
when(configRepository.getStandardWorkspace(WORKSPACE_ID, true)).thenReturn(getWorkspace());
8786
when(workspaceHelper.getWorkspaceForJobIdIgnoreExceptions(job.getId())).thenReturn(WORKSPACE_ID);
88-
when(notificationClient.notifyJobFailure(anyString(), anyString(), anyString(), anyString())).thenReturn(true);
87+
when(notificationClient.notifyJobFailure(anyString(), anyString(), anyString(), anyString(), anyLong())).thenReturn(true);
8988

9089
jobNotifier.failJob("JobNotifierTest was running", job);
9190
final DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withZone(ZoneId.systemDefault());
@@ -94,7 +93,8 @@ void testFailJob() throws IOException, InterruptedException, JsonValidationExcep
9493
"destination-test",
9594
String.format("sync started on %s, running for 1 day 10 hours 17 minutes 36 seconds, as the JobNotifierTest was running.",
9695
formatter.format(Instant.ofEpochSecond(job.getStartedAtInSecond().get()))),
97-
String.format("http://localhost:8000/workspaces/%s/connections/%s", WORKSPACE_ID, job.getScope()));
96+
String.format("http://localhost:8000/workspaces/%s/connections/%s", WORKSPACE_ID, job.getScope()),
97+
job.getId());
9898

9999
final Builder<String, Object> metadata = ImmutableMap.builder();
100100
metadata.put("connection_id", UUID.fromString(job.getScope()));

0 commit comments

Comments
 (0)