-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make GeoIpProcessor backing database instance pluggable. (#93285)
Introduces two new interfaces: GeoIpDatabase and GeoIpDatabaseProvider. GeoIpDatabaseProvider acts as a generic factory interface for GeoIpDatabase instances. This allows for specifying how database instances are obtained to the processor. GeoIpDatabase encompasses the API footprint for performing GeoIp lookups against a maxmind database. --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
7f7cf30
commit c143caf
Showing
11 changed files
with
306 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 93285 | ||
summary: Make `GeoIpProcessor` backing database instance pluggable | ||
area: Ingest Node | ||
type: enhancement | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.ingest.geoip; | ||
|
||
import com.maxmind.geoip2.model.AsnResponse; | ||
import com.maxmind.geoip2.model.CityResponse; | ||
import com.maxmind.geoip2.model.CountryResponse; | ||
|
||
import org.elasticsearch.core.Nullable; | ||
|
||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
|
||
/** | ||
* Provides a uniform interface for interacting with various GeoIP databases. | ||
*/ | ||
public interface GeoIpDatabase { | ||
|
||
/** | ||
* @return the database type as it is detailed in the database file metadata | ||
* @throws IOException if the database file could not be read or the data could not be accessed | ||
*/ | ||
String getDatabaseType() throws IOException; | ||
|
||
/** | ||
* @param ipAddress the IP address to look up | ||
* @return a response containing the city data for the given address if it exists, or <code>null</code> if it could not be found | ||
* @throws UnsupportedOperationException may be thrown if the implementation does not support retrieving city data | ||
*/ | ||
@Nullable | ||
CityResponse getCity(InetAddress ipAddress); | ||
|
||
/** | ||
* @param ipAddress the IP address to look up | ||
* @return a response containing the country data for the given address if it exists, or <code>null</code> if it could not be found | ||
* @throws UnsupportedOperationException may be thrown if the implementation does not support retrieving country data | ||
*/ | ||
@Nullable | ||
CountryResponse getCountry(InetAddress ipAddress); | ||
|
||
/** | ||
* @param ipAddress the IP address to look up | ||
* @return a response containing the Autonomous System Number for the given address if it exists, or <code>null</code> if it could not | ||
* be found | ||
* @throws UnsupportedOperationException may be thrown if the implementation does not support retrieving ASN data | ||
*/ | ||
@Nullable | ||
AsnResponse getAsn(InetAddress ipAddress); | ||
|
||
/** | ||
* Releases the current database object. Called after processing a single document. Databases should be closed or returned to a | ||
* resource pool. No further interactions should be expected. | ||
* @throws IOException if the implementation encounters any problem while cleaning up | ||
*/ | ||
void release() throws IOException; | ||
} |
34 changes: 34 additions & 0 deletions
34
modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDatabaseProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.ingest.geoip; | ||
|
||
/** | ||
* Provides construction and initialization logic for {@link GeoIpDatabase} instances. | ||
*/ | ||
public interface GeoIpDatabaseProvider { | ||
|
||
/** | ||
* Determines if the given database name corresponds to an expired database. Expired databases will not be loaded. | ||
* <br/><br/> | ||
* Verifying database expiration is left to each provider implementation to determine. A return value of <code>false</code> does not | ||
* preclude the possibility of a provider returning <code>true</code> in the future. | ||
* | ||
* @param name the name of the database to provide. | ||
* @return <code>false</code> IFF the requested database file is expired, | ||
* <code>true</code> for all other cases (including unknown file name, file missing, wrong database type, etc). | ||
*/ | ||
Boolean isValid(String name); | ||
|
||
/** | ||
* @param name the name of the database to provide. Default database names that should always be supported are listed in | ||
* {@link IngestGeoIpPlugin#DEFAULT_DATABASE_FILENAMES}. | ||
* @return a ready-to-use database instance, or <code>null</code> if no database could be loaded. | ||
*/ | ||
GeoIpDatabase getDatabase(String name); | ||
} |
Oops, something went wrong.