Skip to content

Commit 1e87f67

Browse files
mashhurselasticsearchmachineyaauie
authored
[Logstash] Move elastic_integration plugin usage to ES logstash-bridge. (#131486)
* Make metadata version field accessible, introduce inverse wrapper with default method to avoid required interface implementation. * RedactPlugin, IngestCommonPlugin and IngestUserAgent plugins moved to the bridge. Processor definitions also moved to the bridge. Module simplifications. * Ingest common plugin simplification. * [CI] Auto commit changes from spotless * Open an access for the x-pack spatial module resources. * [CI] Auto commit changes from spotless * Open access to resources in mapper constant keyword. * Add an access to resource in x-pack wildcard module. * Export and open access to sub-package spatial modules. * Provide module service implementations with provides keyword in x-pack spatial/wildcard/mapper-constant modules. * Export x-pack spatial module packages to make accessible to ES server module. * spike refactor of logstash-bridge stable API - transitions terminology from wrap/unwrap to toInternal/fromInternal - adds abstract base class for ProcessorBridge, since we are expecting external implementations, which includes an internal-shaped proxy to the external definition. - adds copious commentary for the classes that were previously shipped * Format the recent logstash-bridge changes. * Wildcard and mapper constant keyword modules open resource access to painless spi * Rename constant-keyword, wildcard, redact and spatial modules in a way that remove xpack from namings. Move constants from processor bridge to align with a proper place where Ingest common plugin bridge is suitable. --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: Ry Biesemeyer <[email protected]>
1 parent 71130a6 commit 1e87f67

File tree

24 files changed

+548
-138
lines changed

24 files changed

+548
-138
lines changed

libs/logstash-bridge/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ dependencies {
1717
compileOnly project(':modules:lang-painless:spi')
1818
compileOnly project(':modules:lang-mustache')
1919
compileOnly project(':modules:ingest-common')
20-
// compileOnly project(':modules:ingest-geoip')
20+
compileOnly project(':modules:ingest-geoip')
21+
compileOnly project(':modules:ingest-user-agent')
22+
compileOnly project(':x-pack:plugin:core')
23+
compileOnly project(':x-pack:plugin:mapper-constant-keyword')
24+
compileOnly project(':x-pack:plugin:redact')
25+
compileOnly project(':x-pack:plugin:spatial')
26+
compileOnly project(':x-pack:plugin:wildcard')
2127
}
2228

2329
tasks.named('forbiddenApisMain').configure {

libs/logstash-bridge/src/main/java/module-info.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
requires org.elasticsearch.server;
1515
requires org.elasticsearch.painless;
1616
requires org.elasticsearch.painless.spi;
17+
requires org.elasticsearch.ingest.common;
18+
requires org.elasticsearch.ingest.useragent;
1719
requires org.elasticsearch.mustache;
1820
requires org.elasticsearch.xcontent;
21+
requires org.elasticsearch.xcore;
22+
requires org.elasticsearch.constantkeyword;
23+
requires org.elasticsearch.redact;
24+
requires org.elasticsearch.spatial;
25+
requires org.elasticsearch.wildcard;
1926

2027
exports org.elasticsearch.logstashbridge;
2128
exports org.elasticsearch.logstashbridge.common;

libs/logstash-bridge/src/main/java/org/elasticsearch/logstashbridge/StableBridgeAPI.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,52 @@
1616
/**
1717
* A {@code StableBridgeAPI} is the stable bridge to an Elasticsearch API, and can produce instances
1818
* from the actual API that they mirror. As part of the LogstashBridge project, these classes are relied
19-
* upon by the "Elastic Integration Filter Plugin" for Logstash and their external shapes mut not change
19+
* upon by the "Elastic Integration Filter Plugin" for Logstash and their external shapes must not change
2020
* without coordination with the maintainers of that project.
2121
*
22-
* @param <T> the actual type of the Elasticsearch API being mirrored
22+
* @param <INTERNAL> the actual type of the Elasticsearch API being mirrored
2323
*/
24-
public interface StableBridgeAPI<T> {
25-
T unwrap();
24+
public interface StableBridgeAPI<INTERNAL> {
25+
INTERNAL toInternal();
2626

27-
static <T> T unwrapNullable(final StableBridgeAPI<T> nullableStableBridgeAPI) {
27+
static <T> T toInternalNullable(final StableBridgeAPI<T> nullableStableBridgeAPI) {
2828
if (Objects.isNull(nullableStableBridgeAPI)) {
2929
return null;
3030
}
31-
return nullableStableBridgeAPI.unwrap();
31+
return nullableStableBridgeAPI.toInternal();
3232
}
3333

34-
static <K, T> Map<K, T> unwrap(final Map<K, ? extends StableBridgeAPI<T>> bridgeMap) {
35-
return bridgeMap.entrySet().stream().collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, e -> e.getValue().unwrap()));
34+
static <K, T> Map<K, T> toInternal(final Map<K, ? extends StableBridgeAPI<T>> bridgeMap) {
35+
return bridgeMap.entrySet().stream().collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, e -> e.getValue().toInternal()));
3636
}
3737

38-
static <K, T, B extends StableBridgeAPI<T>> Map<K, B> wrap(final Map<K, T> rawMap, final Function<T, B> wrapFunction) {
39-
return rawMap.entrySet().stream().collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, e -> wrapFunction.apply(e.getValue())));
38+
static <K, T, B extends StableBridgeAPI<T>> Map<K, B> fromInternal(final Map<K, T> rawMap, final Function<T, B> externalizor) {
39+
return rawMap.entrySet().stream().collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, e -> externalizor.apply(e.getValue())));
4040
}
4141

