Skip to content

Commit 2356f1d

Browse files
authored
Move grok and dissect runtime fields to specific module (#69673)
As a follow-up of moving runtime fields to server, we'd like to remove the xpack plugin portions that are left. One part of this is the grok and dissect implementation which depends on grok and dissect libraries that painless does not have available. A new runtime-fields-common module is created to hold their implementations and plug in the necessary whitelists.
1 parent 2ce3a47 commit 2356f1d

File tree

10 files changed

+137
-93
lines changed

10 files changed

+137
-93
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
esplugin {
10+
description 'Module for runtime fields features and extensions that have large dependencies'
11+
classname 'org.elasticsearch.runtimefields.RuntimeFieldsCommonPlugin'
12+
extendedPlugins = ['lang-painless']
13+
}
14+
15+
dependencies {
16+
compileOnly project(':modules:lang-painless:spi')
17+
api project(':libs:elasticsearch-grok')
18+
api project(':libs:elasticsearch-dissect')
19+
}
20+
21+
//this plugin is here only for the painless extension, there are no unit tests
22+
tasks.named("testingConventions").configure { enabled = false }
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
22
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
33
* or more contributor license agreements. Licensed under the Elastic License
4-
* 2.0; you may not use this file except in compliance with the Elastic License
5-
* 2.0.
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
67
*/
78

8-
package org.elasticsearch.xpack.runtimefields.mapper;
9+
package org.elasticsearch.runtimefields;
910

1011
import org.apache.lucene.util.SetOnce;
1112
import org.elasticsearch.common.unit.TimeValue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.runtimefields;
10+
11+
import org.elasticsearch.client.Client;
12+
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
13+
import org.elasticsearch.cluster.service.ClusterService;
14+
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
15+
import org.elasticsearch.common.settings.Setting;
16+
import org.elasticsearch.common.settings.Settings;
17+
import org.elasticsearch.common.unit.TimeValue;
18+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
19+
import org.elasticsearch.env.Environment;
20+
import org.elasticsearch.env.NodeEnvironment;
21+
import org.elasticsearch.plugins.Plugin;
22+
import org.elasticsearch.repositories.RepositoriesService;
23+
import org.elasticsearch.script.ScriptService;
24+
import org.elasticsearch.threadpool.ThreadPool;
25+
import org.elasticsearch.watcher.ResourceWatcherService;
26+
27+
import java.util.Collection;
28+
import java.util.Collections;
29+
import java.util.List;
30+
import java.util.function.Supplier;
31+
32+
/**
33+
* The plugin class for all the runtime fields common functionality that requires large dependencies.
34+
* This plugin sets up the environment for the grok function to work in painless as part of the different
35+
* runtime fields contexts.
36+
*/
37+
public final class RuntimeFieldsCommonPlugin extends Plugin {
38+
39+
static final Setting<TimeValue> GROK_WATCHDOG_INTERVAL = Setting.timeSetting(
40+
"runtime_fields.grok.watchdog.interval",
41+
TimeValue.timeValueSeconds(1),
42+
Setting.Property.NodeScope
43+
);
44+
static final Setting<TimeValue> GROK_WATCHDOG_MAX_EXECUTION_TIME = Setting.timeSetting(
45+
"runtime_fields.grok.watchdog.max_execution_time",
46+
TimeValue.timeValueSeconds(1),
47+
Setting.Property.NodeScope
48+
);
49+
50+
private final NamedGroupExtractor.GrokHelper grokHelper;
51+
52+
public RuntimeFieldsCommonPlugin(Settings settings) {
53+
grokHelper = new NamedGroupExtractor.GrokHelper(
54+
GROK_WATCHDOG_INTERVAL.get(settings),
55+
GROK_WATCHDOG_MAX_EXECUTION_TIME.get(settings)
56+
);
57+
}
58+
59+
@Override
60+
public List<Setting<?>> getSettings() {
61+
return org.elasticsearch.common.collect.List.of(GROK_WATCHDOG_INTERVAL, GROK_WATCHDOG_MAX_EXECUTION_TIME);
62+
}
63+
64+
@Override
65+
public Collection<Object> createComponents(
66+
Client client,
67+
ClusterService clusterService,
68+
ThreadPool threadPool,
69+
ResourceWatcherService resourceWatcherService,
70+
ScriptService scriptService,
71+
NamedXContentRegistry xContentRegistry,
72+
Environment environment,
73+
NodeEnvironment nodeEnvironment,
74+
NamedWriteableRegistry namedWriteableRegistry,
75+
IndexNameExpressionResolver indexNameExpressionResolver,
76+
Supplier<RepositoriesService> repositoriesServiceSupplier
77+
) {
78+
grokHelper.finishInitializing(threadPool);
79+
return Collections.emptyList();
80+
}
81+
82+
public NamedGroupExtractor.GrokHelper grokHelper() {
83+
return grokHelper;
84+
}
85+
}
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
22
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
33
* or more contributor license agreements. Licensed under the Elastic License
4-
* 2.0; you may not use this file except in compliance with the Elastic License
5-
* 2.0.
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
67
*/
78

8-
package org.elasticsearch.xpack.runtimefields.mapper;
9+
package org.elasticsearch.runtimefields;
910

1011
import org.elasticsearch.painless.spi.PainlessExtension;
1112
import org.elasticsearch.painless.spi.Whitelist;
@@ -21,15 +22,17 @@
2122
import org.elasticsearch.runtimefields.mapper.LongFieldScript;
2223
import org.elasticsearch.runtimefields.mapper.StringFieldScript;
2324
import org.elasticsearch.script.ScriptContext;
24-
import org.elasticsearch.xpack.runtimefields.RuntimeFields;
2525

2626
import java.util.List;
2727
import java.util.Map;
2828

29+
/**
30+
* The painless extension that adds the necessary whitelist for grok and dissect to all the existing runtime fields contexts.
31+
*/
2932
public class RuntimeFieldsPainlessExtension implements PainlessExtension {
3033
private final List<Whitelist> whitelists;
3134

32-
public RuntimeFieldsPainlessExtension(RuntimeFields plugin) {
35+
public RuntimeFieldsPainlessExtension(RuntimeFieldsCommonPlugin plugin) {
3336
Whitelist commonWhitelist = WhitelistLoader.loadFromResourceFiles(RuntimeFieldsPainlessExtension.class, "common_whitelist.txt");
3437
Whitelist grokWhitelist = new Whitelist(
3538
commonWhitelist.classLoader,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.elasticsearch.runtimefields.RuntimeFieldsPainlessExtension
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
# or more contributor license agreements. Licensed under the Elastic License
4+
# 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
# in compliance with, at your election, the Elastic License 2.0 or the Server
6+
# Side Public License, v 1.
7+
#
8+
9+
class org.elasticsearch.runtimefields.NamedGroupExtractor @no_import {
10+
Map extract(String);
11+
}
12+
13+
static_import {
14+
org.elasticsearch.runtimefields.NamedGroupExtractor dissect(String) from_class org.elasticsearch.runtimefields.NamedGroupExtractor @compile_time_only
15+
org.elasticsearch.runtimefields.NamedGroupExtractor dissect(String, String) from_class org.elasticsearch.runtimefields.NamedGroupExtractor @compile_time_only
16+
}

x-pack/plugin/runtime-fields/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ esplugin {
44
name 'x-pack-runtime-fields'
55
description 'A module which adds support for runtime fields'
66
classname 'org.elasticsearch.xpack.runtimefields.RuntimeFields'
7-
extendedPlugins = ['x-pack-core', 'lang-painless']
7+
extendedPlugins = ['x-pack-core']
88
}
99
archivesBaseName = 'x-pack-runtime-fields'
1010

1111
dependencies {
1212
compileOnly project(":server")
13-
compileOnly project(':modules:lang-painless:spi')
14-
api project(':libs:elasticsearch-grok')
15-
api project(':libs:elasticsearch-dissect')
1613
compileOnly project(path: xpackModule('core'))
1714
}
1815

x-pack/plugin/runtime-fields/src/main/java/org/elasticsearch/xpack/runtimefields/RuntimeFields.java

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,18 @@
77

88
package org.elasticsearch.xpack.runtimefields;
99

10-
import org.elasticsearch.client.Client;
11-
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
12-
import org.elasticsearch.cluster.service.ClusterService;
1310
import org.elasticsearch.common.inject.Module;
14-
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
15-
import org.elasticsearch.common.settings.Setting;
16-
import org.elasticsearch.common.settings.Settings;
17-
import org.elasticsearch.common.unit.TimeValue;
18-
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
19-
import org.elasticsearch.env.Environment;
20-
import org.elasticsearch.env.NodeEnvironment;
2111

2212
import org.elasticsearch.plugins.Plugin;
23-
import org.elasticsearch.repositories.RepositoriesService;
24-
import org.elasticsearch.script.ScriptService;
25-
import org.elasticsearch.threadpool.ThreadPool;
26-
import org.elasticsearch.watcher.ResourceWatcherService;
2713
import org.elasticsearch.xpack.core.XPackPlugin;
28-
import org.elasticsearch.xpack.runtimefields.mapper.NamedGroupExtractor;
29-
import org.elasticsearch.xpack.runtimefields.mapper.NamedGroupExtractor.GrokHelper;
3014

3115
import java.util.Collection;
3216
import java.util.Collections;
33-
import java.util.List;
34-
import java.util.function.Supplier;
3517

3618
public final class RuntimeFields extends Plugin {
3719

38-
static final Setting<TimeValue> GROK_WATCHDOG_INTERVAL = Setting.timeSetting(
39-
"runtime_fields.grok.watchdog.interval",
40-
TimeValue.timeValueSeconds(1),
41-
Setting.Property.NodeScope
42-
);
43-
static final Setting<TimeValue> GROK_WATCHDOG_MAX_EXECUTION_TIME = Setting.timeSetting(
44-
"runtime_fields.grok.watchdog.max_execution_time",
45-
TimeValue.timeValueSeconds(1),
46-
Setting.Property.NodeScope
47-
);
48-
49-
private final NamedGroupExtractor.GrokHelper grokHelper;
50-
51-
public RuntimeFields(Settings settings) {
52-
grokHelper = new NamedGroupExtractor.GrokHelper(
53-
GROK_WATCHDOG_INTERVAL.get(settings),
54-
GROK_WATCHDOG_MAX_EXECUTION_TIME.get(settings)
55-
);
56-
}
57-
58-
@Override
59-
public List<Setting<?>> getSettings() {
60-
return org.elasticsearch.common.collect.List.of(GROK_WATCHDOG_INTERVAL, GROK_WATCHDOG_MAX_EXECUTION_TIME);
61-
}
62-
6320
@Override
6421
public Collection<Module> createGuiceModules() {
6522
return Collections.singletonList(b -> XPackPlugin.bindFeatureSet(b, RuntimeFieldsFeatureSet.class));
6623
}
67-
68-
@Override
69-
public Collection<Object> createComponents(
70-
Client client,
71-
ClusterService clusterService,
72-
ThreadPool threadPool,
73-
ResourceWatcherService resourceWatcherService,
74-
ScriptService scriptService,
75-
NamedXContentRegistry xContentRegistry,
76-
Environment environment,
77-
NodeEnvironment nodeEnvironment,
78-
NamedWriteableRegistry namedWriteableRegistry,
79-
IndexNameExpressionResolver indexNameExpressionResolver,
80-
Supplier<RepositoriesService> repositoriesServiceSupplier
81-
) {
82-
grokHelper.finishInitializing(threadPool);
83-
return org.elasticsearch.common.collect.List.of();
84-
}
85-
86-
public GrokHelper grokHelper() {
87-
return grokHelper;
88-
}
8924
}

x-pack/plugin/runtime-fields/src/main/resources/META-INF/services/org.elasticsearch.painless.spi.PainlessExtension

Lines changed: 0 additions & 1 deletion
This file was deleted.

x-pack/plugin/runtime-fields/src/main/resources/org/elasticsearch/xpack/runtimefields/mapper/common_whitelist.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)