-
Notifications
You must be signed in to change notification settings - Fork 113
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
Conversation
3ef7642
to
828f8d2
Compare
Codecov ReportAttention:
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. |
@Joshua152 thanks, this is good progress. |
Signed-off-by: Joshua Au <[email protected]>
Signed-off-by: Joshua Au <[email protected]>
Signed-off-by: Joshua Au <[email protected]>
Signed-off-by: Joshua Au <[email protected]>
@Joshua152 maybe pull the change from #1022 back to this PR, and let's wrap on this. 😃 |
Signed-off-by: Joshua Au <[email protected]>
Signed-off-by: Joshua Au <[email protected]>
@@ -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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ExplainFilter.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ExplainFilter.kt
Outdated
Show resolved
Hide resolved
return boolQuery | ||
} | ||
|
||
fun validMetaData(metaData: ManagedIndexMetaData): Boolean { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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
ok = request.explainFilter.validMetaData(metaData) | ||
if (!ok) { |
There was a problem hiding this comment.
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) -> |
There was a problem hiding this comment.
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
Signed-off-by: Joshua Au <[email protected]>
Signed-off-by: Joshua Au <[email protected]>
There was a problem hiding this 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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
21f5f8d
into
opensearch-project:main
The backport to
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 |
@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? |
Signed-off-by: Joshua Au <[email protected]>
* 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]>
* 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]>
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:
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.