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

Adds support for using findings from list of monitors as input data for a monitor in workflow #1112

Merged
merged 4 commits into from
Sep 2, 2023

Conversation

eirsep
Copy link
Member

@eirsep eirsep commented Sep 1, 2023

Adds support for using a list monitor ids in chained monitor findings. This helps use input data for a monitor in workflow based on doc ids from findings of multiple monitors instead of a single monitor.

If workflow sequence looks like:
[m1] -> [m2] -> [m3 (chained findings of m1, m2)]
this means m3's data input would be the related doc ids from findings of m1 and m2.

In a given workflow execution the following scenarios may occur:
Scenario 1:
if m1 has findings related to docs 1,2,3 of "index1"
if m2 has findings related to docs 3,4,5 of "index1"
m3's source data would be docs 1,2,3,4,5 of index 1

Scenario 2:
if m1 has findings related to docs 1,2,3 of "index1"
if m2 has findings related to docs 3,4,5 of "index2"
m3's source data would be docs 1,2,3 of "index1" and "index2"

Scenario 3:
if m1 has findings related to docs 1,2,3 of "index1"
if m2 has no findings
m3's source data would be docs 1,2,3 of "index1"

for backward compatibility reasons, the monitorId field would be given preference over the new list type field, monitorIds, if both are provided.

…or in workflow

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
@eirsep eirsep changed the title support using findings from list ofmonitors as input data for a monitor in workflow Adds support for using findings from list ofmonitors as input data for a monitor in workflow Sep 1, 2023
@lezzago
Copy link
Member

lezzago commented Sep 1, 2023

Please add the description piece for the PR

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
@lezzago lezzago changed the title Adds support for using findings from list ofmonitors as input data for a monitor in workflow Adds support for using findings from list of monitors as input data for a monitor in workflow Sep 1, 2023
try {
val existsResponse: IndicesExistsResponse = client.admin().indices().suspendUntil {
exists(IndicesExistsRequest(chainedMonitor.dataSources.findingsIndex).local(true), it)
exists(IndicesExistsRequest(dataSources.findingsIndex).local(true), it)
}
if (existsResponse.isExists == false) return emptyMap()
// Search findings index per monitor and workflow execution id
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: update description since this is not for a single monitor anymore.

@@ -38,17 +38,26 @@ class WorkflowService(
* Returns finding doc ids per index for the given workflow execution
* Used for pre-filtering the dataset in the case of creating a workflow with chained findings
*
* @param chainedMonitor Monitor that is previously executed
* @param chainedMonitors Monitor that is previously executed
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: update comment to indicate Monitors that have previously executed.

indexDoc(index, "2", testDoc2)

testTime = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS))
// Doesn't match
Copy link
Member

Choose a reason for hiding this comment

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

this would still match monitor 2, right?

assertEquals(3, monitorsRunResults.size)
assertFindings(monitorResponse.id, customFindingsIndex1, 2, 2, listOf("1", "2"))
assertFindings(monitorResponse2.id, customFindingsIndex1, 2, 2, listOf("2", "3"))
assertFindings(monitorResponse3.id, customFindingsIndex1, 3, 3, listOf("1", "2", "3"))
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't monitor 3 only execute on document 2 since it takes an input from monitor 1 and 2 and they only both would generate findings from document 2?

Copy link
Member Author

Choose a reason for hiding this comment

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

We would do union of 2 sets here not intersection.

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
@eirsep eirsep merged commit 7b9584c into opensearch-project:main Sep 2, 2023
12 of 14 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Sep 2, 2023
…or a monitor in workflow (#1112)

* support using findings from list ofmonitors as input data for a monitor in workflow

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>

* update exception message assertion in test

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>

* fix code comments in tests and source code

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>

* fix grammar in code comment

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>

---------

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
(cherry picked from commit 7b9584c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
eirsep pushed a commit that referenced this pull request Sep 7, 2023
…or a monitor in workflow (#1112) (#1113)

* support using findings from list ofmonitors as input data for a monitor in workflow



* update exception message assertion in test



* fix code comments in tests and source code



* fix grammar in code comment



---------


(cherry picked from commit 7b9584c)

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
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>
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