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 validations for Personalize input and configurations #151

Merged

Conversation

kulket
Copy link
Contributor

@kulket kulket commented Jul 5, 2023

Description

This pull request adds following changes:

  • Change scoring logic for Personalized ranking to consider ranks instead of scores as well as refactor overall scoring logic implementation
  • Add validation for search request parameters as well as response processor configurations related to Personalization
  • Add E2E tests in the form of unit tests for Personalize ranking
  • Add user agent configuration to Personalize client to understand plugin adoption

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed as per the DCO using --signoff

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.

@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Merging #151 (e0490ff) into main (174ae5f) will increase coverage by 0.02%.
The diff coverage is 92.75%.

@@             Coverage Diff              @@
##               main     #151      +/-   ##
============================================
+ Coverage     83.41%   83.44%   +0.02%     
- Complexity      324      331       +7     
============================================
  Files            41       42       +1     
  Lines          1242     1250       +8     
  Branches        152      153       +1     
============================================
+ Hits           1036     1043       +7     
  Misses          130      130              
- Partials         76       77       +1     
Impacted Files Coverage Δ
...nalizeintelligentranking/utils/ValidationUtil.java 75.00% <75.00%> (ø)
...ng/reranker/impl/AmazonPersonalizedRankerImpl.java 96.10% <97.82%> (+2.84%) ⬆️
...ntranking/PersonalizeRankingResponseProcessor.java 100.00% <100.00%> (ø)
...zeintelligentranking/client/PersonalizeClient.java 65.00% <100.00%> (+6.17%) ⬆️
...igentranking/client/PersonalizeClientSettings.java 96.55% <100.00%> (ø)

... and 2 files with indirect coverage changes

@kulket kulket marked this pull request as ready for review July 6, 2023 02:01
Copy link
Collaborator

@noCharger noCharger left a comment

Choose a reason for hiding this comment

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

Overall looks good, have some small comments

