Skip to content

Conversation

@toepkerd
Copy link
Collaborator

@toepkerd toepkerd commented Oct 30, 2025

Description

Get and Search Monitor functionality for PPL Alerting

Related Issues

#1880

Check List

  • [Y] New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • [Y] 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.

Comment on lines +58 to +60
if (request.method() == HEAD) {
srcContext = FetchSourceContext.DO_NOT_FETCH_SOURCE
}
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose for head here?

Copy link
Member

Choose a reason for hiding this comment

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

If this is copying v1 monitors for UI setup, does the new V2 UI even use this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This case handling is ported over from Alerting V1, where it helped with regenerating the visual basic mode of monitors. This use case doesn't immediately apply to Alerting V2, but the logic will be retained so Alerting V2 can catch this potential curve ball in the future.

* ./gradlew :alerting:integTest -Dhttps=true -Dsecurity=true -Duser=admin -Dpassword=admin \
* --tests "org.opensearch.alerting.resthandler.SecureMonitorV2RestApiIT"
*/
class SecureMonitorV2RestApiIT : AlertingRestTestCase() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we also test update monitor on just cluster permissions and a user trying to update a monitor (change a trigger name, but not the index) that monitors an index that they do not have permissions to

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

Signed-off-by: Dennis Toepker <[email protected]>
.field(_SEQ_NO, seqNo)
.field(_PRIMARY_TERM, primaryTerm)
if (monitorV2 != null) {
builder.field("monitorV2", monitorV2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick:
The monitorV2 field name seems a little awkward in this context. It seems like we could have probably just reused the [GetMonitorResponse] object.

Not blocking if this is the decision we're going for; but seems like the v1 and v2 monitors are being separated to an arbitrary extent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is indeed more of an engineering decision than a product decision. I chose this approach in the spirit of committing to separating the v1 and v2 APIs. It may be a duplicate of the v1 response object now, but it gives us room to add things to v2 that may not be applicable to v1.

}

// RBAC is out of scope for this test, so give all users and requests the same one
val backendRole = "backend_role_a"
Copy link
Member

@lezzago lezzago Oct 30, 2025

Choose a reason for hiding this comment

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

[Not blocking] We can disable filter by backend role setting so this is not needed to be added.

)
fail("Expected update monitor to fail as user does not have permissions to index that monitor queries")
} catch (e: ResponseException) {
assertEquals("Unexpected error status", RestStatus.BAD_REQUEST.status, e.response.statusLine.statusCode)
Copy link
Member

@lezzago lezzago Oct 30, 2025

Choose a reason for hiding this comment

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

We should have handle this error gracefully by calling out the user does not have permissions on the index set in the monitor. This would actually be more of a comment on the update monitor api

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To validate the PPL Query, PPL Alerting submits the raw query to PPL plugin. If there's an error from the PPL plugin, it gets relayed to the user here.

The try catch that throws the error this test expects is pretty one size fits all: an invalid PPL query throws the same error as a valid query on an index users don't have permissions to. Increasing the granularity of the error would require either 1) parsing the string error response of the PPL query API, or 2) doing a separate Alerting level check of the indices in the PPL query before validating the PPL query against PPL Plugin itself.

Will raise a Github issue calling out the one size fits all nature of the validation check against PPL query.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Github issue: #1967

@toepkerd toepkerd merged commit 819599f into opensearch-project:main Oct 31, 2025
18 checks passed
@toepkerd toepkerd deleted the ppl-review branch October 31, 2025 16:55
@opensearch-trigger-bot
Copy link
Contributor

The backport to 3.3 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/alerting/backport-3.3 3.3
# Navigate to the new working tree
pushd ../.worktrees/alerting/backport-3.3
# Create a new branch
git switch --create backport-1966-to-3.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 819599f3431be0691d8540746a7a9c132e41dfa3
# Push it to GitHub
git push --set-upstream origin backport-1966-to-3.3
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/alerting/backport-3.3

Then, create a pull request where the base branch is 3.3 and the compare/head branch is backport-1966-to-3.3.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.19 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/alerting/backport-2.19 2.19
# Navigate to the new working tree
pushd ../.worktrees/alerting/backport-2.19
# Create a new branch
git switch --create backport-1966-to-2.19
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 819599f3431be0691d8540746a7a9c132e41dfa3
# Push it to GitHub
git push --set-upstream origin backport-1966-to-2.19
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/alerting/backport-2.19

Then, create a pull request where the base branch is 2.19 and the compare/head branch is backport-1966-to-2.19.

toepkerd added a commit to toepkerd/alerting that referenced this pull request Nov 2, 2025
* PPL Alerting: Get and Search Monitors

Signed-off-by: Dennis Toepker <[email protected]>

* adding requested ID

Signed-off-by: Dennis Toepker <[email protected]>

---------

Signed-off-by: Dennis Toepker <[email protected]>
Co-authored-by: Dennis Toepker <[email protected]>
(cherry picked from commit 819599f)
toepkerd added a commit that referenced this pull request Nov 3, 2025
* PPL Alerting: Get and Search Monitors



* adding requested ID



---------



(cherry picked from commit 819599f)

Signed-off-by: Dennis Toepker <[email protected]>
Co-authored-by: Dennis Toepker <[email protected]>
toepkerd added a commit to toepkerd/alerting that referenced this pull request Nov 8, 2025
* PPL Alerting: Get and Search Monitors

Signed-off-by: Dennis Toepker <[email protected]>

* adding requested ID

Signed-off-by: Dennis Toepker <[email protected]>

---------

Signed-off-by: Dennis Toepker <[email protected]>
Co-authored-by: Dennis Toepker <[email protected]>
toepkerd added a commit to toepkerd/alerting that referenced this pull request Nov 8, 2025
* PPL Alerting: Get and Search Monitors

Signed-off-by: Dennis Toepker <[email protected]>

* adding requested ID

Signed-off-by: Dennis Toepker <[email protected]>

---------

Signed-off-by: Dennis Toepker <[email protected]>
Co-authored-by: Dennis Toepker <[email protected]>
toepkerd added a commit to toepkerd/alerting that referenced this pull request Nov 9, 2025
* PPL Alerting: Get and Search Monitors

Signed-off-by: Dennis Toepker <[email protected]>

* adding requested ID

Signed-off-by: Dennis Toepker <[email protected]>

---------

Signed-off-by: Dennis Toepker <[email protected]>
Co-authored-by: Dennis Toepker <[email protected]>
amsiglan pushed a commit that referenced this pull request Nov 9, 2025
* PPL Alerting: Get and Search Monitors



* adding requested ID



---------

Signed-off-by: Dennis Toepker <[email protected]>
Co-authored-by: Dennis Toepker <[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.

4 participants