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

[WIP] spark: load config resolver #1146

Closed
wants to merge 1 commit into from
Closed
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 @@ -23,6 +23,8 @@
import com.netflix.spectator.sidecar.SidecarRegistry;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigResolveOptions;
import com.typesafe.config.ConfigResolver;
import org.apache.spark.metrics.sink.Sink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -56,7 +58,7 @@ public SparkSink(
Properties properties,
MetricRegistry registry,
org.apache.spark.SecurityManager manager) {
final Config config = loadConfig();
final Config config = loadConfig(properties);
sidecarRegistry = new SidecarRegistry(
Clock.SYSTEM, new SpectatorConfig(config.getConfig("spectator.spark.sidecar")));
reporter = SpectatorReporter.forRegistry(registry)
Expand All @@ -76,8 +78,24 @@ public SparkSink(
}
}

private Config loadConfig() {
return ConfigFactory.load(pickClassLoader());
private Config loadConfig(Properties properties) {
ClassLoader classLoader = pickClassLoader();
String resolverClassName = properties.getProperty("resolver");
if (resolverClassName == null) {
return ConfigFactory.load(classLoader);
}
ConfigResolver configResolver = getConfigResolver(resolverClassName, classLoader);
ConfigResolveOptions resolveOptions = ConfigResolveOptions.defaults().appendResolver(configResolver);
return ConfigFactory.load(classLoader, resolveOptions);
}

private static ConfigResolver getConfigResolver(String resolverClassName, ClassLoader classLoader) {
try {
LOGGER.info("Creating ConfigResolver instance for {}", resolverClassName);
return (ConfigResolver) classLoader.loadClass(resolverClassName).getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new IllegalArgumentException(String.format("Error creating instance for %s", resolverClassName), e);
}
}

@SuppressWarnings("PMD.UseProperClassLoader")
Expand Down
Loading