diff --git a/config-object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java b/config-object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java index 5e53bca2a3..03256ea947 100644 --- a/config-object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java +++ b/config-object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java @@ -86,6 +86,10 @@ protected String buildClassNameForChangeEvent(T data) { return data.getClass().getName(); } + protected Optional getDefaultConfigValue(RequestContext requestContext, T data) { + return Optional.empty(); + } + protected List> orderFetchedObjects( List> objects) { return objects; @@ -333,7 +337,8 @@ private void tryReportCreation(RequestContext requestContext, ContextualConfigOb requestContext, this.buildClassNameForChangeEvent(result.getData()), result.getContext(), - this.buildValueForChangeEvent(result.getData()))); + this.buildValueForChangeEvent(result.getData()), + getDefaultConfigValue(requestContext, result.getData()))); } private void tryReportUpdate( @@ -356,7 +361,8 @@ private void tryReportUpdate( previousValue); return previousValue; }), - this.buildValueForChangeEvent(result.getData()))); + this.buildValueForChangeEvent(result.getData()), + getDefaultConfigValue(requestContext, result.getData()))); } protected Deadline getDeadline() { diff --git a/config-service-change-event-api/src/main/proto/org/hypertrace/config/change/event/v1/config_change_event_value.proto b/config-service-change-event-api/src/main/proto/org/hypertrace/config/change/event/v1/config_change_event_value.proto index 728fef1895..a1596a2ce6 100644 --- a/config-service-change-event-api/src/main/proto/org/hypertrace/config/change/event/v1/config_change_event_value.proto +++ b/config-service-change-event-api/src/main/proto/org/hypertrace/config/change/event/v1/config_change_event_value.proto @@ -16,6 +16,7 @@ message ConfigChangeEventValue { optional string user_name = 5; string user_email = 7; int64 event_time_millis = 6; + string default_config_json = 8; } message ConfigCreateEvent { diff --git a/config-service-change-event-generator/src/main/java/org/hypertrace/config/service/change/event/api/ConfigChangeEventGenerator.java b/config-service-change-event-generator/src/main/java/org/hypertrace/config/service/change/event/api/ConfigChangeEventGenerator.java index 6181cfa293..cbec5026b9 100644 --- a/config-service-change-event-generator/src/main/java/org/hypertrace/config/service/change/event/api/ConfigChangeEventGenerator.java +++ b/config-service-change-event-generator/src/main/java/org/hypertrace/config/service/change/event/api/ConfigChangeEventGenerator.java @@ -1,6 +1,7 @@ package org.hypertrace.config.service.change.event.api; import com.google.protobuf.Value; +import java.util.Optional; import org.hypertrace.core.grpcutils.context.RequestContext; /** The interface config change event generator. */ @@ -72,4 +73,23 @@ void sendUpdateNotification( String context, Value prevConfig, Value latestConfig); + + default void sendCreateNotification( + RequestContext requestContext, + String configType, + String context, + Value config, + Optional defaultConfig) { + sendCreateNotification(requestContext, configType, context, config); + } + + default void sendUpdateNotification( + RequestContext requestContext, + String configType, + String context, + Value prevConfig, + Value latestConfig, + Optional defaultConfig) { + sendUpdateNotification(requestContext, configType, context, prevConfig, latestConfig); + } } diff --git a/config-service-change-event-generator/src/main/java/org/hypertrace/config/service/change/event/impl/ConfigChangeEventGeneratorImpl.java b/config-service-change-event-generator/src/main/java/org/hypertrace/config/service/change/event/impl/ConfigChangeEventGeneratorImpl.java index 86aabdd750..885e867cd8 100644 --- a/config-service-change-event-generator/src/main/java/org/hypertrace/config/service/change/event/impl/ConfigChangeEventGeneratorImpl.java +++ b/config-service-change-event-generator/src/main/java/org/hypertrace/config/service/change/event/impl/ConfigChangeEventGeneratorImpl.java @@ -57,7 +57,7 @@ public class ConfigChangeEventGeneratorImpl implements ConfigChangeEventGenerato @Override public void sendCreateNotification( RequestContext requestContext, String configType, Value config) { - produceCreateNotification(requestContext, configType, Optional.empty(), config); + produceCreateNotification(requestContext, configType, Optional.empty(), config, Optional.empty()); } @Override @@ -70,13 +70,13 @@ public void sendDeleteNotification( public void sendUpdateNotification( RequestContext requestContext, String configType, Value prevConfig, Value latestConfig) { produceUpdateNotification( - requestContext, configType, Optional.empty(), prevConfig, latestConfig); + requestContext, configType, Optional.empty(), prevConfig, latestConfig, Optional.empty()); } @Override public void sendCreateNotification( RequestContext requestContext, String configType, String context, Value config) { - produceCreateNotification(requestContext, configType, Optional.of(context), config); + produceCreateNotification(requestContext, configType, Optional.of(context), config, Optional.empty()); } @Override @@ -93,14 +93,37 @@ public void sendUpdateNotification( Value prevConfig, Value latestConfig) { produceUpdateNotification( - requestContext, configType, Optional.of(context), prevConfig, latestConfig); + requestContext, configType, Optional.of(context), prevConfig, latestConfig, Optional.empty()); + } + + @Override + public void sendCreateNotification( + RequestContext requestContext, + String configType, + String context, + Value config, + Optional defaultConfig) { + produceCreateNotification(requestContext, configType, Optional.of(context), config, defaultConfig); + } + + @Override + public void sendUpdateNotification( + RequestContext requestContext, + String configType, + String context, + Value prevConfig, + Value latestConfig, + Optional defaultConfig) { + produceUpdateNotification( + requestContext, configType, Optional.of(context), prevConfig, latestConfig, defaultConfig); } private void produceCreateNotification( RequestContext requestContext, String configType, Optional contextOptional, - Value config) { + Value config, + Optional defaultConfig) { String tenantId = requestContext.getTenantId().get(); try { Builder builder = ConfigChangeEventValue.newBuilder(); @@ -110,6 +133,7 @@ private void produceCreateNotification( .build()); builder.setEventTimeMillis(clock.millis()); populateUserDetails(requestContext, builder); + setDefaultConfigJson(builder, defaultConfig); configChangeEventProducer.send( KeyUtil.getKey(tenantId, configType, contextOptional), builder.build()); } catch (Exception ex) { @@ -127,7 +151,8 @@ private void produceUpdateNotification( String configType, Optional contextOptional, Value prevConfig, - Value latestConfig) { + Value latestConfig, + Optional defaultConfig) { String tenantId = requestContext.getTenantId().get(); try { Builder builder = ConfigChangeEventValue.newBuilder(); @@ -138,6 +163,7 @@ private void produceUpdateNotification( .build()); builder.setEventTimeMillis(clock.millis()); populateUserDetails(requestContext, builder); + setDefaultConfigJson(builder, defaultConfig); configChangeEventProducer.send( KeyUtil.getKey(tenantId, configType, contextOptional), builder.build()); } catch (Exception ex) { @@ -176,6 +202,17 @@ private void produceDeleteNotification( } } + private void setDefaultConfigJson(Builder builder, Optional defaultConfig) { + defaultConfig.ifPresent( + value -> { + try { + builder.setDefaultConfigJson(ConfigProtoConverter.convertToJsonString(value)); + } catch (Exception ex) { + log.warn("Unable to convert default config to JSON for change event", ex); + } + }); + } + private void populateUserDetails(RequestContext requestContext, Builder builder) { requestContext.getUserId().ifPresent(builder::setUserId); requestContext.getName().ifPresent(builder::setUserName);