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

Implemented filtering on the ISM eplain API #998

Merged
merged 9 commits into from
Dec 14, 2023

Conversation

Joshua152
Copy link
Contributor

@Joshua152 Joshua152 commented Oct 10, 2023

Issue
#651

Description of changes:
Added POST method to ISM explain API to enable filtering on the policies. This does the same thing as GET, except adds in filtering. The request body should look as follows:

"filter": {
"policy_id": "my_id",
"state": "my_state_name",
"action_type": "my_action_type"
}

The filter only returns policies for which they match every filter given. If a filter is left out (ex. "policy_id"), any of that filter will be allowed.

CheckList:

  • Commits are signed 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 Oct 12, 2023

Codecov Report

Attention: 66 lines in your changes are missing coverage. Please review.

Comparison is base (417d0d9) 74.80% compared to head (6139c9d) 74.41%.

Files Patch % Lines
...gement/indexstatemanagement/model/ExplainFilter.kt 1.96% 49 Missing and 1 partial ⚠️
...transport/action/explain/TransportExplainAction.kt 20.00% 11 Missing and 1 partial ⚠️
...exstatemanagement/resthandler/RestExplainAction.kt 66.66% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #998      +/-   ##
============================================
- Coverage     74.80%   74.41%   -0.39%     
+ Complexity     2787     2785       -2     
============================================
  Files           366      367       +1     
  Lines         16422    16502      +80     
  Branches       2342     2357      +15     
============================================
- Hits          12284    12280       -4     
- Misses         2836     2919      +83     
- Partials       1302     1303       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bowenlan-amzn
Copy link
Member

@Joshua152 thanks, this is good progress.
I put down some more details on the requirements of this feature #651 (comment), we can do this iteratively.

@bowenlan-amzn
Copy link
Member

@Joshua152 maybe pull the change from #1022 back to this PR, and let's wrap on this. 😃

@@ -22,7 +22,8 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedInde
import java.io.ByteArrayInputStream
import java.nio.charset.StandardCharsets

