From b8dfb1c71a86a70ce79e0dc8de8c2c9b752a651f Mon Sep 17 00:00:00 2001 From: Prerana Singhal Date: Mon, 16 Oct 2023 23:31:00 +0530 Subject: [PATCH] feat: added syslog support in notification channel (#180) * feat: added syslog support in notification channel * Fixed the flaky test --- .../service/ConfigServiceGrpcImplTest.java | 17 +++++++++-------- .../service/v1/notification_channel.proto | 5 +++++ ...ionChannelConfigServiceRequestValidator.java | 13 ++++++++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/config-service-impl/src/test/java/org/hypertrace/config/service/ConfigServiceGrpcImplTest.java b/config-service-impl/src/test/java/org/hypertrace/config/service/ConfigServiceGrpcImplTest.java index 2508b8d9..f4b332a2 100644 --- a/config-service-impl/src/test/java/org/hypertrace/config/service/ConfigServiceGrpcImplTest.java +++ b/config-service-impl/src/test/java/org/hypertrace/config/service/ConfigServiceGrpcImplTest.java @@ -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; @@ -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)); @@ -251,6 +245,13 @@ void deleteConfigs() throws IOException { verify(responseObserver, times(1)).onError(any(Throwable.class)); } + private boolean matchDeletedResponse(DeleteConfigsResponse response) { + List 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); diff --git a/notification-channel-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_channel.proto b/notification-channel-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_channel.proto index 75a19a1c..e8e54974 100644 --- a/notification-channel-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_channel.proto +++ b/notification-channel-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_channel.proto @@ -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 { @@ -55,3 +56,7 @@ message WebhookHeader { message SplunkIntegrationChannelConfig { string splunk_integration_id = 1; } + +message SyslogIntegrationChannelConfig { + string syslog_server_integration_id = 1; +} diff --git a/notification-channel-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationChannelConfigServiceRequestValidator.java b/notification-channel-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationChannelConfigServiceRequestValidator.java index 0ccd7d20..1dac90d8 100644 --- a/notification-channel-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationChannelConfigServiceRequestValidator.java +++ b/notification-channel-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationChannelConfigServiceRequestValidator.java @@ -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; @@ -112,7 +113,8 @@ 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); @@ -120,6 +122,8 @@ private void validateNotificationChannelMutableData(NotificationChannelMutableDa data.getS3BucketChannelConfigList().forEach(this::validateS3BucketConfig); data.getSplunkIntegrationChannelConfigList() .forEach(this::validateSplunkIntegrationChannelConfig); + data.getSyslogIntegrationChannelConfigList() + .forEach(this::validateSyslogIntegrationChannelConfig); } public void validateGetAllNotificationChannelsRequest( @@ -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); + } }