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

This commit is contained in:
Pedro Silva 2022-09-06 20:53:58 +01:00 committed by GitHub
parent 20138a32e5
commit 9434afc78a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 2 deletions

View File

@ -81,6 +81,9 @@ public class MetadataChangeLogProcessor {
// 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);

View File

@ -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
*/

View File

@ -35,6 +35,7 @@ import javax.annotation.Nonnull;
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;
@ -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

View File

@ -79,7 +79,8 @@ public class EntityChangeEventGeneratorHookTest {
differRegistry,
_mockClient,
mockAuthentication,
createMockEntityRegistry());
createMockEntityRegistry(),
true);
}
@Test

View File

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