data class StateMetaData(
data class
Copy link
Member

Choose a reason for hiding this comment

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

Can change this back

@@ -21,6 +22,7 @@ class ExplainRequest : ActionRequest {
val local: Boolean
val clusterManagerTimeout: TimeValue
val searchParams: SearchParams
val explainFilter: ExplainFilter
Copy link
Member

Choose a reason for hiding this comment

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

Prefer explainFilter to be nullable.


@JvmStatic
@Throws(IOException::class)
fun parse(xcp: XContentParser): ExplainFilter {
Copy link
Member

Choose a reason for hiding this comment

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

Please add unit tests for the codecov warning. Feel free to add in another PR
Let me know if you need any guidance on writing UTs

return boolQuery
}

fun validMetaData(metaData: ManagedIndexMetaData): Boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Better name as filterByMetadata? or even byMetadata since the class name already contains filter in it

}

fun validMetaData(metaData: ManagedIndexMetaData): Boolean {
var ok = true
Copy link
Member

Choose a reason for hiding this comment

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

ok is a little misleading here 😃 sometimes it's actually not ok

ok = false
}

if (failed != null && (actionMetaData == null || actionMetaData.failed != failed)) {
Copy link
Member

Choose a reason for hiding this comment

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

Also check the retry.failed field in metadata here, if it's true, meaning this job is failed

Comment on lines 302 to 303
ok = request.explainFilter.validMetaData(metaData)
if (!ok) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: if (request.explainFilter.validMetaData(metaData))

response.responses.associate { it.id to getMetadata(it.response)?.toMap() }

metadataMap = metadataMap.filter { (_, value) ->
Copy link
Member

Choose a reason for hiding this comment

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

Need to add IT in RestExplainIT for this, feel free to do this in another PR

@bowenlan-amzn bowenlan-amzn mentioned this pull request Nov 9, 2023
1 task
@bowenlan-amzn bowenlan-amzn added the v2.12.0 Issues targeting release v2.12.0 label Nov 9, 2023
Copy link
Member

@bowenlan-amzn bowenlan-amzn left a comment

Choose a reason for hiding this comment

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

Very good!

if (value != null) {
val metaData = ManagedIndexMetaData.fromMap(value)

if (!request.explainFilter.byMetaData(metaData)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we removing metaData.index from indexNames and indexNamesToUUIDs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When creating the actual response, all the index names are looped over. So, in order to remove the filtered indices, they must be removed from indexNames.

@@ -52,6 +56,14 @@ class RestExplainAction : BaseRestHandler() {
ReplacedRoute(
GET, "$EXPLAIN_BASE_URI/{index}",
GET, "$LEGACY_EXPLAIN_BASE_URI/{index}"
),
ReplacedRoute(
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we able to use explain API with filter enabled across all indices and on specific indices?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it works for both

Copy link
Contributor

@jowg-amazon jowg-amazon left a comment

Choose a reason for hiding this comment

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

LGTM

@bowenlan-amzn bowenlan-amzn merged commit 21f5f8d into opensearch-project:main Dec 14, 2023
22 of 25 checks passed
@opensearch-trigger-bot
Copy link
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:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/index-management/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/index-management/backport-2.x
# Create a new branch
git switch --create backport/backport-998-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 21f5f8d40377d91eb45d3af3747fffde5fe06525
# Push it to GitHub
git push --set-upstream origin backport/backport-998-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/index-management/backport-2.x

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

@bowenlan-amzn
Copy link
Member

@Joshua152 this has been merged in, but the backport failed, can you manually apply this change to 2.x branch and create a PR please?

Joshua152 added a commit to Joshua152/index-management that referenced this pull request Dec 18, 2023
@Joshua152 Joshua152 mentioned this pull request Dec 18, 2023
1 task
Joshua152 added a commit to Joshua152/index-management that referenced this pull request Dec 26, 2023
* Implemented filtering on the ISM eplain API

Signed-off-by: Joshua Au <[email protected]>

* Fixed tests for ExplainRequest

Signed-off-by: Joshua Au <[email protected]>

* Added filtering on query and metadata map

Signed-off-by: Joshua Au <[email protected]>

* Filtered on indexNames in metadata

Signed-off-by: Joshua Au <[email protected]>

* Fixed github workflow check errors

Signed-off-by: Joshua Au <[email protected]>

* Removed debugging comments

Signed-off-by: Joshua Au <[email protected]>

* Updated code styling to make more clear

Signed-off-by: Joshua Au <[email protected]>

* Refactored code to match suggestions

Signed-off-by: Joshua Au <[email protected]>

---------

Signed-off-by: Joshua Au <[email protected]>
Co-authored-by: bowenlan-amzn <[email protected]>
jowg-amazon pushed a commit that referenced this pull request Jan 4, 2024
* Backport issue #998 to 2.x

Signed-off-by: Joshua Au <[email protected]>

* Issue651 tests (#1046)

* Implemented filtering on the ISM eplain API

Signed-off-by: Joshua Au <[email protected]>

* Fixed tests for ExplainRequest

Signed-off-by: Joshua Au <[email protected]>

* Added filtering on query and metadata map

Signed-off-by: Joshua Au <[email protected]>

* Filtered on indexNames in metadata

Signed-off-by: Joshua Au <[email protected]>

* Fixed github workflow check errors

Signed-off-by: Joshua Au <[email protected]>

* Removed debugging comments

Signed-off-by: Joshua Au <[email protected]>

* Updated code styling to make more clear

Signed-off-by: Joshua Au <[email protected]>

* Refactored code to match suggestions

Signed-off-by: Joshua Au <[email protected]>

* Added test case for the ExplainFilter.byMetaData and parse methods

Signed-off-by: Joshua Au <[email protected]>

* Started implementation of explain filter IT

Signed-off-by: Joshua Au <[email protected]>

* Implemented test explain filter method

Signed-off-by: Joshua Au <[email protected]>

* Implemented explain filter test on failure

Signed-off-by: Joshua Au <[email protected]>

* Cleaned up log statements

Signed-off-by: Joshua Au <[email protected]>

* Added explain filter test for success

Signed-off-by: Joshua Au <[email protected]>

* Fixed lint errors

Signed-off-by: Joshua Au <[email protected]>

* Removed policy from index to fix flaky tests

Signed-off-by: Joshua Au <[email protected]>

---------

Signed-off-by: Joshua Au <[email protected]>
Signed-off-by: bowenlan-amzn <[email protected]>
Co-authored-by: bowenlan-amzn <[email protected]>

* Fixed content type import

Signed-off-by: Joshua Au <[email protected]>

* Implemented filtering on the ISM eplain API (#998)

* Implemented filtering on the ISM eplain API

Signed-off-by: Joshua Au <[email protected]>

* Fixed tests for ExplainRequest

Signed-off-by: Joshua Au <[email protected]>

* Added filtering on query and metadata map

Signed-off-by: Joshua Au <[email protected]>

* Filtered on indexNames in metadata

Signed-off-by: Joshua Au <[email protected]>

* Fixed github workflow check errors

Signed-off-by: Joshua Au <[email protected]>

* Removed debugging comments

Signed-off-by: Joshua Au <[email protected]>

* Updated code styling to make more clear

Signed-off-by: Joshua Au <[email protected]>

* Refactored code to match suggestions

Signed-off-by: Joshua Au <[email protected]>

---------

Signed-off-by: Joshua Au <[email protected]>
Co-authored-by: bowenlan-amzn <[email protected]>

* Issue651 tests (#1046)

* Implemented filtering on the ISM eplain API

Signed-off-by: Joshua Au <[email protected]>

* Fixed tests for ExplainRequest

Signed-off-by: Joshua Au <[email protected]>

* Added filtering on query and metadata map

Signed-off-by: Joshua Au <[email protected]>

* Filtered on indexNames in metadata

Signed-off-by: Joshua Au <[email protected]>

* Fixed github workflow check errors

Signed-off-by: Joshua Au <[email protected]>

* Removed debugging comments

Signed-off-by: Joshua Au <[email protected]>

* Updated code styling to make more clear

Signed-off-by: Joshua Au <[email protected]>

* Refactored code to match suggestions

Signed-off-by: Joshua Au <[email protected]>

* Added test case for the ExplainFilter.byMetaData and parse methods

Signed-off-by: Joshua Au <[email protected]>

* Started implementation of explain filter IT

Signed-off-by: Joshua Au <[email protected]>

* Implemented test explain filter method

Signed-off-by: Joshua Au <[email protected]>

* Implemented explain filter test on failure

Signed-off-by: Joshua Au <[email protected]>

* Cleaned up log statements

Signed-off-by: Joshua Au <[email protected]>

* Added explain filter test for success

Signed-off-by: Joshua Au <[email protected]>

* Fixed lint errors

Signed-off-by: Joshua Au <[email protected]>

* Removed policy from index to fix flaky tests

Signed-off-by: Joshua Au <[email protected]>

---------

Signed-off-by: Joshua Au <[email protected]>
Signed-off-by: bowenlan-amzn <[email protected]>
Co-authored-by: bowenlan-amzn <[email protected]>

* Backport explain filter tests

* Sleep thread to allow jobs to finish

Signed-off-by: Joshua Au <[email protected]>

---------

Signed-off-by: Joshua Au <[email protected]>
Signed-off-by: bowenlan-amzn <[email protected]>
Co-authored-by: bowenlan-amzn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants