-
Notifications
You must be signed in to change notification settings - Fork 0
align bridge to yaauie/elasticsearch@94d58d47cd #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| LOGSTASH_PATH=../../logstash | ||
| ELASTICSEARCH_REPO=mashhurs/elasticsearch | ||
| ELASTICSEARCH_TREEISH=logstash-bridge-geoip-interfaces | ||
| ELASTICSEARCH_REPO=yaauie/elasticsearch | ||
| ELASTICSEARCH_TREEISH=rye-bridge-refinement-progress |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| rootProject.name = 'logstash-filter-elastic_integration' | ||
| rootProject.name = 'logstash-filter-elastic_integration' |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,12 @@ | |
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.elasticsearch.logstashbridge.core.CheckedBiFunctionBridge; | ||
| import org.elasticsearch.logstashbridge.geoip.IpDatabaseBridge; | ||
| import org.elasticsearch.logstashbridge.geoip.MaxMindDbBridge; | ||
| import org.elasticsearch.ingest.geoip.shaded.com.maxmind.db.CHMCache; | ||
| import org.elasticsearch.ingest.geoip.shaded.com.maxmind.db.NoCache; | ||
| import org.elasticsearch.ingest.geoip.shaded.com.maxmind.db.NodeCache; | ||
| import org.elasticsearch.ingest.geoip.shaded.com.maxmind.db.Reader; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this was my confusion that we fully move to the ES logstash-bridge w/o embedding the JARs but after analyzing the risk of conflict, as we took offline discussion, our original approach is the right one. This indicates we DON'T NEED maxmind dependencies in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will remove these dependencies, just noting here to remind myself while reviewing. |
||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
|
|
@@ -19,14 +23,14 @@ | |
| public class IpDatabaseAdapter extends IpDatabaseBridge.AbstractExternal { | ||
| private static final Logger LOGGER = LogManager.getLogger(IpDatabaseAdapter.class); | ||
|
|
||
| private final MaxMindDbBridge.Reader databaseReader; | ||
| private final Reader databaseReader; | ||
| private final String databaseType; | ||
|
|
||
| private volatile boolean isReaderClosed = false; | ||
|
|
||
| public IpDatabaseAdapter(final MaxMindDbBridge.Reader databaseReader) { | ||
| public IpDatabaseAdapter(final Reader databaseReader) { | ||
| this.databaseReader = databaseReader; | ||
| this.databaseType = databaseReader.getDatabaseType(); | ||
| this.databaseType = databaseReader.getMetadata().getDatabaseType(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -35,8 +39,19 @@ public String getDatabaseType() { | |
| } | ||
|
|
||
| @Override | ||
| public MaxMindDbBridge.Reader getDatabaseReader() throws IOException { | ||
| return this.databaseReader; | ||
| public <RESPONSE> RESPONSE getResponse(String ipAddress, CheckedBiFunctionBridge<Reader, String, RESPONSE, Exception> responseProvider) { | ||
| try { | ||
| return responseProvider.apply(this.databaseReader, ipAddress); | ||
| } catch (Exception e) { | ||
| throw convertToRuntime(e); | ||
| } | ||
| } | ||
|
|
||
| private static RuntimeException convertToRuntime(final Exception e) { | ||
| if (e instanceof RuntimeException re) { | ||
| return re; | ||
| } | ||
| return new RuntimeException(e); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -58,25 +73,25 @@ boolean isReaderClosed() { | |
| } | ||
|
|
||
| public static IpDatabaseAdapter defaultForPath(final Path database) throws IOException { | ||
| return new Builder(database.toFile()).setCache(MaxMindDbBridge.NodeCache.get(10_000)).build(); | ||
| return new Builder(database.toFile()).setCache(new CHMCache(10_000)).build(); | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private File databasePath; | ||
| private MaxMindDbBridge.NodeCache nodeCache; | ||
| private NodeCache nodeCache; | ||
|
|
||
| public Builder(final File databasePath) { | ||
| this.databasePath = databasePath; | ||
| } | ||
|
|
||
| public Builder setCache(final MaxMindDbBridge.NodeCache nodeCache) { | ||
| public Builder setCache(final NodeCache nodeCache) { | ||
| this.nodeCache = nodeCache; | ||
| return this; | ||
| } | ||
|
|
||
| public IpDatabaseAdapter build() throws IOException { | ||
| final MaxMindDbBridge.NodeCache nodeCache = Optional.ofNullable(this.nodeCache).orElseGet(MaxMindDbBridge.NodeCache::getInstance); | ||
| final MaxMindDbBridge.Reader databaseReader = new MaxMindDbBridge.Reader(this.databasePath, nodeCache); | ||
| final NodeCache nodeCache = Optional.ofNullable(this.nodeCache).orElseGet(NoCache::getInstance); | ||
| final Reader databaseReader = new Reader(this.databasePath, nodeCache); | ||
| return new IpDatabaseAdapter(databaseReader); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️