Skip to content

Commit

Permalink
feat: added syslog support in notification channel (#180)
Browse files Browse the repository at this point in the history
* feat: added syslog support in notification channel

* Fixed the flaky test
  • Loading branch information
singhalprerana authored Oct 16, 2023
1 parent 73e3e05 commit b8dfb1c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -232,14 +233,7 @@ void deleteConfigs() throws IOException {
verify(configStore, times(1))
.deleteConfigs(
eq(Set.of(getConfigResourceContext(context1), getConfigResourceContext(context2))));
verify(responseObserver, times(1))
.onNext(
DeleteConfigsResponse.newBuilder()
.addAllDeletedConfigs(
List.of(
buildContextSpecificConfig(context1, config1, 10L, 20L),
buildContextSpecificConfig(context2, config2, 10L, 20L)))
.build());
verify(responseObserver, times(1)).onNext(argThat(this::matchDeletedResponse));
verify(responseObserver, times(1)).onCompleted();
verify(responseObserver, never()).onError(any(Throwable.class));

Expand All @@ -251,6 +245,13 @@ void deleteConfigs() throws IOException {
verify(responseObserver, times(1)).onError(any(Throwable.class));
}

private boolean matchDeletedResponse(DeleteConfigsResponse response) {
List<ContextSpecificConfig> configs = response.getDeletedConfigsList();
return configs.size() == 2
&& configs.contains(buildContextSpecificConfig("context1", config1, 10L, 20L))
&& configs.contains(buildContextSpecificConfig("context2", config2, 10L, 20L));
}

@Test
void deleteDefaultContextConfig() throws IOException {
ConfigStore configStore = mock(ConfigStore.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ message NotificationChannelMutableData {
repeated WebhookChannelConfig webhook_channel_config = 3;
repeated AwsS3BucketChannelConfig s3_bucket_channel_config = 4;
repeated SplunkIntegrationChannelConfig splunk_integration_channel_config = 5;
repeated SyslogIntegrationChannelConfig syslog_integration_channel_config = 6;
}

message AwsS3BucketChannelConfig {
Expand Down Expand Up @@ -55,3 +56,7 @@ message WebhookHeader {
message SplunkIntegrationChannelConfig {
string splunk_integration_id = 1;
}

message SyslogIntegrationChannelConfig {
string syslog_server_integration_id = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hypertrace.notification.config.service.v1.GetNotificationChannelRequest;
import org.hypertrace.notification.config.service.v1.NotificationChannelMutableData;
import org.hypertrace.notification.config.service.v1.SplunkIntegrationChannelConfig;
import org.hypertrace.notification.config.service.v1.SyslogIntegrationChannelConfig;
import org.hypertrace.notification.config.service.v1.UpdateNotificationChannelRequest;
import org.hypertrace.notification.config.service.v1.WebhookChannelConfig;
import org.hypertrace.notification.config.service.v1.WebhookHeader;
Expand Down Expand Up @@ -112,14 +113,17 @@ private void validateNotificationChannelMutableData(NotificationChannelMutableDa
if (data.getEmailChannelConfigCount() == 0
&& data.getWebhookChannelConfigCount() == 0
&& data.getS3BucketChannelConfigCount() == 0
&& data.getSplunkIntegrationChannelConfigCount() == 0) {
&& data.getSplunkIntegrationChannelConfigCount() == 0
&& data.getSyslogIntegrationChannelConfigCount() == 0) {
throw Status.INVALID_ARGUMENT.withDescription("No config present").asRuntimeException();
}
data.getEmailChannelConfigList().forEach(this::validateEmailChannelConfig);
data.getWebhookChannelConfigList().forEach(this::validateWebhookChannelConfig);
data.getS3BucketChannelConfigList().forEach(this::validateS3BucketConfig);
data.getSplunkIntegrationChannelConfigList()
.forEach(this::validateSplunkIntegrationChannelConfig);
data.getSyslogIntegrationChannelConfigList()
.forEach(this::validateSyslogIntegrationChannelConfig);
}

public void validateGetAllNotificationChannelsRequest(
Expand Down Expand Up @@ -180,4 +184,11 @@ private void validateSplunkIntegrationChannelConfig(
splunkIntegrationChannelConfig,
SplunkIntegrationChannelConfig.SPLUNK_INTEGRATION_ID_FIELD_NUMBER);
}

private void validateSyslogIntegrationChannelConfig(
SyslogIntegrationChannelConfig syslogIntegrationChannelConfig) {
validateNonDefaultPresenceOrThrow(
syslogIntegrationChannelConfig,
SyslogIntegrationChannelConfig.SYSLOG_SERVER_INTEGRATION_ID_FIELD_NUMBER);
}
}

0 comments on commit b8dfb1c

Please sign in to comment.