Skip to content

Commit

Permalink
feat(hooks): Add toggle for enabling/disabling platform event hook (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro93 authored and shirshanka committed Sep 8, 2022
1 parent 60fc667 commit bcfbae9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public void consume(final ConsumerRecord<String, GenericRecord> consumerRecord)

// Here - plug in additional "custom processor hooks"
for (MetadataChangeLogHook hook : this.hooks) {
if (!hook.isEnabled()) {
continue;
}
try (Timer.Context ignored = MetricUtils.timer(this.getClass(), hook.getClass().getSimpleName() + "_latency")
.time()) {
hook.invoke(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public interface MetadataChangeLogHook {
*/
default void init() { }

/**
* Return whether the hook is enabled or not. If not enabled, the below invoke method is not triggered
*/
default boolean isEnabled() {
return true;
}

/**
* Invoke the hook when a MetadataChangeLog is received
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -91,17 +92,25 @@ public class EntityChangeEventGeneratorHook implements MetadataChangeLogHook {
private final EntityClient _entityClient;
private final Authentication _systemAuthentication;
private final EntityRegistry _entityRegistry;
private final Boolean _isEnabled;

@Autowired
public EntityChangeEventGeneratorHook(
@Nonnull final AspectDifferRegistry aspectDifferRegistry,
@Nonnull final RestliEntityClient entityClient,
@Nonnull final Authentication systemAuthentication,
@Nonnull final EntityRegistry entityRegistry) {
@Nonnull final EntityRegistry entityRegistry,
@Nonnull @Value("${entityChangeEvents.enabled:true}") Boolean isEnabled) {
_aspectDifferRegistry = Objects.requireNonNull(aspectDifferRegistry);
_entityClient = Objects.requireNonNull(entityClient);
_systemAuthentication = Objects.requireNonNull(systemAuthentication);
_entityRegistry = Objects.requireNonNull(entityRegistry);
_isEnabled = isEnabled;
}

@Override
public boolean isEnabled() {
return _isEnabled;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void setupTest() {
differRegistry,
_mockClient,
mockAuthentication,
createMockEntityRegistry());
createMockEntityRegistry(),
true);
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions metadata-service/factories/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,6 @@ siblings:

featureFlags:
showSimplifiedHomepageByDefault: ${SHOW_SIMPLIFIED_HOMEPAGE_BY_DEFAULT:false} # shows a simplified homepage with just datasets, charts and dashboards by default to users. this can be configured in user settings

entityChangeEvents:
enabled: ${ENABLE_ENTITY_CHANGE_EVENTS_HOOK:true}

0 comments on commit bcfbae9

Please sign in to comment.