Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ protected String buildClassNameForChangeEvent(T data) {
return data.getClass().getName();
}

protected Optional<Value> getDefaultConfigValue(RequestContext requestContext, T data) {
return Optional.empty();
}

protected List<ContextualConfigObject<T>> orderFetchedObjects(
List<ContextualConfigObject<T>> objects) {
return objects;
Expand Down Expand Up @@ -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(
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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. */
Expand Down Expand Up @@ -72,4 +73,23 @@ void sendUpdateNotification(
String context,
Value prevConfig,
Value latestConfig);

default void sendCreateNotification(
RequestContext requestContext,
String configType,
String context,
Value config,
Optional<Value> defaultConfig) {
sendCreateNotification(requestContext, configType, context, config);
}

default void sendUpdateNotification(
RequestContext requestContext,
String configType,
String context,
Value prevConfig,
Value latestConfig,
Optional<Value> defaultConfig) {
sendUpdateNotification(requestContext, configType, context, prevConfig, latestConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<Value> defaultConfig) {
produceCreateNotification(requestContext, configType, Optional.of(context), config, defaultConfig);
}

@Override
public void sendUpdateNotification(
RequestContext requestContext,
String configType,
String context,
Value prevConfig,
Value latestConfig,
Optional<Value> defaultConfig) {
produceUpdateNotification(
requestContext, configType, Optional.of(context), prevConfig, latestConfig, defaultConfig);
}

private void produceCreateNotification(
RequestContext requestContext,
String configType,
Optional<String> contextOptional,
Value config) {
Value config,
Optional<Value> defaultConfig) {
String tenantId = requestContext.getTenantId().get();
try {
Builder builder = ConfigChangeEventValue.newBuilder();
Expand All @@ -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) {
Expand All @@ -127,7 +151,8 @@ private void produceUpdateNotification(
String configType,
Optional<String> contextOptional,
Value prevConfig,
Value latestConfig) {
Value latestConfig,
Optional<Value> defaultConfig) {
String tenantId = requestContext.getTenantId().get();
try {
Builder builder = ConfigChangeEventValue.newBuilder();
Expand All @@ -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) {
Expand Down Expand Up @@ -176,6 +202,17 @@ private void produceDeleteNotification(
}
}

private void setDefaultConfigJson(Builder builder, Optional<Value> 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);
Expand Down
Loading