42-
static <T, B extends StableBridgeAPI<T>> B wrap(final T delegate, final Function<T, B> wrapFunction) {
42+
static <T, B extends StableBridgeAPI<T>> B fromInternal(final T delegate, final Function<T, B> externalizor) {
4343
if (Objects.isNull(delegate)) {
4444
return null;
4545
}
46-
return wrapFunction.apply(delegate);
46+
return externalizor.apply(delegate);
4747
}
4848

49-
abstract class Proxy<T> implements StableBridgeAPI<T> {
50-
protected final T delegate;
49+
/**
50+
* An {@code ProxyInternal<INTERNAL>} is an implementation of {@code StableBridgeAPI<INTERNAL>} that
51+
* proxies calls to a delegate that is an actual {@code INTERNAL}.
52+
*
53+
* @param <INTERNAL>
54+
*/
55+
abstract class ProxyInternal<INTERNAL> implements StableBridgeAPI<INTERNAL> {
56+
protected final INTERNAL internalDelegate;
5157

52-
protected Proxy(final T delegate) {
53-
this.delegate = delegate;
58+
protected ProxyInternal(final INTERNAL internalDelegate) {
59+
this.internalDelegate = internalDelegate;
5460
}
5561

5662
@Override
57-
public T unwrap() {
58-
return delegate;
63+
public INTERNAL toInternal() {
64+
return internalDelegate;
5965
}
6066
}
6167
}

libs/logstash-bridge/src/main/java/org/elasticsearch/logstashbridge/common/SettingsBridge.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,33 @@
1111
import org.elasticsearch.common.settings.Settings;
1212
import org.elasticsearch.logstashbridge.StableBridgeAPI;
1313

14-
public class SettingsBridge extends StableBridgeAPI.Proxy<Settings> {
14+
/**
15+
* An external bridge for {@link Settings}
16+
*/
17+
public class SettingsBridge extends StableBridgeAPI.ProxyInternal<Settings> {
1518

16-
public static SettingsBridge wrap(final Settings delegate) {
19+
public static SettingsBridge fromInternal(final Settings delegate) {
1720
return new SettingsBridge(delegate);
1821
}
1922

2023
public static Builder builder() {
21-
return Builder.wrap(Settings.builder());
24+
return Builder.fromInternal(Settings.builder());
2225
}
2326

2427
public SettingsBridge(final Settings delegate) {
2528
super(delegate);
2629
}
2730

2831
@Override
29-
public Settings unwrap() {
30-
return this.delegate;
32+
public Settings toInternal() {
33+
return this.internalDelegate;
3134
}
3235

33-
public static class Builder extends StableBridgeAPI.Proxy<Settings.Builder> {
34-
static Builder wrap(final Settings.Builder delegate) {
36+
/**
37+
* An external bridge for {@link Settings.Builder} that proxies calls to a real {@link Settings.Builder}
38+
*/
39+
public static class Builder extends StableBridgeAPI.ProxyInternal<Settings.Builder> {
40+
static Builder fromInternal(final Settings.Builder delegate) {
3541
return new Builder(delegate);
3642
}
3743

@@ -40,12 +46,12 @@ private Builder(final Settings.Builder delegate) {
4046
}
4147

4248
public Builder put(final String key, final String value) {
43-
this.delegate.put(key, value);
49+
this.internalDelegate.put(key, value);
4450
return this;
4551
}
4652

4753
public SettingsBridge build() {
48-
return new SettingsBridge(this.delegate.build());
54+
return new SettingsBridge(this.internalDelegate.build());
4955
}
5056
}
5157
}

libs/logstash-bridge/src/main/java/org/elasticsearch/logstashbridge/core/IOUtilsBridge.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
import java.io.Closeable;
1414

15+
/**
16+
* An external bridge for {@link IOUtils}
17+
*/
1518
public class IOUtilsBridge {
1619
public static void closeWhileHandlingException(final Iterable<? extends Closeable> objects) {
1720
IOUtils.closeWhileHandlingException(objects);

libs/logstash-bridge/src/main/java/org/elasticsearch/logstashbridge/env/EnvironmentBridge.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@
1414

1515
import java.nio.file.Path;
1616

17-
public class EnvironmentBridge extends StableBridgeAPI.Proxy<Environment> {
18-
public static EnvironmentBridge wrap(final Environment delegate) {
17+
/**
18+
* An external bridge for {@link Environment}
19+
*/
20+
public class EnvironmentBridge extends StableBridgeAPI.ProxyInternal<Environment> {
21+
public static EnvironmentBridge fromInternal(final Environment delegate) {
1922
return new EnvironmentBridge(delegate);
2023
}
2124

2225
public EnvironmentBridge(final SettingsBridge settingsBridge, final Path configPath) {
23-
this(new Environment(settingsBridge.unwrap(), configPath));
26+
this(new Environment(settingsBridge.toInternal(), configPath));
2427
}
2528

2629
private EnvironmentBridge(final Environment delegate) {
2730
super(delegate);
2831
}
2932

3033
@Override
31-
public Environment unwrap() {
32-
return this.delegate;
34+
public Environment toInternal() {
35+
return this.internalDelegate;
3336
}
3437
}

libs/logstash-bridge/src/main/java/org/elasticsearch/logstashbridge/ingest/ConfigurationUtilsBridge.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
import java.util.Map;
1616

17+
/**
18+
* An external bridge for {@link ConfigurationUtils}
19+
*/
1720
public class ConfigurationUtilsBridge {
1821
public static TemplateScriptBridge.Factory compileTemplate(
1922
final String processorType,
@@ -23,7 +26,7 @@ public static TemplateScriptBridge.Factory compileTemplate(
2326
final ScriptServiceBridge scriptServiceBridge
2427
) {
2528
return new TemplateScriptBridge.Factory(
26-
ConfigurationUtils.compileTemplate(processorType, processorTag, propertyName, propertyValue, scriptServiceBridge.unwrap())
29+
ConfigurationUtils.compileTemplate(processorType, processorTag, propertyName, propertyValue, scriptServiceBridge.toInternal())
2730
);
2831
}
2932

libs/logstash-bridge/src/main/java/org/elasticsearch/logstashbridge/ingest/IngestDocumentBridge.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@
1818
import java.util.Set;
1919
import java.util.function.BiConsumer;
2020

21-
public class IngestDocumentBridge extends StableBridgeAPI.Proxy<IngestDocument> {
21+
/**
22+
* An external bridge for {@link IngestDocument} that proxies calls through a real {@link IngestDocument}
23+
*/
24+
public class IngestDocumentBridge extends StableBridgeAPI.ProxyInternal<IngestDocument> {
25+
26+
public static final class Constants {
27+
public static final String METADATA_VERSION_FIELD_NAME = IngestDocument.Metadata.VERSION.getFieldName();
28+
29+
private Constants() {}
30+
}
2231

23-
public static IngestDocumentBridge wrap(final IngestDocument ingestDocument) {
32+
public static IngestDocumentBridge fromInternalNullable(final IngestDocument ingestDocument) {
2433
if (ingestDocument == null) {
2534
return null;
2635
}
@@ -36,55 +45,56 @@ private IngestDocumentBridge(IngestDocument inner) {
3645
}
3746

3847
public MetadataBridge getMetadata() {
39-
return new MetadataBridge(delegate.getMetadata());
48+
return new MetadataBridge(internalDelegate.getMetadata());
4049
}
4150

4251
public Map<String, Object> getSource() {
43-
return delegate.getSource();
52+
return internalDelegate.getSource();
4453
}
4554

4655
public boolean updateIndexHistory(final String index) {
47-
return delegate.updateIndexHistory(index);
56+
return internalDelegate.updateIndexHistory(index);
4857
}
4958

5059
public Set<String> getIndexHistory() {
51-
return Set.copyOf(delegate.getIndexHistory());
60+
return Set.copyOf(internalDelegate.getIndexHistory());
5261
}
5362

5463
public boolean isReroute() {
55-
return LogstashInternalBridge.isReroute(delegate);
64+
return LogstashInternalBridge.isReroute(internalDelegate);
5665
}
5766

5867
public void resetReroute() {
59-
LogstashInternalBridge.resetReroute(delegate);
68+
LogstashInternalBridge.resetReroute(internalDelegate);
6069
}
6170

6271
public Map<String, Object> getIngestMetadata() {
63-
return Map.copyOf(delegate.getIngestMetadata());
72+
return internalDelegate.getIngestMetadata();
6473
}
6574

6675
public <T> T getFieldValue(final String fieldName, final Class<T> type) {
67-
return delegate.getFieldValue(fieldName, type);
76+
return internalDelegate.getFieldValue(fieldName, type);
6877
}
6978

7079
public <T> T getFieldValue(final String fieldName, final Class<T> type, final boolean ignoreMissing) {
71-
return delegate.getFieldValue(fieldName, type, ignoreMissing);
80+
return internalDelegate.getFieldValue(fieldName, type, ignoreMissing);
7281
}
7382

7483
public String renderTemplate(final TemplateScriptBridge.Factory templateScriptFactory) {
75-
return delegate.renderTemplate(templateScriptFactory.unwrap());
84+
return internalDelegate.renderTemplate(templateScriptFactory.toInternal());
7685
}
7786

7887
public void setFieldValue(final String path, final Object value) {
79-
delegate.setFieldValue(path, value);
88+
internalDelegate.setFieldValue(path, value);
8089
}
8190

8291
public void removeField(final String path) {
83-
delegate.removeField(path);
92+
internalDelegate.removeField(path);
8493
}
8594

86-
// public void executePipeline(Pipeline pipeline, BiConsumer<IngestDocument, Exception> handler) {
8795
public void executePipeline(final PipelineBridge pipelineBridge, final BiConsumer<IngestDocumentBridge, Exception> handler) {
88-
this.delegate.executePipeline(pipelineBridge.unwrap(), (unwrapped, e) -> handler.accept(IngestDocumentBridge.wrap(unwrapped), e));
96+
this.internalDelegate.executePipeline(pipelineBridge.toInternal(), (ingestDocument, e) -> {
97+
handler.accept(IngestDocumentBridge.fromInternalNullable(ingestDocument), e);
98+
});
8999
}
90100
}

libs/logstash-bridge/src/main/java/org/elasticsearch/logstashbridge/ingest/PipelineBridge.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
import java.util.Map;
1717
import java.util.function.BiConsumer;
1818

19-
public class PipelineBridge extends StableBridgeAPI.Proxy<Pipeline> {
20-
public static PipelineBridge wrap(final Pipeline pipeline) {
19+
/**
20+
* An external bridge for {@link Pipeline}
21+
*/
22+
public class PipelineBridge extends StableBridgeAPI.ProxyInternal<Pipeline> {
23+
public static PipelineBridge fromInternal(final Pipeline pipeline) {
2124
return new PipelineBridge(pipeline);
2225
}
2326

@@ -28,12 +31,12 @@ public static PipelineBridge create(
2831
Map<String, ProcessorBridge.Factory> processorFactories,
2932
ScriptServiceBridge scriptServiceBridge
3033
) throws Exception {
31-
return wrap(
34+
return fromInternal(
3235
Pipeline.create(
3336
id,
3437
config,
35-
StableBridgeAPI.unwrap(processorFactories),
36-
StableBridgeAPI.unwrapNullable(scriptServiceBridge),
38+
StableBridgeAPI.toInternal(processorFactories),
39+
StableBridgeAPI.toInternalNullable(scriptServiceBridge),
3740
null
3841
)
3942
);
@@ -44,13 +47,13 @@ public PipelineBridge(final Pipeline delegate) {
4447
}
4548

4649
public String getId() {
47-
return delegate.getId();
50+
return internalDelegate.getId();
4851
}
4952

5053
public void execute(final IngestDocumentBridge ingestDocumentBridge, final BiConsumer<IngestDocumentBridge, Exception> handler) {
51-
this.delegate.execute(
52-
StableBridgeAPI.unwrapNullable(ingestDocumentBridge),
53-
(unwrapped, e) -> handler.accept(IngestDocumentBridge.wrap(unwrapped), e)
54+
this.internalDelegate.execute(
55+
StableBridgeAPI.toInternalNullable(ingestDocumentBridge),
56+
(ingestDocument, e) -> handler.accept(IngestDocumentBridge.fromInternalNullable(ingestDocument), e)
5457
);
5558
}
5659
}

0 commit comments

Comments
 (0)