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

fix chained findings monitor logic in update detector flow #1019

Merged
merged 2 commits into from
May 9, 2024

Conversation

eirsep
Copy link
Member

@eirsep eirsep commented May 8, 2024

Description

Currently when updating a detector with aggegation rules, the chained finding doc levelmonitor is getting deleted
This PR fixes the logic to update/retain the chained finding doc level monitor
Added to integ test to verify detector behaviour after updating detector.

engechas
engechas previously approved these changes May 8, 2024
@@ -465,6 +465,18 @@ public void onResponse(Map<String, Map<String, String>> ruleFieldMappings) {
new ActionListener<>() {
@Override
public void onResponse(Collection<IndexMonitorRequest> indexMonitorRequests) {
if (detector.getRuleIdMonitorIdMap().containsKey("chained_findings_monitor")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

chained_findings_monitor should be a constant

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

@@ -465,6 +465,18 @@ public void onResponse(Map<String, Map<String, String>> ruleFieldMappings) {
new ActionListener<>() {
@Override
public void onResponse(Collection<IndexMonitorRequest> indexMonitorRequests) {
if (detector.getRuleIdMonitorIdMap().containsKey("chained_findings_monitor")) {
String cmfId = detector.getRuleIdMonitorIdMap().get("chained_findings_monitor");
if (enabledWorkflowUsage && !indexMonitorRequests.isEmpty() && rulesById.stream().anyMatch(it -> it.getRight().isAggregationRule())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Triplicate condition + same logic on line 475. Should be refactored to a private method, something like workflowContainsAggregationRule()

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

if (detector.getRuleIdMonitorIdMap().containsKey("chained_findings_monitor")) {
String cmfId = detector.getRuleIdMonitorIdMap().get("chained_findings_monitor");
if (enabledWorkflowUsage && !indexMonitorRequests.isEmpty() && rulesById.stream().anyMatch(it -> it.getRight().isAggregationRule())) {
//todo update not create chained findings monitor
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should create and link an issue for this. Or at least elaborate on why this todo exists

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we know why the chained monitor gets deleted in the first place?

Copy link
Member Author

Choose a reason for hiding this comment

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

removing TODO. its resolved

jowg-amazon
jowg-amazon previously approved these changes May 8, 2024
praveensameneni
praveensameneni previously approved these changes May 9, 2024
…reate constant for chained findings monitor string literal

Signed-off-by: Surya Sashank Nistala <[email protected]>
@eirsep eirsep dismissed stale reviews from praveensameneni, jowg-amazon, and engechas via f9e276a May 9, 2024 00:20
@eirsep eirsep merged commit df5f746 into opensearch-project:main May 9, 2024
16 checks passed
@opensearch-trigger-bot
Copy link
Contributor

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

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

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.13 failed:

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

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

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

opensearch-trigger-bot bot pushed a commit that referenced this pull request May 9, 2024
* fix chained findings monitor logic in update detector flow

Signed-off-by: Surya Sashank Nistala <[email protected]>

* extract check for chained findings monitor into a re-usable method. create constant for chained findings monitor string literal

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Surya Sashank Nistala <[email protected]>
(cherry picked from commit df5f746)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
eirsep pushed a commit that referenced this pull request May 9, 2024
…1020)

* fix chained findings monitor logic in update detector flow



* extract check for chained findings monitor into a re-usable method. create constant for chained findings monitor string literal



---------


(cherry picked from commit df5f746)

Signed-off-by: Surya Sashank Nistala <[email protected]>
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>
opensearch-trigger-bot bot added a commit that referenced this pull request May 9, 2024
…1020)

* fix chained findings monitor logic in update detector flow

* extract check for chained findings monitor into a re-usable method. create constant for chained findings monitor string literal

---------

(cherry picked from commit df5f746)

Signed-off-by: Surya Sashank Nistala <[email protected]>
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>
(cherry picked from commit c162a6f)
opensearch-trigger-bot bot added a commit that referenced this pull request May 9, 2024
…1020)

* fix chained findings monitor logic in update detector flow

* extract check for chained findings monitor into a re-usable method. create constant for chained findings monitor string literal

---------

(cherry picked from commit df5f746)

Signed-off-by: Surya Sashank Nistala <[email protected]>
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>
(cherry picked from commit c162a6f)
eirsep pushed a commit that referenced this pull request May 9, 2024
…1020) (#1023)

* fix chained findings monitor logic in update detector flow

* extract check for chained findings monitor into a re-usable method. create constant for chained findings monitor string literal

---------

(cherry picked from commit df5f746)

Signed-off-by: Surya Sashank Nistala <[email protected]>
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>
(cherry picked from commit c162a6f)

Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
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