Skip to content

Commit a46977f

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 4a94534 commit a46977f

File tree

10 files changed

+136
-93
lines changed

10 files changed

+136
-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,84 @@
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.List;
29+
import java.util.function.Supplier;
30+
31+
/**
32+
* The plugin class for all the runtime fields common functionality that requires large dependencies.
33+
* This plugin sets up the environment for the grok function to work in painless as part of the different
34+
* runtime fields contexts.
35+
*/
36+
public final class RuntimeFieldsCommonPlugin extends Plugin {
37+
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 RuntimeFieldsCommonPlugin(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 List.of(GROK_WATCHDOG_INTERVAL, GROK_WATCHDOG_MAX_EXECUTION_TIME);
61+
}
62+
63+
@Override
64+
public Collection<Object> createComponents(
65+
Client client,
66+
ClusterService clusterService,
67+
ThreadPool threadPool,
68+
ResourceWatcherService resourceWatcherService,
69+
ScriptService scriptService,
70+
NamedXContentRegistry xContentRegistry,
71+
Environment environment,
72+
NodeEnvironment nodeEnvironment,
73+
NamedWriteableRegistry namedWriteableRegistry,
74+
IndexNameExpressionResolver indexNameExpressionResolver,
75+
Supplier<RepositoriesService> repositoriesServiceSupplier
76+
) {
77+
grokHelper.finishInitializing(threadPool);
78+
return List.of();
79+
}
80+
81+
public NamedGroupExtractor.GrokHelper grokHelper() {
82+
return grokHelper;
83+
}
84+
}
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
@@ -9,85 +9,20 @@
99

1010
import org.elasticsearch.action.ActionRequest;
1111
import org.elasticsearch.action.ActionResponse;
12-
import org.elasticsearch.client.Client;
13-
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
14-
import org.elasticsearch.cluster.service.ClusterService;
15-
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
16-
import org.elasticsearch.common.settings.Setting;
17-
import org.elasticsearch.common.settings.Settings;
18-
import org.elasticsearch.common.unit.TimeValue;
19-
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
20-
import org.elasticsearch.env.Environment;
21-
import org.elasticsearch.env.NodeEnvironment;
2212
import org.elasticsearch.plugins.ActionPlugin;
2313
import org.elasticsearch.plugins.Plugin;
24-
import org.elasticsearch.repositories.RepositoriesService;
25-
import org.elasticsearch.script.ScriptService;
26-
import org.elasticsearch.threadpool.ThreadPool;
27-
import org.elasticsearch.watcher.ResourceWatcherService;
2814
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
2915
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
30-
import org.elasticsearch.xpack.runtimefields.mapper.NamedGroupExtractor;
31-
import org.elasticsearch.xpack.runtimefields.mapper.NamedGroupExtractor.GrokHelper;
3216

33-
import java.util.Collection;
3417
import java.util.List;
35-
import java.util.function.Supplier;
3618

3719
public final class RuntimeFields extends Plugin implements ActionPlugin {
3820

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 RuntimeFields(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 List.of(GROK_WATCHDOG_INTERVAL, GROK_WATCHDOG_MAX_EXECUTION_TIME);
62-
}
63-
6421
@Override
6522
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
6623
return List.of(
6724
new ActionPlugin.ActionHandler<>(XPackUsageFeatureAction.RUNTIME_FIELDS, RuntimeFieldsUsageTransportAction.class),
6825
new ActionPlugin.ActionHandler<>(XPackInfoFeatureAction.RUNTIME_FIELDS, RuntimeFieldsInfoTransportAction.class)
6926
);
7027
}
71-
72-
@Override
73-
public Collection<Object> createComponents(
74-
Client client,
75-
ClusterService clusterService,
76-
ThreadPool threadPool,
77-
ResourceWatcherService resourceWatcherService,
78-
ScriptService scriptService,
79-
NamedXContentRegistry xContentRegistry,
80-
Environment environment,
81-
NodeEnvironment nodeEnvironment,
82-
NamedWriteableRegistry namedWriteableRegistry,
83-
IndexNameExpressionResolver indexNameExpressionResolver,
84-
Supplier<RepositoriesService> repositoriesServiceSupplier
85-
) {
86-
grokHelper.finishInitializing(threadPool);
87-
return List.of();
88-
}
89-
90-
public GrokHelper grokHelper() {
91-
return grokHelper;
92-
}
9328
}

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)