@@ -10,11 +10,13 @@
import com.amazonaws.services.personalizeruntime.model.GetPersonalizedRankingRequest;
import com.amazonaws.services.personalizeruntime.model.GetPersonalizedRankingResult;
import com.amazonaws.services.personalizeruntime.model.PredictedItem;
import org.apache.commons.lang3.StringUtils;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using StringUtils requires adding the Apache Commons Lang library as a dependency. While this is not a significant issue, it does introduce an additional external dependency that needs to be managed and potentially increases the project's size. Also, calling utility methods for simple string operations (only isEmpty is used) can add some overhead compared to inline operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will replace it with !=null and isEmpty() checks on the String object itself.

}
// Validate Personalize recipe
if(!SUPPORTED_PERSONALIZE_RECIPES.contains(config.getRecipe())) {
throw ConfigurationUtils.newConfigurationException(processorType, processorTag, "recipe", "not supported recipe provided");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add test case on this exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already have a test case supporting this: Refer here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

 Check warning on line 48 in src/main/java/org/opensearch/search/relevance/transformer/personalizeintelligentranking/utils/ValidationUtil.java

Codecov
/ codecov/patch
src/main/java/org/opensearch/search/relevance/transformer/personalizeintelligentranking/utils/ValidationUtil.java#L48

Comment on lines 53 to 59
private static boolean isValidCampaignOrRoleArn(String arn, String expectedService) {
try {
Arn arnObj = Arn.fromString(arn);
String arnService = arnObj.getService();
if (!arnService.equals(expectedService)) {
return false;
}
} catch (IllegalArgumentException iae) {
return false;
}
return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
private static boolean isValidCampaignOrRoleArn(String arn, String expectedService) {
try {
Arn arnObj = Arn.fromString(arn);
String arnService = arnObj.getService();
if (!arnService.equals(expectedService)) {
return false;
}
} catch (IllegalArgumentException iae) {
return false;
}
return true;
}
private static boolean isValidCampaignOrRoleArn(String arn, String expectedService) {
try {
Arn arnObj = Arn.fromString(arn);
return arnObj.getService().equals(expectedService);
} catch (IllegalArgumentException ignored) {
return false;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for suggestion. Will make this change.

Description:
===========
This commit adds following changes:
* Change scoring logic to consider ranks instead of scores
* Add validation for Personalize inputs and configurations
* Add E2E tests in the form of unit tests for Personalize ranking

Signed-off-by: Ketan Kulkarni <[email protected]>
…tion

Description:
============
This change adds following:
* User agent configuration for Personalize client to understand plugin adoption
* Add validation related unit tests

Signed-off-by: Ketan Kulkarni <[email protected]>
Description:
===========
This commit adds following changes:
* Change scoring logic to consider ranks instead of scores
* Add validation for Personalize inputs and configurations
* Add E2E tests in the form of unit tests for Personalize ranking

Signed-off-by: Ketan Kulkarni <[email protected]>
Description:
===========
This commit includes following:
* Change response processor name from personalize_ranking to personalized_search_ranking
* Change client settings to use same naming convention
* Address review comments

Signed-off-by: Ketan Kulkarni <[email protected]>
Signed-off-by: Ketan Kulkarni <[email protected]>
@kulket kulket force-pushed the feat-validation-exception-handling branch from 9f3f660 to e0490ff Compare July 12, 2023 00:07
Copy link
Collaborator

@mingshl mingshl left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@noCharger noCharger left a comment

Choose a reason for hiding this comment

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

Overall looks good. Left some non-blocking comments. Can't wait to see it included in 2.9!

}
// Validate Personalize recipe
if(!SUPPORTED_PERSONALIZE_RECIPES.contains(config.getRecipe())) {
throw ConfigurationUtils.newConfigurationException(processorType, processorTag, "recipe", "not supported recipe provided");
Copy link
Collaborator

Choose a reason for hiding this comment

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

 Check warning on line 48 in src/main/java/org/opensearch/search/relevance/transformer/personalizeintelligentranking/utils/ValidationUtil.java

Codecov
/ codecov/patch
src/main/java/org/opensearch/search/relevance/transformer/personalizeintelligentranking/utils/ValidationUtil.java#L48

@mingshl mingshl merged commit e305c13 into opensearch-project:main Jul 12, 2023
16 checks passed
@mingshl mingshl added the backport 2.x Backport to 2.x branch label Jul 12, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 12, 2023
* Add validations for Personalize input and configurations

Description:
===========
This commit adds following changes:
* Change scoring logic to consider ranks instead of scores
* Add validation for Personalize inputs and configurations
* Add E2E tests in the form of unit tests for Personalize ranking

Signed-off-by: Ketan Kulkarni <[email protected]>

* Add user agent prefix to Personalize client to understand plugin adoption

Description:
============
This change adds following:
* User agent configuration for Personalize client to understand plugin adoption
* Add validation related unit tests

Signed-off-by: Ketan Kulkarni <[email protected]>

* Add validations for Personalize input and configurations

Description:
===========
This commit adds following changes:
* Change scoring logic to consider ranks instead of scores
* Add validation for Personalize inputs and configurations
* Add E2E tests in the form of unit tests for Personalize ranking

Signed-off-by: Ketan Kulkarni <[email protected]>

* Change response processor config name

Description:
===========
This commit includes following:
* Change response processor name from personalize_ranking to personalized_search_ranking
* Change client settings to use same naming convention
* Address review comments

Signed-off-by: Ketan Kulkarni <[email protected]>

* Fix typo in unit test

Signed-off-by: Ketan Kulkarni <[email protected]>

---------

Signed-off-by: Ketan Kulkarni <[email protected]>
(cherry picked from commit e305c13)
mingshl pushed a commit that referenced this pull request Jul 12, 2023
* Add validations for Personalize input and configurations

Description:
===========
This commit adds following changes:
* Change scoring logic to consider ranks instead of scores
* Add validation for Personalize inputs and configurations
* Add E2E tests in the form of unit tests for Personalize ranking

Signed-off-by: Ketan Kulkarni <[email protected]>

* Add user agent prefix to Personalize client to understand plugin adoption

Description:
============
This change adds following:
* User agent configuration for Personalize client to understand plugin adoption
* Add validation related unit tests

Signed-off-by: Ketan Kulkarni <[email protected]>

* Add validations for Personalize input and configurations

Description:
===========
This commit adds following changes:
* Change scoring logic to consider ranks instead of scores
* Add validation for Personalize inputs and configurations
* Add E2E tests in the form of unit tests for Personalize ranking

Signed-off-by: Ketan Kulkarni <[email protected]>

* Change response processor config name

Description:
===========
This commit includes following:
* Change response processor name from personalize_ranking to personalized_search_ranking
* Change client settings to use same naming convention
* Address review comments

Signed-off-by: Ketan Kulkarni <[email protected]>

* Fix typo in unit test

Signed-off-by: Ketan Kulkarni <[email protected]>

---------

Signed-off-by: Ketan Kulkarni <[email protected]>
(cherry picked from commit e305c13)

Co-authored-by: kulket <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants