Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hooks): Add toggle for enabling/disabling platform event hook #5840

Merged
Merged
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 @@ -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}