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

Fixed a bug that prevented alerts from being generated for doc level monitors that use wildcard characters in index names. #894

Merged
merged 1 commit into from
May 5, 2023

Conversation

AWSHurneyt
Copy link
Collaborator

Issue #, if available:

Description of changes:

  1. Fixed a bug that prevented alerts from being generated for doc level monitors that use wildcard characters in index names.
  2. Fixed integration tests that examine this use case.

CheckList:
[x] 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.

…monitors that use wildcard characters in index names.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
@AWSHurneyt
Copy link
Collaborator Author

The BWC and security github checks are expected to be failing on main at the moment.

@lezzago
Copy link
Member

lezzago commented May 1, 2023

Did we figure out exactly why the previous tests did not catch this bug?

@AWSHurneyt
Copy link
Collaborator Author

AWSHurneyt commented May 1, 2023

Some findings regarding the test that failed to pick up this bug

The test execute monitor with wildcard index that generates alerts and findings test used the * wildcard character to configure the index for the test monitor. However, it still didn't pick up this bug; alerts and findings were still generated.

This will need further deep diving, but preliminary troubleshooting so far suggests the issue may actually relate to the names used for the test indices; test1, test2, and test* in the monitor configuration itself.

(For reference, the test documents contained the value "test_field" : "us-west-2".)

Even without the fix included in this PR, the test passes when the query is defined as query = "NOT (test_field:\"us-west-1\")" or query = "test_field:\"us-west-2\"". However, I noticed that the test was using test1 and test2 for the index names whereas my manual testing used test-index1 and test-index2. I adjusted the test to add the -index to the index names, and it started to fail as expected; but only for query = "NOT (test_field:\"us-west-1\")". After applying the fix, it passed as expected for both query test cases.

@lezzago
Copy link
Member

lezzago commented May 4, 2023

Lets create an issue to follow up on investigation

@lezzago lezzago merged commit 8c033b9 into opensearch-project:main May 5, 2023
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.0 failed:

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

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

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

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.1 failed:

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

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

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

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.2 failed:

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

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

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

