-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add geoip service extension Signed-off-by: Asif Sohail Mohammed <nsifmoh@amazon.com> --------- Signed-off-by: Asif Sohail Mohammed <nsifmoh@amazon.com>
- Loading branch information
1 parent
f21937a
commit 29b0630
Showing
21 changed files
with
558 additions
and
49 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
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
22 changes: 22 additions & 0 deletions
22
...va/org/opensearch/dataprepper/plugins/processor/extension/DefaultGeoIpConfigSupplier.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,22 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor.extension; | ||
|
||
import org.opensearch.dataprepper.plugins.processor.GeoIPProcessorService; | ||
|
||
public class DefaultGeoIpConfigSupplier implements GeoIpConfigSupplier { | ||
private final GeoIpServiceConfig geoIpServiceConfig; | ||
|
||
public DefaultGeoIpConfigSupplier(final GeoIpServiceConfig geoIpServiceConfig) { | ||
this.geoIpServiceConfig = geoIpServiceConfig; | ||
} | ||
|
||
@Override | ||
public GeoIPProcessorService getGeoIPProcessorService() { | ||
//TODO: use GeoIpServiceConfig and return GeoIPProcessorService | ||
return null; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ain/java/org/opensearch/dataprepper/plugins/processor/extension/GeoIpConfigExtension.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,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor.extension; | ||
|
||
import org.opensearch.dataprepper.model.annotations.DataPrepperExtensionPlugin; | ||
import org.opensearch.dataprepper.model.annotations.DataPrepperPluginConstructor; | ||
import org.opensearch.dataprepper.model.plugin.ExtensionPlugin; | ||
import org.opensearch.dataprepper.model.plugin.ExtensionPoints; | ||
|
||
@DataPrepperExtensionPlugin(modelType = GeoIpServiceConfig.class, rootKeyJsonPath = "/geoip_service") | ||
public class GeoIpConfigExtension implements ExtensionPlugin { | ||
private final DefaultGeoIpConfigSupplier defaultGeoIpConfigSupplier; | ||
|
||
@DataPrepperPluginConstructor | ||
public GeoIpConfigExtension(final GeoIpServiceConfig geoIpServiceConfig) { | ||
this.defaultGeoIpConfigSupplier = new DefaultGeoIpConfigSupplier(geoIpServiceConfig != null ? geoIpServiceConfig : new GeoIpServiceConfig()); | ||
} | ||
|
||
@Override | ||
public void apply(final ExtensionPoints extensionPoints) { | ||
extensionPoints.addExtensionProvider(new GeoIpConfigProvider(this.defaultGeoIpConfigSupplier)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...main/java/org/opensearch/dataprepper/plugins/processor/extension/GeoIpConfigProvider.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,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor.extension; | ||
|
||
import org.opensearch.dataprepper.model.plugin.ExtensionProvider; | ||
|
||
import java.util.Optional; | ||
|
||
public class GeoIpConfigProvider implements ExtensionProvider<GeoIpConfigSupplier> { | ||
private final GeoIpConfigSupplier geoIpConfigSupplier; | ||
|
||
public GeoIpConfigProvider(final GeoIpConfigSupplier geoIpConfigSupplier) { | ||
this.geoIpConfigSupplier = geoIpConfigSupplier; | ||
} | ||
|
||
@Override | ||
public Optional<GeoIpConfigSupplier> provideInstance(Context context) { | ||
return Optional.of(this.geoIpConfigSupplier); | ||
} | ||
|
||
@Override | ||
public Class<GeoIpConfigSupplier> supportedClass() { | ||
return GeoIpConfigSupplier.class; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...main/java/org/opensearch/dataprepper/plugins/processor/extension/GeoIpConfigSupplier.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,22 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor.extension; | ||
|
||
import org.opensearch.dataprepper.plugins.processor.GeoIPProcessorService; | ||
|
||
/** | ||
* Interface for supplying {@link GeoIPProcessorService} to {@link GeoIpConfigExtension} | ||
* | ||
* @since 2.7 | ||
*/ | ||
public interface GeoIpConfigSupplier { | ||
/** | ||
* Returns the {@link GeoIPProcessorService} | ||
* | ||
* @since 2.7 | ||
*/ | ||
GeoIPProcessorService getGeoIPProcessorService(); | ||
} |
31 changes: 31 additions & 0 deletions
31
.../main/java/org/opensearch/dataprepper/plugins/processor/extension/GeoIpServiceConfig.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,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor.extension; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.Valid; | ||
|
||
public class GeoIpServiceConfig { | ||
private static final MaxMindConfig DEFAULT_MAXMIND_CONFIG = new MaxMindConfig(); | ||
|
||
public GeoIpServiceConfig() { | ||
// This default constructor is used if geoip_service is not configured | ||
} | ||
|
||
@JsonProperty("maxmind") | ||
@Valid | ||
private MaxMindConfig maxMindConfig = DEFAULT_MAXMIND_CONFIG; | ||
|
||
/** | ||
* Gets the configuration for MaxMind. | ||
* | ||
* @return The MaxMind configuration | ||
* @since 2.7 | ||
*/ | ||
public MaxMindConfig getMaxMindConfig() { | ||
return maxMindConfig; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...r/src/main/java/org/opensearch/dataprepper/plugins/processor/extension/MaxMindConfig.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,99 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.processor.extension; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.AssertTrue; | ||
import jakarta.validation.constraints.Min; | ||
import org.hibernate.validator.constraints.time.DurationMax; | ||
import org.hibernate.validator.constraints.time.DurationMin; | ||
|
||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MaxMindConfig { | ||
private static final String S3_PREFIX = "s3://"; | ||
|
||
//TODO: Add validations to database paths | ||
//TODO: Make default path to be a public CDN endpoint | ||
private static final List<String> DEFAULT_DATABASE_PATHS = new ArrayList<>(); | ||
private static final Duration DEFAULT_DATABASE_REFRESH_INTERVAL = Duration.ofDays(7); | ||
private static final int DEFAULT_CACHE_SIZE = 4096; | ||
|
||
@JsonProperty("database_paths") | ||
private List<String> databasePaths = DEFAULT_DATABASE_PATHS; | ||
|
||
@JsonProperty("database_refresh_interval") | ||
@DurationMin(days = 1) | ||
@DurationMax(days = 30) | ||
private Duration databaseRefreshInterval = DEFAULT_DATABASE_REFRESH_INTERVAL; | ||
|
||
@JsonProperty("cache_size") | ||
@Min(1) | ||
//TODO: Add a Max limit on cache size | ||
private int cacheSize = DEFAULT_CACHE_SIZE; | ||
|
||
//TODO: Add a destination path to store database files | ||
@JsonProperty("aws") | ||
@Valid | ||
private AwsAuthenticationOptionsConfig awsAuthenticationOptionsConfig; | ||
|
||
public MaxMindConfig() { | ||
// This default constructor is used if maxmind is not configured | ||
} | ||
|
||
@AssertTrue(message = "aws should be configured if any path in database_paths is S3 bucket path.") | ||
boolean isAwsAuthenticationOptionsRequired() { | ||
for (final String databasePath : databasePaths) { | ||
if (databasePath.startsWith(S3_PREFIX)) { | ||
return awsAuthenticationOptionsConfig != null; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Gets the MaxMind database paths | ||
* | ||
* @return The MaxMind database paths | ||
* @since 2.7 | ||
*/ | ||
public List<String> getDatabasePaths() { | ||
return databasePaths; | ||
} | ||
|
||
/** | ||
* Gets the database refresh duration. This loads the database from the paths into memory again in case if there are any updates. | ||
* | ||
* @return The refresh duration | ||
* @since 2.7 | ||
*/ | ||
public Duration getDatabaseRefreshInterval() { | ||
return databaseRefreshInterval; | ||
} | ||
|
||
/** | ||
* Gets the cache size used in CHM cache for MaxMind DatabaseReader. | ||
* | ||
* @return The cache size | ||
* @since 2.7 | ||
*/ | ||
public int getCacheSize() { | ||
return cacheSize; | ||
} | ||
|
||
/** | ||
* Gets the AWS authentication config used for reading from S3 bucket | ||
* | ||
* @return The AWS authentication options | ||
* @since 2.7 | ||
*/ | ||
public AwsAuthenticationOptionsConfig getAwsAuthenticationOptionsConfig() { | ||
return awsAuthenticationOptionsConfig; | ||
} | ||
} |
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
Oops, something went wrong.