mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-25 08:58:26 +00:00
feat(hooks): Add toggle for enabling/disabling platform event hook (#5840)
This commit is contained in:
parent
20138a32e5
commit
9434afc78a
@ -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);
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -79,7 +79,8 @@ public class EntityChangeEventGeneratorHookTest {
|
||||
differRegistry,
|
||||
_mockClient,
|
||||
mockAuthentication,
|
||||
createMockEntityRegistry());
|
||||
createMockEntityRegistry(),
|
||||
true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -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}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user