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

[Feature] New module geospatial-client for cross-plugin IP enrichment #700

Merged
merged 36 commits into from
Dec 9, 2024

Conversation

andy-k-improving
Copy link
Contributor

Description

This is an implementation ticket which follow the discussion of #698, to create a new Gradle module for other OpenSearch Plugin to import, in order to make an IP enrichment call to GeoSpatial plugin to resolve GeoLocation data with existing data source.

Hight-level code changes:

  • A new Gradle module geospatial-client with appreciate Gradle setting files to publish it as a standalone Jar.
  • A core class ipEnrichmentActionClient which serve as the interface, this is the only way for other Plugin to interact with GeoSpatial's IP enrichment functionality
  • A collection of classes to support the IP enrichment remote call access IpEnrichmentAction, IpEnrichmentRequest and IpEnrichmentResponse
  • IpEnrichementTransportAction class which contain the logic for the IP address lookup and register it during the GeoSpatial's bootstrap time

Non GeoSpatial plugin can now interact with the new functionality like below:

IpEnrichmentActionClient ipClient = new IpEnrichmentActionClient(client.getNodeClient());
        try {
          Map<String, Object> geoLocationData = ipClient.getGeoLocationData("50.68.18.229");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

Related Issues

Resolves #698

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

@andy-k-improving
Copy link
Contributor Author

@heemin32 here is the implementation for #698 as we discussed earlier of the week, would you mind to have a look and advise?
Any comment will be appreciated.

Copy link
Collaborator

@navneet1v navneet1v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked very high level on the code. I like the idea of having a client. But I want to get some consistencies in the code. and I am hoping client to very lightweight.

client/build.gradle Outdated Show resolved Hide resolved
Comment on lines 25 to 26
@ExtendWith(MockitoExtension.class)
class IpEnrichmentActionClientTest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all the tests lets use the same test framework used in plugin rather than using standard Mockito ensure that test framework is same across different modules of the plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the build.gradle to read the Mockito version from the opensearch.build plugin, in this case we will have the same version of Mockito as the main OpenSearch repo.

testImplementation "org.mockito:mockito-core:${versions.mockito}"

Or you mean I should ditch Mockito all together?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was tests in this client should extend from OpenSearchTestCase just like the plugin and not specifically on the mockito version.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with not doing this would be that we first we will not able to test the code with random data and another problem is since we will not have seed whenever we want to reproduce a failure. Not sure why MLCommons didn't do this. This is an acceptable practice in Opensearch Plugins. Plus you will miss out on all the different mocking and testing framework added by Opensearch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my point, this depends on the amount of logic to test.
I agree we should have it to remain the consistency, but for now if we aim to have it as a thin client which has no actual logic inside except the argument validation.
This may be a overkill.

client/build.gradle Show resolved Hide resolved
@andy-k-improving
Copy link
Contributor Author

andy-k-improving commented Nov 26, 2024

@navneet1v I have fixed most of the point except the Mockito, can you have a look on the review?
Thanks,

@andy-k-improving
Copy link
Contributor Author

@heemin32 I updated the code to reflect comments, can you have another look.
Also whats your thought on the cluster upgrade scenario?

@heemin32
Copy link
Collaborator

heemin32 commented Nov 26, 2024

@heemin32 I updated the code to reflect comments, can you have another look. Also whats your thought on the cluster upgrade scenario?

I think, we can add versioning on this serialization/deserialization using OpenSearch version?

@heemin32
Copy link
Collaborator

@Xtansia Could you take a look at this?

@andy-k-improving
Copy link
Contributor Author

andy-k-improving commented Nov 27, 2024

I think, we can add versioning on this serialization/deserialization using OpenSearch vers

Just to align on this, what's the expected behaviour in the case when serializationID doesn't match?
Should we thrown an exception, or we should attempt to parse it as per the serializationID? (Ex: v1.19.0 version of the plugin serializating the object from v1.18.0...etc)

@andy-k-improving
Copy link
Contributor Author

andy-k-improving commented Nov 27, 2024

@heemin32 I updated the code to reflect comments, can you have another look. Also whats your thought on the cluster upgrade scenario?

I think, we can add versioning on this serialization/deserialization using OpenSearch version?

I have updated the code to perform version check, can you have a look and advise?
Thx!

@heemin32
Copy link
Collaborator

Another general comment is if we should implement it as a rest API rather than client? What do you think? @andy-k-improving

@andy-k-improving
Copy link
Contributor Author

Another general comment is if we should implement it as a rest API rather than client? What do you think? @andy-k-improving

We should have it in the long term || as day-2, but I don't think that make sense to bundle it in one PR, as there will be more considerations I foresee (Ex: performance, web-layer security) need to be addressed || discussed ahead of the implementation.
Let me create another issue perhaps?

@andy-k-improving
Copy link
Contributor Author

@heemin32 Also do you foresee any problem to publish the geospatial-client jar?
In local, I see the jar is produced correctly, but not sure will that be the same when publishing to AWS || Maven central.

@heemin32
Copy link
Collaborator

Let me create another issue perhaps?

No need for that. I was considering either this or that, but not both. Thanks.

@heemin32
Copy link
Collaborator

@heemin32 Also do you foresee any problem to publish the geospatial-client jar? In local, I see the jar is produced correctly, but not sure will that be the same when publishing to AWS || Maven central.

I don’t have much expertise on that topic. @ylwu-amzn, is there anything specific we should consider when publishing the client? Asking as ml-common already has done it.

@andy-k-improving
Copy link
Contributor Author

No need for that. I was considering either this or that, but not both. Thanks.

If that is the case, then I rather keep this instead of REST.

Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
Signed-off-by: Andy Kwok <andy.kwok@improving.com>
@andy-k-improving
Copy link
Contributor Author

@heemin32 done.

@heemin32
Copy link
Collaborator

heemin32 commented Dec 6, 2024

@andy-k-improving, thanks for the change. If you don't get response from @navneet1v by next Monday, let me pull in another person to review this PR.

Copy link
Collaborator

@navneet1v navneet1v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment. Overall code looks good to me. There is system.out statement left in the code. Added a comment for that.

Comment on lines 25 to 26
@ExtendWith(MockitoExtension.class)
class IpEnrichmentActionClientTest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with not doing this would be that we first we will not able to test the code with random data and another problem is since we will not have seed whenever we want to reproduce a failure. Not sure why MLCommons didn't do this. This is an acceptable practice in Opensearch Plugins. Plus you will miss out on all the different mocking and testing framework added by Opensearch.

@heemin32 heemin32 merged commit eb8aba6 into opensearch-project:main Dec 9, 2024
10 checks passed
@heemin32 heemin32 added the backport 2.x Backport PR to 2.x branch label Dec 9, 2024
opensearch-trigger-bot bot pushed a commit that referenced this pull request Dec 9, 2024
…nt (#700)

* Common module

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* POC

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Consolidate interface

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Consolidate interface

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Remove common module

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Gradle cleanup

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Lombok

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Java doc - 1

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Java doc

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* API Signature

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Fetch default data source

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Logger

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Initial test cases

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Add test-cases

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Test-cases: Client

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update tests

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update code style

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Style fix

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update deps

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Spotless

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Spotless

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Code refactor

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Serialisation attempt

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Remove custom serialisation support

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Address code comments

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update test infra

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Remove unused test-cases

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Add lombok config

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update test

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update changelog

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update gradle

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update Gradle build

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update artifact info

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Minimise diff

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Style fix

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Code comments

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

---------

Signed-off-by: Andy Kwok <andy.kwok@improving.com>
(cherry picked from commit eb8aba6)
heemin32 pushed a commit that referenced this pull request Dec 9, 2024
…nt (#700) (#705)

* Common module

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* POC

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Consolidate interface

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Consolidate interface

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Remove common module

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Gradle cleanup

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Lombok

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Java doc - 1

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Java doc

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* API Signature

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Fetch default data source

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Logger

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Initial test cases

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Add test-cases

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Test-cases: Client

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update tests

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update code style

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Style fix

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update deps

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Spotless

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Spotless

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Code refactor

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Serialisation attempt

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Remove custom serialisation support

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Address code comments

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update test infra

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Remove unused test-cases

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Add lombok config

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update test

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update changelog

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update gradle

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update Gradle build

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Update artifact info

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Minimise diff

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Style fix

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

* Code comments

Signed-off-by: Andy Kwok <andy.kwok@improving.com>

---------

Signed-off-by: Andy Kwok <andy.kwok@improving.com>
(cherry picked from commit eb8aba6)

Co-authored-by: Andy Kwok <andy.kwok@improving.com>
@acarbonetto acarbonetto deleted the ft-hf-common-module branch December 10, 2024 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport PR to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] Expose Geo2IP Enrichment feature to other plugins to standardize OpenSearch IP enrichment offering
3 participants