Skip to content

Commit fa0373a

Browse files
authored
[7.x] [ML] Fix log spam and disable ILM/SLM history for native ML tests (#55475)
* [ML] fix native ML test log spam (#55459) This adds a dependency to ingest common. This removes the log spam resulting from basic plugins being enabled that require the common ingest processors. * removing unnecessary changes * removing unused imports * removing unnecessary java setting
1 parent 8e618fd commit fa0373a

File tree

3 files changed

+78
-5
lines changed

3 files changed

+78
-5
lines changed

x-pack/plugin/ml/qa/basic-multi-node/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ testClusters.integTest {
1515
setting 'xpack.watcher.enabled', 'false'
1616
setting 'xpack.ml.enabled', 'true'
1717
setting 'xpack.license.self_generated.type', 'trial'
18+
setting 'indices.lifecycle.history_index_enabled', 'false'
19+
setting 'slm.history_index_enabled', 'false'
1820
}

x-pack/plugin/ml/qa/native-multi-node-tests/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dependencies {
77
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
88
testCompile project(path: xpackModule('ml'), configuration: 'runtime')
99
testCompile project(path: xpackModule('ml'), configuration: 'testArtifacts')
10+
testCompile project(path: ':modules:ingest-common')
1011
}
1112

1213
// location for keys and certificates
@@ -51,6 +52,8 @@ testClusters.integTest {
5152
setting 'xpack.security.audit.enabled', 'false'
5253
setting 'xpack.license.self_generated.type', 'trial'
5354
setting 'xpack.ml.min_disk_space_off_heap', '200mb'
55+
setting 'indices.lifecycle.history_index_enabled', 'false'
56+
setting 'slm.history_index_enabled', 'false'
5457

5558
keystore 'bootstrap.password', 'x-pack-test-password'
5659
keystore 'xpack.security.transport.ssl.secure_key_passphrase', 'testnode'

x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeIntegTestCase.java

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@
1818
import org.elasticsearch.common.unit.TimeValue;
1919
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
2020
import org.elasticsearch.index.reindex.ReindexPlugin;
21+
import org.elasticsearch.ingest.common.IngestCommonPlugin;
2122
import org.elasticsearch.persistent.PersistentTaskParams;
2223
import org.elasticsearch.persistent.PersistentTaskState;
2324
import org.elasticsearch.plugins.Plugin;
25+
import org.elasticsearch.script.IngestScript;
26+
import org.elasticsearch.script.MockScriptEngine;
27+
import org.elasticsearch.script.MockScriptPlugin;
28+
import org.elasticsearch.script.ScoreScript;
29+
import org.elasticsearch.script.ScriptContext;
30+
import org.elasticsearch.script.ScriptEngine;
2431
import org.elasticsearch.search.SearchModule;
2532
import org.elasticsearch.test.ESIntegTestCase;
2633
import org.elasticsearch.test.SecuritySettingsSourceField;
@@ -35,21 +42,26 @@
3542
import org.elasticsearch.xpack.core.ilm.LifecycleType;
3643
import org.elasticsearch.xpack.core.ilm.RolloverAction;
3744
import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType;
45+
import org.elasticsearch.xpack.core.ml.MlMetaIndex;
3846
import org.elasticsearch.xpack.core.ml.MlMetadata;
3947
import org.elasticsearch.xpack.core.ml.MlTasks;
4048
import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction;
41-
import org.elasticsearch.xpack.core.ml.action.GetFiltersAction;
4249
import org.elasticsearch.xpack.core.ml.action.OpenJobAction;
4350
import org.elasticsearch.xpack.core.ml.action.PutFilterAction;
4451
import org.elasticsearch.xpack.core.ml.action.SetUpgradeModeAction;
4552
import org.elasticsearch.xpack.core.ml.action.StartDataFrameAnalyticsAction;
4653
import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction;
4754
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedState;
4855
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsTaskState;
56+
import org.elasticsearch.xpack.core.ml.inference.persistence.InferenceIndexConstants;
4957
import org.elasticsearch.xpack.core.ml.job.config.JobTaskState;
5058
import org.elasticsearch.xpack.core.ml.job.config.MlFilter;
59+
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex;
60+
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields;
61+
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
5162
import org.elasticsearch.xpack.core.security.SecurityField;
5263
import org.elasticsearch.xpack.core.security.authc.TokenMetadata;
64+
import org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry;
5365
import org.elasticsearch.xpack.ilm.IndexLifecycle;
5466

5567
import java.io.IOException;
@@ -59,8 +71,11 @@
5971
import java.util.Arrays;
6072
import java.util.Collection;
6173
import java.util.Collections;
74+
import java.util.HashSet;
6275
import java.util.List;
6376
import java.util.Map;
77+
import java.util.Set;
78+
import java.util.function.Function;
6479

6580
import static org.elasticsearch.test.XContentTestUtils.convertToMap;
6681
import static org.elasticsearch.test.XContentTestUtils.differenceBetweenMapsIgnoringArrayOrder;
@@ -82,6 +97,11 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
8297
return Arrays.asList(
8398
LocalStateCompositeXPackPlugin.class,
8499
Netty4Plugin.class,
100+
// The monitoring plugin requires script and gsub processors to be loaded
101+
IngestCommonPlugin.class,
102+
// The monitoring plugin script processor references painless. Include this for script compilation.
103+
// This is to reduce log spam
104+
MockPainlessScriptEngine.TestPlugin.class,
85105
// ILM is required for .ml-state template index settings
86106
IndexLifecycle.class);
87107
}
@@ -110,7 +130,9 @@ protected Settings externalClusterClientSettings() {
110130
builder.put(NetworkModule.TRANSPORT_TYPE_KEY, SecurityField.NAME4);
111131
builder.put(SecurityField.USER_SETTING.getKey(), "x_pack_rest_user:" + SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING);
112132
builder.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), true);
133+
builder.put(XPackSettings.WATCHER_ENABLED.getKey(), false);
113134
builder.put(LifecycleSettings.LIFECYCLE_HISTORY_INDEX_ENABLED_SETTING.getKey(), false);
135+
builder.put(LifecycleSettings.SLM_HISTORY_INDEX_ENABLED_SETTING.getKey(), false);
114136
builder.put("xpack.security.transport.ssl.enabled", true);
115137
builder.put("xpack.security.transport.ssl.key", key.toAbsolutePath().toString());
116138
builder.put("xpack.security.transport.ssl.certificate", certificate.toAbsolutePath().toString());
@@ -125,6 +147,18 @@ protected void cleanUp() {
125147
waitForPendingTasks();
126148
}
127149

150+
@Override
151+
protected Set<String> excludeTemplates() {
152+
return new HashSet<>(Arrays.asList(
153+
NotificationsIndex.NOTIFICATIONS_INDEX,
154+
MlMetaIndex.INDEX_NAME,
155+
AnomalyDetectorsIndexFields.STATE_INDEX_PREFIX,
156+
AnomalyDetectorsIndex.jobResultsIndexPrefix(),
157+
InferenceIndexConstants.LATEST_INDEX_NAME,
158+
SnapshotLifecycleTemplateRegistry.SLM_TEMPLATE_NAME
159+
));
160+
}
161+
128162
protected abstract void cleanUpResources();
129163

130164
private void waitForPendingTasks() {
@@ -166,10 +200,6 @@ protected PutFilterAction.Response putMlFilter(MlFilter filter) {
166200
return client().execute(PutFilterAction.INSTANCE, new PutFilterAction.Request(filter)).actionGet();
167201
}
168202

169-
protected GetFiltersAction.Response getMlFilters() {
170-
return client().execute(GetFiltersAction.INSTANCE, new GetFiltersAction.Request()).actionGet();
171-
}
172-
173203
@Override
174204
protected void ensureClusterStateConsistency() throws IOException {
175205
if (cluster() != null && cluster().size() > 0) {
@@ -228,4 +258,42 @@ protected void ensureClusterStateConsistency() throws IOException {
228258
}
229259
}
230260
}
261+
262+
public static class MockPainlessScriptEngine extends MockScriptEngine {
263+
264+
public static final String NAME = "painless";
265+
266+
public static class TestPlugin extends MockScriptPlugin {
267+
@Override
268+
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
269+
return new MockPainlessScriptEngine();
270+
}
271+
272+
@Override
273+
protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
274+
return Collections.emptyMap();
275+
}
276+
}
277+
278+
@Override
279+
public String getType() {
280+
return NAME;
281+
}
282+
283+
@Override
284+
public <T> T compile(String name, String script, ScriptContext<T> context, Map<String, String> options) {
285+
if (context.instanceClazz.equals(ScoreScript.class)) {
286+
return context.factoryClazz.cast(new MockScoreScript(p -> 0.0));
287+
}
288+
if (context.name.equals("ingest")) {
289+
IngestScript.Factory factory = vars -> new IngestScript(vars) {
290+
@Override
291+
public void execute(Map<String, Object> ctx) {
292+
}
293+
};
294+
return context.factoryClazz.cast(factory);
295+
}
296+
throw new IllegalArgumentException("mock painless does not know how to handle context [" + context.name + "]");
297+
}
298+
}
231299
}

0 commit comments

Comments
 (0)