Skip to content

Commit

Permalink
feat(pluginRegistry): add configuration to reduce runnable frequency (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHolstien authored Mar 6, 2024
1 parent d476f5f commit eed0abe
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class PluginEntityRegistryLoader {
private static int _MAXLOADFAILURES = 5;
private final Boolean scanningEnabled;
private final String pluginDirectory;
private final int loadDelaySeconds;
// Registry Name -> Registry Version -> (Registry, LoadResult)
private final Map<String, Map<ComparableVersion, Pair<EntityRegistry, EntityRegistryLoadResult>>>
patchRegistries;
Expand All @@ -38,7 +39,7 @@ public class PluginEntityRegistryLoader {
private boolean booted = false;
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);

public PluginEntityRegistryLoader(String pluginDirectory) {
public PluginEntityRegistryLoader(String pluginDirectory, int loadDelaySeconds) {
File directory = new File(pluginDirectory);
if (!directory.exists() || !directory.isDirectory()) {
log.warn(
Expand All @@ -50,6 +51,7 @@ public PluginEntityRegistryLoader(String pluginDirectory) {
}
this.pluginDirectory = pluginDirectory;
this.patchRegistries = new HashMap<>();
this.loadDelaySeconds = loadDelaySeconds;
}

public Map<String, Map<ComparableVersion, Pair<EntityRegistry, EntityRegistryLoadResult>>>
Expand Down Expand Up @@ -133,7 +135,7 @@ public PluginEntityRegistryLoader start(boolean waitForInitialization)
}
},
0,
5,
loadDelaySeconds,
TimeUnit.SECONDS);
started = true;
if (waitForInitialization) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public AspectTemplateEngine getAspectTemplateEngine() {

MergedEntityRegistry configEntityRegistry = new MergedEntityRegistry(baseEntityRegistry);
PluginEntityRegistryLoader pluginEntityRegistryLoader =
new PluginEntityRegistryLoader(TestConstants.BASE_DIRECTORY)
new PluginEntityRegistryLoader(TestConstants.BASE_DIRECTORY, 60)
.withBaseRegistry(configEntityRegistry)
.start(true);
assertEquals(pluginEntityRegistryLoader.getPatchRegistries().size(), 1);
Expand Down Expand Up @@ -170,7 +170,7 @@ public void testEntityRegistryWithGoodBase() throws FileNotFoundException, Inter

MergedEntityRegistry mergedEntityRegistry = new MergedEntityRegistry(getBaseEntityRegistry());
PluginEntityRegistryLoader pluginEntityRegistryLoader =
new PluginEntityRegistryLoader(BASE_DIRECTORY)
new PluginEntityRegistryLoader(BASE_DIRECTORY, 60)
.withBaseRegistry(mergedEntityRegistry)
.start(true);
assertEquals(pluginEntityRegistryLoader.getPatchRegistries().size(), 1);
Expand Down Expand Up @@ -215,7 +215,7 @@ public void testEntityRegistryVersioning() throws InterruptedException {
String multiversionPluginDir = "src/test_plugins/";

PluginEntityRegistryLoader pluginEntityRegistryLoader =
new PluginEntityRegistryLoader(multiversionPluginDir)
new PluginEntityRegistryLoader(multiversionPluginDir, 60)
.withBaseRegistry(mergedEntityRegistry)
.start(true);
Map<String, Map<ComparableVersion, Pair<EntityRegistry, EntityRegistryLoadResult>>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
@Data
public class EntityRegistryPluginConfiguration {
String path;
int loadDelaySeconds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ datahub:
pluginSecurityMode: ${PLUGIN_SECURITY_MODE:RESTRICTED} # Possible value RESTRICTED or LENIENT, default to RESTRICTED
entityRegistry:
path: ${ENTITY_REGISTRY_PLUGIN_PATH:/etc/datahub/plugins/models}
loadDelaySeconds: ${ENTITY_REGISTRY_PLUGIN_LOAD_DELAY_SECONDS:60} # Rate at which plugin runnable executes, will run every N seconds.
retention:
path: ${RETENTION_PLUGIN_PATH:/etc/datahub/plugins/retention}
auth:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package com.linkedin.gms.factory.entityregistry;

import com.linkedin.gms.factory.config.ConfigurationProvider;
import com.linkedin.metadata.config.EntityRegistryPluginConfiguration;
import com.linkedin.metadata.models.registry.PluginEntityRegistryLoader;
import com.linkedin.metadata.spring.YamlPropertySourceFactory;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import javax.annotation.Nonnull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource(value = "classpath:/application.yml", factory = YamlPropertySourceFactory.class)
public class PluginEntityRegistryFactory {

@Value("${datahub.plugin.entityRegistry.path}")
private String pluginRegistryPath;

@Bean(name = "pluginEntityRegistry")
@Nonnull
protected PluginEntityRegistryLoader getInstance()
protected PluginEntityRegistryLoader getInstance(ConfigurationProvider configurationProvider)
throws FileNotFoundException, MalformedURLException {
return new PluginEntityRegistryLoader(pluginRegistryPath);
EntityRegistryPluginConfiguration pluginConfiguration =
configurationProvider.getDatahub().getPlugin().getEntityRegistry();
return new PluginEntityRegistryLoader(
pluginConfiguration.getPath(), pluginConfiguration.getLoadDelaySeconds());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public EntityRegistry entityRegistry() throws EntityRegistryException, Interrupt
dependency.
*/
PluginEntityRegistryLoader custom =
new PluginEntityRegistryLoader(getClass().getResource("/custom-model").getFile());
new PluginEntityRegistryLoader(getClass().getResource("/custom-model").getFile(), 60);

ConfigEntityRegistry standard =
new ConfigEntityRegistry(
Expand Down

0 comments on commit eed0abe

Please sign in to comment.