opensearch-trigger-bot bot pushed a commit that referenced this pull request May 5, 2023
…monitors that use wildcard characters in index names. (#894)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.3 failed:

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

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

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

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.4 failed:

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

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

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

opensearch-trigger-bot bot pushed a commit that referenced this pull request May 5, 2023
…monitors that use wildcard characters in index names. (#894)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 5, 2023
…monitors that use wildcard characters in index names. (#894)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 5, 2023
…monitors that use wildcard characters in index names. (#894)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)

val percolateQueryBuilder = PercolateQueryBuilderExt("query", docs, XContentType.JSON)
if (monitor.id.isNotEmpty()) {
boolQueryBuilder.filter(QueryBuilders.matchQuery("monitor_id", monitor.id))
boolQueryBuilder.must(QueryBuilders.matchQuery("monitor_id", monitor.id).operator(Operator.AND))
}
boolQueryBuilder.filter(percolateQueryBuilder)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In follow-up revision, refactor this from .filter() to .must().

AWSHurneyt added a commit that referenced this pull request May 5, 2023
…monitors that use wildcard characters in index names. (#894) (#901)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)

Co-authored-by: AWSHurneyt <hurneyt@amazon.com>
AWSHurneyt added a commit that referenced this pull request May 5, 2023
…monitors that use wildcard characters in index names. (#894) (#904)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)

Co-authored-by: AWSHurneyt <hurneyt@amazon.com>
@eirsep
Copy link
Member

eirsep commented May 5, 2023

THE percolateQueryBuilder sub-query is still being added as a "query.filter()"
we should add that also as a MUSTxAND condition
Otherwise we are liable to having a change there where we add a new subquery with query.filter() which makes the percolate query optional in an implicit OR with the newly added sub-query

@lezzago @getsaurabh02

AWSHurneyt added a commit that referenced this pull request May 31, 2023
…monitors that use wildcard characters in index names. (#894) (#902)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)

Co-authored-by: AWSHurneyt <hurneyt@amazon.com>
AWSHurneyt added a commit to AWSHurneyt/OpenSearch-Alerting that referenced this pull request Jun 7, 2023
…monitors that use wildcard characters in index names. (opensearch-project#894) (opensearch-project#902)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)

Co-authored-by: AWSHurneyt <hurneyt@amazon.com>
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
lezzago pushed a commit to lezzago/alerting-opensearch that referenced this pull request Jun 8, 2023
…monitors that use wildcard characters in index names. (opensearch-project#894)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
lezzago added a commit that referenced this pull request Jun 8, 2023
* Added exception check once the .opendistro-alerting-config index is b… (#650)

* Added exception check once the .opendistro-alerting-config index is being created

During .opendistro-alerting-config index creation, if ResourceAlreadyExists exception is being raised, the flow will check first if the index is in yellow state and then it will re-try to index monitor

Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com>

* Formating of the file fixed

Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com>

Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com>

* refactored DeleteMonitor Action to be synchronious (#628) (#630)

* refactored DeleteMonitor Action to be synchronious

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>

* [Backport 2.x] QueryIndex rollover when field mapping limit is reached (#729)

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* Mappings fix backport 2.x (#730)

* Added support for "nested" mappings (#645)

* example

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* fixed updating mappings for queryIndex

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* mappings traversal bug fix (#669)

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* Added unwrapping exception from core; added more debug logs (#728)

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* Add DataSources test for future backports

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>

* fix  percolator mapping error when having field name 'type' (#726)

Signed-off-by: Raj Chakravarthi <raj@icedome.ca>

* [BUG] ExecuteMonitor inserting metadata doc during dry run (#758)

* execute monitor bugfix

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* added IT

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* fixed created retval when skipIndex=true

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

---------

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* fix for ERROR alert state generation in doc-level monitors (#768)

Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>

* Adjusting max field index setting dynamically for query index (#776)

* added adjusting max field index setting dynamicly for query index

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* Multiple indices support in DocLevelMonitorInput (#784)

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* Doc transform 2.x backport (#853)

* conflict resovle - backport from main to 2.x

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* fixed module class names

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

---------

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* Update config index schema if needed at the start of each monitor execution (#849)

* Update config index schema if needed at the start of each monitor execution

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>

* Mappings parsing fix (#851)

* fixed mappings parsing when field name named "properties" exists in mappings

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* message typo fix

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

---------

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* [Backport 2.x] Notification security fix (#861)

* Notification security fix (#852)

* added injecting whole user object in threadContext before calling notification APIs so that backend roles are available to notification plugin

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* compile fix

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* refactored user_info injection to use InjectSecurity

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* ktlint fix

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

---------

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
(cherry picked from commit e0b7a5a)

* remove unneeded import

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>

---------

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
Co-authored-by: Ashish Agrawal <ashisagr@amazon.com>

* Fixed a bug that prevented alerts from being generated for doc level monitors that use wildcard characters in index names. (#894)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* fixed security tests (#484) (#794)

* fixed security tests

Signed-off-by: Raj Chakravarthi <raj@icedome.ca>
(cherry picked from commit c51940f)

---------

Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com>
Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
Signed-off-by: Raj Chakravarthi <raj@icedome.ca>
Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
Co-authored-by: Stevan Buzejic <30922513+stevanbz@users.noreply.github.com>
Co-authored-by: Surya Sashank Nistala <snistala@amazon.com>
Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
Co-authored-by: RAJ CHAKRAVARTHI <49325334+raj-chak@users.noreply.github.com>
Co-authored-by: Subhobrata Dey <sbcd90@gmail.com>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: AWSHurneyt <hurneyt@amazon.com>
Co-authored-by: RAJ CHAKRAVARTHI <raj@icedome.ca>
AWSHurneyt added a commit that referenced this pull request Jun 8, 2023
* [Backport 2.x] QueryIndex rollover when field mapping limit is reached (#729)

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* log error messages and clean up monitor when indexing doc level queries or metadata creation fails (#900) (#912)

* log errors and clean up monitor when indexing doc level queries or metadata creation fails
* refactor delete monitor action to re-use delete methods
Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* [Backport 2.x] Notification security fix (#861)

* Notification security fix (#852)

* added injecting whole user object in threadContext before calling notification APIs so that backend roles are available to notification plugin

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* compile fix

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* refactored user_info injection to use InjectSecurity

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* ktlint fix

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

---------

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
(cherry picked from commit e0b7a5a)

* remove unneeded import

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>

---------

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
Co-authored-by: Ashish Agrawal <ashisagr@amazon.com>
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* Added missing imports.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* Multiple indices support in DocLevelMonitorInput (#784) (#808)

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>

* Removed redundant calls to initDocLevelQueryIndex and indexDocLevelQueries.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* Fixed a bug that prevented alerts from being generated for doc level monitors that use wildcard characters in index names. (#894) (#902)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)

Co-authored-by: AWSHurneyt <hurneyt@amazon.com>
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* Resolved backport issue for PR 729.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* Resolved backport issue for PR 758.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

---------

Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
Co-authored-by: Surya Sashank Nistala <snistala@amazon.com>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: Ashish Agrawal <ashisagr@amazon.com>
lezzago pushed a commit that referenced this pull request Aug 2, 2023
…monitors that use wildcard characters in index names. (#894) (#903)

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
(cherry picked from commit 8c033b9)

Co-authored-by: AWSHurneyt <hurneyt@amazon.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.

3 participants