From 3595195685891d67e72fbf8bfaf8169b8f3836c1 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Sat, 28 Mar 2020 12:40:08 -0400 Subject: [PATCH] Do not stash environment in machine learning (#54371) Today the machine learning plugin stashes a copy of the environment in its constructor, and uses the stashed copy to construct its components even though it is provided with an environment to create these components. What is more, the environment it creates in its constructor is not fully initialized, as it does not have the final copy of the settings, but the environment passed in while creating components does. This commit removes that stashed copy of the environment. --- .../java/org/elasticsearch/xpack/ml/MachineLearning.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index e17d06dbf9390..f2912f454e494 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -419,7 +419,6 @@ public Set getRoles() { private static final Logger logger = LogManager.getLogger(MachineLearning.class); private final Settings settings; - private final Environment env; private final boolean enabled; private final SetOnce autodetectProcessManager = new SetOnce<>(); @@ -431,7 +430,6 @@ public Set getRoles() { public MachineLearning(Settings settings, Path configPath) { this.settings = settings; this.enabled = XPackSettings.MACHINE_LEARNING_ENABLED.get(settings); - this.env = new Environment(settings, configPath); } protected XPackLicenseState getLicenseState() { return XPackPlugin.getSharedLicenseState(); } @@ -550,7 +548,7 @@ public Collection createComponents(Client client, ClusterService cluster JobConfigProvider jobConfigProvider = new JobConfigProvider(client, xContentRegistry); DatafeedConfigProvider datafeedConfigProvider = new DatafeedConfigProvider(client, xContentRegistry); UpdateJobProcessNotifier notifier = new UpdateJobProcessNotifier(client, clusterService, threadPool); - JobManager jobManager = new JobManager(env, + JobManager jobManager = new JobManager(environment, settings, jobResultsProvider, jobResultsPersister, @@ -613,7 +611,7 @@ public Collection createComponents(Client client, ClusterService cluster } NormalizerFactory normalizerFactory = new NormalizerFactory(normalizerProcessFactory, threadPool.executor(MachineLearning.UTILITY_THREAD_POOL_NAME)); - AutodetectProcessManager autodetectProcessManager = new AutodetectProcessManager(env, settings, client, threadPool, + AutodetectProcessManager autodetectProcessManager = new AutodetectProcessManager(environment, settings, client, threadPool, xContentRegistry, anomalyDetectionAuditor, clusterService, jobManager, jobResultsProvider, jobResultsPersister, jobDataCountsPersister, autodetectProcessFactory, normalizerFactory, nativeStorageProvider, indexNameExpressionResolver); this.autodetectProcessManager.set(autodetectProcessManager);