-
Notifications
You must be signed in to change notification settings - Fork 213
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
Add geoip service extension #3944
Add geoip service extension #3944
Conversation
Signed-off-by: Asif Sohail Mohammed <[email protected]>
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.
I have one initial comment. I'll try to look deeper a little later.
super(pluginSetting); | ||
this.geoIPProcessorConfig = geoCodingProcessorConfig; | ||
this.tempPath = System.getProperty("java.io.tmpdir")+ File.separator + TEMP_PATH_FOLDER; | ||
geoIPProcessorService = new GeoIPProcessorService(geoCodingProcessorConfig,tempPath); | ||
tagsOnSourceNotFoundFailure = geoCodingProcessorConfig.getTagsOnSourceNotFoundFailure(); | ||
this.geoIpProcessingMatchCounter = pluginMetrics.counter(GEO_IP_PROCESSING_MATCH); | ||
this.geoIpProcessingMismatchCounter = pluginMetrics.counter(GEO_IP_PROCESSING_MISMATCH); | ||
// TODO: use this config and clean up MaxMind service config from pipeline.yaml | ||
geoIpServiceConfig = geoIpConfigSupplier.getGeoIpServiceConfig(); |
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.
I think that this code should want to get a GeoIpService
. That is, we can have one underlying object for handling GeoIP requests.
By doing that, we'd be able to share the underlying database and structures across multiple instances of GeoIPProcessor
. This can reduce the memory load in Data Prepper.
So, I think we'd want to pass into the constructor:
final GeoIpServiceProvider geoIpServiceProvider
And then call:
geoIpService = geoIpServiceProvider.getService();
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.
Yeah, I like the suggestion. This way only one GeoIP service is created and updated once per node. I will implement in a different PR, I will expose a getGeoIpService
in the GeoIpConfigSupplier
interface and it will create the service using config.
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.
I'm ok with creating in a new PR. But, if you go that route, I think we will want to remove the code that exposes the config outside of the extension. I think it will be unnecessary.
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.
This looks good. Thanks for adding this extension! I have a few small comments.
By the way, the tests look good. They are a good size and very readable.
// This default constructor is used if maxmind is not configured | ||
} | ||
|
||
@AssertTrue(message = "database_refresh_interval should be between 1 and 30 days.") |
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.
You can replace this with the following annotations on getDatabaseRefreshInterval()
.
@DurationMin(days = 0)
@DurationMax(days = 30)
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.
Thanks for this, I looked if there is any annotations for duration but could not find it.
* @return The MaxMind database paths | ||
* @since 2.7 | ||
*/ | ||
public List<String> getDatabasePaths() { |
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.
Why do we have multiple paths? Is this to include the country, ASN, etc.?
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.
Yeah, for multiple databases city, country, ASN. I will add an annotation so it can have max size of 3.
assertThat(dataPrepperConfiguration.getPipelineExtensions(), CoreMatchers.notNullValue()); | ||
|
||
final Map<String, Object> geoipServiceConfigMap = (Map<String, Object>) dataPrepperConfiguration.getPipelineExtensions().getExtensionMap().get("geoip_service"); | ||
System.out.println(geoipServiceConfigMap); |
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.
Please do not use println
.
You can use a logger in testing if you'd really like.
assertThat(maxMindConfig.getDatabasePaths().size(), equalTo(3)); | ||
} | ||
|
||
private void reflectivelySetField(final MaxMindConfig maxMindConfig, final String fieldName, final Object value) throws NoSuchFieldException, IllegalAccessException { |
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.
Let's use the common implementation.
Line 29 in 6648d9f
public static <T> void setField(final Class<T> configurationClass, final Object configurationObject, |
private Duration databaseRefreshInterval = DEFAULT_DATABASE_REFRESH_INTERVAL; | ||
@JsonProperty("cache_size") | ||
@Min(1) | ||
//TODO: Add a Max limit on cache size |
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.
Do you have any thoughts on the maximum cache size? How big is each entry?
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.
I don't have any right now, but it's something to think about as it can abused if max limit is not added
Signed-off-by: Asif Sohail Mohammed <[email protected]>
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.
Thanks @asifsmohammed . This looks good. Please correct the license header and then I'll be good to approve.
@@ -1,9 +1,9 @@ | |||
/* | |||
* Copyright OpenSearch Contributors | |||
* SPDX-License-Identifier: Apache-2.0 | |||
* PDX-License-Identifier: Apache-2.0 |
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.
This should be SPDX
. See: https://github.com/opensearch-project/data-prepper/blob/main/CONTRIBUTING.md#java-gradlegroovy
Maybe this was a replace-all error?
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.
This change was applied to a few files.
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.
It's just a typo in my Intellij copyright setup, fixed it.
Signed-off-by: Asif Sohail Mohammed <[email protected]>
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.
LGTM. Assuming this missing pieces will be in a separate PR.
//TODO: Add a Max limit on cache size | ||
private int cacheSize = DEFAULT_CACHE_SIZE; | ||
|
||
//TODO: Add a destination path to store database files |
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.
Not following this comment, are you intended for storing files in database_paths into different paths?
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.
Yeah, right now it's stored in a temp folder. But it should be configured
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class DefaultGeoIpConfigSupplierTest { |
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.
I suppose this test needs to be extended in later PR
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.
Yes, I will be adding tests to this
29b0630
into
opensearch-project:main
Description
geoip_service
extension which is used to configure maxmindThis PR does not remove existing config, I will make a separate PR to remove old config. It might break a lot of code.
Issues Resolved
Resolves #3941
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.