Skip to content
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

Merged
merged 3 commits into from
Jan 17, 2024

Conversation

asifsmohammed
Copy link
Collaborator

@asifsmohammed asifsmohammed commented Jan 10, 2024

Description

  • Adds geoip_service extension which is used to configure maxmind
  • Adds geoip plugin to build

This 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

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

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.

Signed-off-by: Asif Sohail Mohammed <[email protected]>
Copy link
Member

@dlvenable dlvenable left a 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();
Copy link
Member

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();

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Member

@dlvenable dlvenable left a 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.")
Copy link
Member

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)

Copy link
Collaborator Author

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() {
Copy link
Member

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.?

Copy link
Collaborator Author

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);
Copy link
Member

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 {
Copy link
Member

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.

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
Copy link
Member

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?

Copy link
Collaborator Author

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

Copy link
Member

@dlvenable dlvenable left a 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
Copy link
Member

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?

Copy link
Member

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.

Copy link
Collaborator Author

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]>
Copy link
Collaborator

@chenqi0805 chenqi0805 left a 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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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

Copy link
Collaborator Author

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

@asifsmohammed asifsmohammed merged commit 29b0630 into opensearch-project:main Jan 17, 2024
72 of 74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GeoIP extensions in Data Prepper Config
3 participants