Skip to content

Commit 09c332c

Browse files
committed
Use logstash-bridge GeoIP interfaces.
1 parent a6491b9 commit 09c332c

File tree

8 files changed

+29
-65
lines changed

8 files changed

+29
-65
lines changed

build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ task buildElasticsearchLocalDistro(dependsOn: unzipDownloadedElasticsearchSource
221221
errorOutput = funneler.funnelInstance
222222
}
223223

224-
def esSource = "${buildDir}/elasticsearch-source/"
224+
def esSource = "/Users/mashhur/Dev/elastic/elasticsearch/"
225225
def esBuildDir = "${esSource}/build"
226226

227227
inputs.dir esSource
@@ -261,6 +261,7 @@ task buildElasticsearchLogstashBridge(type: Exec) {
261261
description "builds logstash-bridge lib module"
262262

263263
dependsOn buildElasticsearchLocalDistro
264+
mustRunAfter buildElasticsearchLocalDistro
264265

265266
def logFile = project.file("${buildDir}/logstash-bridge-build.log")
266267
doFirst {
@@ -269,7 +270,7 @@ task buildElasticsearchLogstashBridge(type: Exec) {
269270
errorOutput = funneler.funnelInstance
270271
}
271272

272-
def esSource = "${buildDir}/elasticsearch-source/"
273+
def esSource = "/Users/mashhur/Dev/elastic/elasticsearch/"
273274
def esBuildDir = "${esSource}/build"
274275

275276
inputs.dir esSource
@@ -358,14 +359,14 @@ task shadeElasticsearchLogstashBridge(type: com.github.jengelman.gradle.plugins.
358359
description "Shades the Elasticsearch logstash-bridge jar"
359360

360361
dependsOn buildElasticsearchLogstashBridge
361-
362-
from("${buildDir}/elasticsearch-source/libs/logstash-bridge/build/distributions") {
362+
363+
from("/Users/mashhur/Dev/elastic/elasticsearch/libs/logstash-bridge/build/distributions") {
363364
include "elasticsearch-logstash-bridge-*.jar"
364365
}
365-
366+
366367
archiveFileName = "elasticsearch-logstash-bridge-shaded.jar"
367368
destinationDirectory = file("${buildDir}/shaded")
368-
369+
369370
exclude '**/module-info.class'
370371
}
371372

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
LOGSTASH_PATH=../../logstash
22
ELASTICSEARCH_REPO=mashhurs/elasticsearch
3-
ELASTICSEARCH_TREEISH=move-to-bridge-stable-api-investigation
3+
ELASTICSEARCH_TREEISH=logstash-bridge-geoip-interfaces

src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/ConstantIpDatabaseHolder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package co.elastic.logstash.filters.elasticintegration.geoip;
22

3-
import org.elasticsearch.ingest.geoip.IpDatabase;
4-
53
import java.io.Closeable;
64
import java.io.IOException;
75
import java.util.Objects;

src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/GeoIpProcessorFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
package co.elastic.logstash.filters.elasticintegration.geoip;
88

9-
import org.elasticsearch.ingest.geoip.GeoIpProcessor;
109
import org.elasticsearch.logstashbridge.ingest.ProcessorBridge;
10+
import org.elasticsearch.logstashbridge.geoip.GeoIpProcessorBridge;
1111

1212
import java.util.Map;
1313
import java.util.stream.Collectors;
@@ -24,7 +24,8 @@ public ProcessorBridge create(Map<String, ProcessorBridge.Factory> processorFact
2424
String tag,
2525
String description,
2626
Map<String, Object> config) throws Exception {
27-
return ProcessorBridge.fromInternal(new GeoIpProcessor.Factory("geoip", this.ipDatabaseProvider)
27+
return ProcessorBridge.fromInternal(new GeoIpProcessorBridge.Factory("geoip", this.ipDatabaseProvider.toInternal())
28+
.toInternal()
2829
.create(processorFactories.entrySet()
2930
.stream()
3031
.collect(Collectors.toMap(Map.Entry::getKey,e -> e.getValue().toInternal())),

src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/IpDatabaseAdapter.java

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,32 @@
88

99
import org.apache.logging.log4j.LogManager;
1010
import org.apache.logging.log4j.Logger;
11-
import org.elasticsearch.ExceptionsHelper;
12-
import org.elasticsearch.common.CheckedBiFunction;
13-
import org.elasticsearch.ingest.geoip.IpDatabase;
14-
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.db.CHMCache;
15-
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.db.NoCache;
16-
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.db.NodeCache;
17-
import org.elasticsearch.ingest.geoip.shaded.com.maxmind.db.Reader;
11+
import org.elasticsearch.logstashbridge.geoip.IpDatabaseBridge;
12+
import org.elasticsearch.logstashbridge.geoip.MaxMindDbBridge;
1813

1914
import java.io.File;
2015
import java.io.IOException;
2116
import java.nio.file.Path;
2217
import java.util.Optional;
2318

24-
public class IpDatabaseAdapter implements IpDatabase {
19+
public class IpDatabaseAdapter implements IpDatabaseBridge {
2520
private static final Logger LOGGER = LogManager.getLogger(IpDatabaseAdapter.class);
2621

27-
private final Reader databaseReader;
22+
private final MaxMindDbBridge.Reader databaseReader;
2823
private final String databaseType;
2924

3025
private volatile boolean isReaderClosed = false;
3126

32-
public IpDatabaseAdapter(final Reader databaseReader) {
27+
public IpDatabaseAdapter(final MaxMindDbBridge.Reader databaseReader) {
3328
this.databaseReader = databaseReader;
34-
this.databaseType = databaseReader.getMetadata().getDatabaseType();
29+
this.databaseType = databaseReader.getDatabaseType();
3530
}
3631

3732
@Override
3833
public String getDatabaseType() {
3934
return this.databaseType;
4035
}
4136

42-
@Override
43-
public <RESPONSE> RESPONSE getResponse(String ipAddress, CheckedBiFunction<Reader, String, RESPONSE, Exception> responseProvider) {
44-
try {
45-
return responseProvider.apply(this.databaseReader, ipAddress);
46-
} catch (Exception e) {
47-
throw ExceptionsHelper.convertToRuntime(e);
48-
}
49-
}
50-
51-
@Override
52-
public void close() throws IOException {
53-
// no-op
54-
// IpDatabase is an AutoCloseable class which is not our intention to close after try-with-resource operations.
55-
// use closeReader() instead
56-
}
57-
5837
public void closeReader() throws IOException {
5938
LOGGER.debug("Closing the database adapter");
6039
this.databaseReader.close();
@@ -67,25 +46,25 @@ boolean isReaderClosed() {
6746
}
6847

6948
public static IpDatabaseAdapter defaultForPath(final Path database) throws IOException {
70-
return new Builder(database.toFile()).setCache(new CHMCache(10_000)).build();
49+
return new Builder(database.toFile()).setCache(MaxMindDbBridge.NodeCache.get(10_000)).build();
7150
}
7251

7352
public static class Builder {
7453
private File databasePath;
75-
private NodeCache nodeCache;
54+
private MaxMindDbBridge.NodeCache nodeCache;
7655

77-
public Builder(File databasePath) {
56+
public Builder(final File databasePath) {
7857
this.databasePath = databasePath;
7958
}
8059

81-
public Builder setCache(final NodeCache nodeCache) {
60+
public Builder setCache(final MaxMindDbBridge.NodeCache nodeCache) {
8261
this.nodeCache = nodeCache;
8362
return this;
8463
}
8564

8665
public IpDatabaseAdapter build() throws IOException {
87-
final NodeCache nodeCache = Optional.ofNullable(this.nodeCache).orElseGet(NoCache::getInstance);
88-
final Reader databaseReader = new Reader(this.databasePath, nodeCache);
66+
final MaxMindDbBridge.NodeCache nodeCache = Optional.ofNullable(this.nodeCache).orElseGet(MaxMindDbBridge.NodeCache::getInstance);
67+
final MaxMindDbBridge.Reader databaseReader = new MaxMindDbBridge.Reader(this.databasePath, nodeCache);
8968
return new IpDatabaseAdapter(databaseReader);
9069
}
9170
}

src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/IpDatabaseHolder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package co.elastic.logstash.filters.elasticintegration.geoip;
22

3-
import org.elasticsearch.ingest.geoip.IpDatabase;
4-
53
interface IpDatabaseHolder {
64
boolean isValid();
75

src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/IpDatabaseProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import org.apache.logging.log4j.LogManager;
1010
import org.apache.logging.log4j.Logger;
11-
import org.elasticsearch.cluster.metadata.ProjectId;
12-
import org.elasticsearch.ingest.geoip.IpDatabase;
1311
import org.elasticsearch.logstashbridge.core.IOUtilsBridge;
12+
import org.elasticsearch.logstashbridge.geoip.IpDatabaseBridge;
13+
import org.elasticsearch.logstashbridge.geoip.IpDatabaseProviderBridge;
1414

1515
import java.io.Closeable;
1616
import java.io.File;
@@ -23,24 +23,24 @@
2323
import java.util.Map;
2424
import java.util.Objects;
2525

26-
public class IpDatabaseProvider implements org.elasticsearch.ingest.geoip.IpDatabaseProvider, Closeable {
26+
public class IpDatabaseProvider extends IpDatabaseProviderBridge.AbstractExternal implements Closeable {
2727

2828
private static final Logger LOGGER = LogManager.getLogger(IpDatabaseProvider.class);
2929

3030
private final Map<String, IpDatabaseHolder> databaseMap;
3131

32-
IpDatabaseProvider(Map<String, IpDatabaseHolder> databaseMap) {
32+
public IpDatabaseProvider(Map<String, IpDatabaseHolder> databaseMap) {
3333
this.databaseMap = Map.copyOf(databaseMap);
3434
}
3535

3636
@Override
37-
public Boolean isValid(ProjectId projectId, String databaseIdentifierFileName) {
37+
public Boolean isValid(String databaseIdentifierFileName) {
3838
final IpDatabaseHolder holder = getDatabaseHolder(databaseIdentifierFileName);
3939
return Objects.nonNull(holder) && holder.isValid();
4040
}
4141

4242
@Override
43-
public IpDatabase getDatabase(ProjectId projectId, String databaseIdentifierFileName) {
43+
public IpDatabaseBridge getDatabase(String databaseIdentifierFileName) {
4444
final IpDatabaseHolder holder = getDatabaseHolder(databaseIdentifierFileName);
4545
if (Objects.isNull(holder)) {
4646
return null;

src/main/java/co/elastic/logstash/filters/elasticintegration/geoip/ValidatableIpDatabase.java

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

0 commit comments

Comments
 (0)