Skip to content

[Extensions] Add Regex validator#6221

Merged
ryanbogan merged 21 commits intoopensearch-project:mainfrom
mloufra:sample-validator
Mar 10, 2023
Merged

[Extensions] Add Regex validator#6221
ryanbogan merged 21 commits intoopensearch-project:mainfrom
mloufra:sample-validator

Conversation

@mloufra
Copy link
Copy Markdown
Contributor

@mloufra mloufra commented Feb 7, 2023

Description

Add Regex Validator implement Writeable and Validator to make Validator writeable for custom setting.

Issues Resolved

Fixes opensearch-project/opensearch-sdk-java#350

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 7, 2023

Gradle Check (Jenkins) Run Completed with:

Copy link
Copy Markdown
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

Great job!

A few minor tweaks needed, and a usability suggestion from the original issue.

// RegexValidator
public static class RegexValidator implements Writeable, Validator<String> {
private Pattern pattern;
private String value = "forbidden";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't hardcode this iniitialization. I don't think you use it anywhere, so it can just be deleted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ACK

return properties != null && Arrays.asList(properties).contains(Property.Filtered);
}

// RegexValidator
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A more descriptive class javadoc would be helpful! :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ACK


@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(pattern.pattern());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is good. You don't need to store the original string because you can extract it with pattern().

@Override
public void validate(String value) {
if(pattern.matcher(value).matches()){
throw new IllegalArgumentException("custom setting contains forbidden");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The message here should be "Custom setting matches regex [" + pattern.pattern() + "]".

See this comment for a suggestion to add an (optional) second String in an overloaded constructor, which if not null, will use that message here instead of this one.

EnumSet<Property> propSet = in.readEnumSet(Property.class);
// Put it all in a setting object
this.setting = createSetting(type, key, defaultValue, fallback, propSet.toArray(Property[]::new));
this.setting = createSetting(type, key, defaultValue, validator, fallback, propSet.toArray(Property[]::new));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK for now, when your parser PR is merged you'll have to rebase to update this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ACK

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 8, 2023

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 8, 2023

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 8, 2023

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 8, 2023

Gradle Check (Jenkins) Run Completed with:

@mloufra mloufra requested a review from dbwiddis February 8, 2023 22:25
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 8, 2023

Gradle Check (Jenkins) Run Completed with:

mloufra added 3 commits March 8, 2023 22:34
Signed-off-by: Frank Lou <mloufra@amazon.com>
Signed-off-by: Frank Lou <mloufra@amazon.com>
Signed-off-by: Frank Lou <mloufra@amazon.com>
@mloufra mloufra force-pushed the sample-validator branch from 4288cc9 to c3daa44 Compare March 8, 2023 23:03
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 8, 2023

Gradle Check (Jenkins) Run Completed with:

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 8, 2023

Codecov Report

Merging #6221 (8e67ed4) into main (8c0e5d0) will increase coverage by 0.02%.
The diff coverage is 75.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@             Coverage Diff              @@
##               main    #6221      +/-   ##
============================================
+ Coverage     70.77%   70.80%   +0.02%     
- Complexity    59125    59144      +19     
============================================
  Files          4804     4804              
  Lines        283098   283121      +23     
  Branches      40813    40816       +3     
============================================
+ Hits         200372   200470      +98     
+ Misses        66269    66183      -86     
- Partials      16457    16468      +11     
Impacted Files Coverage Δ
...g/opensearch/common/settings/WriteableSetting.java 69.58% <50.00%> (-2.00%) ⬇️
...n/java/org/opensearch/common/settings/Setting.java 86.32% <100.00%> (+0.19%) ⬆️

... and 457 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Frank Lou <mloufra@amazon.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2023

Gradle Check (Jenkins) Run Completed with:

@mloufra mloufra requested a review from dbwiddis March 9, 2023 00:10
Copy link
Copy Markdown
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

Some final javadoc fixes and this will be GTG

public static class RegexValidator implements Writeable, Validator<String> {
private Pattern pattern;

public RegexValidator(String regex) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You added the javadoc to the streaminput constructor below, not this one... this is the one developers will use. The StreamInput constructor will be used by the transport service sending these between OpenSearch and SDK.

Also you need the @param javadoc tag for the parameters.

Signed-off-by: Frank Lou <mloufra@amazon.com>
@mloufra mloufra requested a review from dbwiddis March 9, 2023 17:49
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2023

Gradle Check (Jenkins) Run Completed with:

@mloufra mloufra requested a review from dblock March 9, 2023 19:41
@ryanbogan ryanbogan dismissed dblock’s stale review March 10, 2023 19:25

Changes have been addressed

Signed-off-by: Frank Lou <mloufra@amazon.com>
@ryanbogan ryanbogan added skip-changelog backport 2.x Backport to 2.x branch labels Mar 10, 2023
@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@ryanbogan ryanbogan merged commit b0ab550 into opensearch-project:main Mar 10, 2023
@mloufra mloufra deleted the sample-validator branch March 10, 2023 20:54
@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-6221-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 b0ab550ecfb80a2942b58169c5c38e500950a8cc
# Push it to GitHub
git push --set-upstream origin backport/backport-6221-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-6221-to-2.x.

@ryanbogan ryanbogan added backport 2.x Backport to 2.x branch and removed backport 2.x Backport to 2.x branch labels Mar 10, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 10, 2023
* add RegexValidator class

Signed-off-by: Frank Lou <mloufra@amazon.com>

* add regexValidator

Signed-off-by: Frank Lou <mloufra@amazon.com>

* addressing comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* addressing comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* do spotless

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* fix merge conflict

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* fix AssertionError

Signed-off-by: Frank Lou <mloufra@amazon.com>

* fix AssertionError

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* add javadoc

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* remove changlog

Signed-off-by: Frank Lou <mloufra@amazon.com>

---------

Signed-off-by: Frank Lou <mloufra@amazon.com>
(cherry picked from commit b0ab550)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ryanbogan pushed a commit that referenced this pull request Mar 10, 2023
* add RegexValidator class



* add regexValidator



* addressing comment



* addressing comment



* do spotless



* address comment



* fix merge conflict



* address comment



* address comment



* address comment



* address comment



* address comment



* address comment



* address comment



* address comment



* fix AssertionError



* fix AssertionError



* address comment



* add javadoc



* address comment



* remove changlog



---------


(cherry picked from commit b0ab550)

Signed-off-by: Frank Lou <mloufra@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
mingshl pushed a commit to mingshl/OpenSearch-Mingshl that referenced this pull request Mar 24, 2023
* add RegexValidator class

Signed-off-by: Frank Lou <mloufra@amazon.com>

* add regexValidator

Signed-off-by: Frank Lou <mloufra@amazon.com>

* addressing comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* addressing comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* do spotless

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* fix merge conflict

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* fix AssertionError

Signed-off-by: Frank Lou <mloufra@amazon.com>

* fix AssertionError

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* add javadoc

Signed-off-by: Frank Lou <mloufra@amazon.com>

* address comment

Signed-off-by: Frank Lou <mloufra@amazon.com>

* remove changlog

Signed-off-by: Frank Lou <mloufra@amazon.com>

---------

Signed-off-by: Frank Lou <mloufra@amazon.com>
Signed-off-by: Mingshi Liu <mingshl@amazon.com>
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 skip-changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Demonstrate custom validators in HelloWorld Extension

6 participants