Skip to content

Populate results and trigggeredDocs field in document level trigger execution context #496

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

Closed
wants to merge 1 commit into from

Conversation

eirsep
Copy link
Member

@eirsep eirsep commented Jul 23, 2022

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

Issue #, if available:
#479

Description of changes:
Populate results and trigggeredDocs field in document level trigger execution context.

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.

@eirsep eirsep requested a review from a team July 23, 2022 00:12
@eirsep eirsep marked this pull request as draft July 23, 2022 00:12
@eirsep eirsep force-pushed the fix-doc-ctx branch 3 times, most recently from 17f1695 to 490ec84 Compare July 23, 2022 02:45
@codecov-commenter
Copy link

codecov-commenter commented Jul 23, 2022

Codecov Report

Merging #496 (b2e484e) into main (9f3c393) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##               main     #496      +/-   ##
============================================
- Coverage     76.75%   76.71%   -0.04%     
  Complexity      176      176              
============================================
  Files           166      166              
  Lines          8370     8370              
  Branches       1232     1232              
============================================
- Hits           6424     6421       -3     
- Misses         1342     1343       +1     
- Partials        604      606       +2     
Impacted Files Coverage Δ
.../opensearch/alerting/DocumentLevelMonitorRunner.kt 81.85% <100.00%> (ø)
...ing/script/DocumentLevelTriggerExecutionContext.kt 100.00% <100.00%> (ø)
...ing/model/destination/DestinationContextFactory.kt 75.00% <0.00%> (-3.58%) ⬇️
...nationmigration/DestinationMigrationCoordinator.kt 61.70% <0.00%> (-2.13%) ⬇️
...ain/kotlin/org/opensearch/alerting/AlertService.kt 77.99% <0.00%> (-0.48%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us.

@eirsep eirsep marked this pull request as ready for review July 25, 2022 18:17
@eirsep eirsep requested a review from lezzago July 25, 2022 18:36
@lezzago
Copy link
Member

lezzago commented Jul 25, 2022

Please create an IT test that checks the action output of the message to ensure we get data from results.
In this test, we are validating if notification message and we would need to do something similar for this PR.

@eirsep
Copy link
Member Author

eirsep commented Jul 26, 2022

Please create an IT test that checks the action output of the message to ensure we get data from results. In this test, we are validating if notification message and we would need to do something similar for this PR.

Added a test to verify that we are seeing results in the alert action output.

@Suppress("UNCHECKED_CAST") val actionOutput = (actionResult as Map<String, Map<String, String>>)["output"]
as Map<String, String>
assertTrue(actionOutput["subject"].toString().contains(docQuery.id))
assertTrue(actionOutput["subject"].toString().contains(docQuery.id))
Copy link
Member

Choose a reason for hiding this comment

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

Check the message as well since subject is being checked twice.

@eirsep eirsep requested a review from lezzago July 26, 2022 18:29
lezzago
lezzago previously approved these changes Jul 26, 2022
for (triggerResult in output.objectMap("trigger_results").values) {
assertEquals(1, triggerResult.objectMap("action_results").values.size)
for (alertActionResult in triggerResult.objectMap("action_results").values) {
for (actionResult in alertActionResult.values) {
Copy link
Member

Choose a reason for hiding this comment

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

What if alertActionResult.values is 0 or empty? We will never reach the below assertion?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added assertion.

monitor, trigger, emptyList(), Instant.now(), Instant.now(),
alerts, emptyList(), emptyList(), null
monitor, trigger, monitorRunResult.inputResults.results, monitorRunResult.periodStart, monitorRunResult.periodEnd,
alerts, emptyList(), emptyList(), monitorRunResult.scriptContextError(trigger)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to have a test to surface out the inputResults.error?

Copy link
Member

Choose a reason for hiding this comment

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

That is a good point, we should check if we get the expected data from there as well.

Copy link
Member

Choose a reason for hiding this comment

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

I believe we should have a follow up PR or in this PR to have tests to verify every part of the `ctx`` values.

Copy link
Member

Choose a reason for hiding this comment

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

Lets create an issue and tag it here

@@ -222,7 +222,7 @@ object DocumentLevelMonitorRunner : MonitorRunner() {
queryToDocIds: Map<DocLevelQuery, Set<String>>,
dryrun: Boolean
): DocumentLevelTriggerRunResult {
val triggerCtx = DocumentLevelTriggerExecutionContext(monitor, trigger)
val triggerCtx = DocumentLevelTriggerExecutionContext(monitor, trigger, monitorResult)
Copy link
Member

Choose a reason for hiding this comment

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

I think instead of the entire monitorResult, we should rather have the triggerResults set as part of the context for the actions. In DocumentLevelAlerting the two could be different, as trigger results are the final set of document ids sent for alert, post the trigger condition evaluation.

cc: @lezzago

Copy link
Member

Choose a reason for hiding this comment

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

Oh that is a good point. I was thinking it to be more in line with the other monitor types and have this as the monitor result instead of the trigger result since that is what the other monitors seem to do.

Copy link
Member

Choose a reason for hiding this comment

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

I agree now that we should use trigger results. The other monitor types did not do this because the trigger results from those other monitor types did not have the granularity and useful information.

Copy link
Member

Choose a reason for hiding this comment

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

This still needs to address below two concerns - could also be discussed with product for requirements:

  1. The monitorResult returned as part of the ctx during the Alerts is the combination of all the documents before the trigger was executed. Since this result ignores the trigger logic and will be repeated across all the Alerts, for the users it could be challenging to map the actual documents which led to those specific Alerts.

  2. We also introduced related_doc_ids as part of the Alerts record, and it is specific to Doc Level Alerts. Since it holds the final result for document Id matching the Alerts, it is more contextual information. However, it introduces an inconsistency for how the users are expected to fetch these compared to other monitor type.

My proposal would be to deprecate related_doc_ids in Alerts record slowly, whole have the ctx hold the documents id specific to those alerts (post trigger execution).

@lezzago lezzago self-requested a review July 27, 2022 00:00
@eirsep eirsep force-pushed the fix-doc-ctx branch 5 times, most recently from a40837c to 76680d9 Compare August 3, 2022 22:33
@eirsep
Copy link
Member Author

eirsep commented Aug 3, 2022

@lezzago I have attached the output of successfully running alerting integ test task as I am blocked on the infra issue in opensearch plugins

% ./gradlew :alerting:integTest
=======================================
OpenSearch Build Hamster says Hello!
  Gradle Version        : 7.4.2
  OS Info               : Linux 5.4.196-119.356.amzn2int.x86_64 (amd64)
  JDK Version           : 14 (Oracle JDK)
  JAVA_HOME             : /opt/jdk-14
  Random Testing Seed   : 9424B7CF3E963F4B
  In FIPS 140 mode      : false
=======================================

> Task :alerting-core:compileKotlin
w: /local/home/snistala/opensearch/alerting/core/src/main/kotlin/org/opensearch/alerting/core/action/node/ScheduledJobsStatsTransportAction.kt: (11, 44): 'BaseNodeRequest' is deprecated. Deprecated in Java
w: /local/home/snistala/opensearch/alerting/core/src/main/kotlin/org/opensearch/alerting/core/action/node/ScheduledJobsStatsTransportAction.kt: (119, 39): 'BaseNodeRequest' is deprecated. Deprecated in Java

> Task :alerting:compileKotlin
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt: (36, 9): The corresponding parameter in the supertype 'MonitorRunner' is named 'dryRun'. This may cause problems when calling this function with named arguments.
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt: (68, 9): The corresponding parameter in the supertype 'MonitorRunner' is named 'dryRun'. This may cause problems when calling this function with named arguments.
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt: (108, 60): Unchecked cast: MutableMap<String, Any> to MutableMap<String, MutableMap<String, Any>>
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt: (425, 59): Unnecessary non-null assertion (!!) on a non-null receiver of type ClusterService
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/QueryLevelMonitorRunner.kt: (28, 9): The corresponding parameter in the supertype 'MonitorRunner' is named 'dryRun'. This may cause problems when calling this function with named arguments.
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/model/DocumentLevelTriggerRunResult.kt: (34, 51): No cast needed
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/model/Finding.kt: (40, 40): Access to companion object through parenthesized class name is deprecated. Please, add explicit Companion qualifier.
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/model/Finding.kt: (90, 20): '@JvmOverloads' annotation has no effect for methods without default arguments
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/model/FindingWithDocs.kt: (28, 34): Access to companion object through parenthesized class name is deprecated. Please, add explicit Companion qualifier.
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/model/Monitor.kt: (113, 31): Access to companion object through parenthesized class name is deprecated. Please, add explicit Companion qualifier.
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/model/Monitor.kt: (114, 33): Access to companion object through parenthesized class name is deprecated. Please, add explicit Companion qualifier.
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/model/MonitorMetadata.kt: (57, 20): '@JvmOverloads' annotation has no effect for methods without default arguments
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/model/action/ActionExecutionScope.kt: (141, 17): Parameter 'sin' is never used
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/resthandler/RestIndexMonitorAction.kt: (87, 9): Non exhaustive 'when' statements on enum will be prohibited in 1.7, add 'CLUSTER_METRICS_MONITOR' branch or 'else' branch instead
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportIndexMonitorAction.kt: (524, 49): Unchecked cast: Map<String, Any> to MutableMap<String, MutableMap<String, Any>>
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt: (91, 29): Unchecked cast: Any? to Map<String, Map<String, Any>>
w: /local/home/snistala/opensearch/alerting/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt: (129, 33): Variable 'bulkResponse' is never used

> Task :alerting:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :alerting:compileTestKotlin
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/DocumentMonitorRunnerIT.kt: (503, 13): Variable 'searchResult' is never used
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/DocumentMonitorRunnerIT.kt: (542, 13): Variable 'searchResult' is never used
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/DocumentMonitorRunnerIT.kt: (595, 13): Variable 'searchResult' is never used
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/DocumentMonitorRunnerIT.kt: (656, 13): Variable 'searchResult' is never used
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregatorTests.kt: (102, 17): 'assertThat(T!, Matcher<in T!>!): Unit' is deprecated. Deprecated in Java
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregatorTests.kt: (162, 17): 'assertThat(T!, Matcher<in T!>!): Unit' is deprecated. Deprecated in Java
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregatorTests.kt: (183, 17): 'assertThat(T!, Matcher<in T!>!): Unit' is deprecated. Deprecated in Java
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregatorTests.kt: (226, 17): 'assertThat(T!, Matcher<in T!>!): Unit' is deprecated. Deprecated in Java
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregatorTests.kt: (270, 17): 'assertThat(T!, Matcher<in T!>!): Unit' is deprecated. Deprecated in Java
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregatorTests.kt: (318, 17): 'assertThat(T!, Matcher<in T!>!): Unit' is deprecated. Deprecated in Java
w: /local/home/snistala/opensearch/alerting/alerting/src/test/kotlin/org/opensearch/alerting/model/DocLevelMonitorInputTests.kt: (66, 13): Variable 'inputString' is never used

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 4m 40s
16 actionable tasks: 11 executed, 5 up-to-date


 % git status
HEAD detached at origin/fix-doc-ctx

@eirsep eirsep changed the title Populate results field in document level trigger execution context Populate results and trigggeredDocs field in document level trigger execution context Aug 3, 2022
@eirsep
Copy link
Member Author

eirsep commented Aug 4, 2022

@lezzago @getsaurabh02
I wasn't able to figure out a way to simulate a test which returns an error in the alert action context.

I will open an issue to add ITs to test

let's focus this PR on getting the result and triggered docs field in Document level monitoring. I have added tests for the same.

@eirsep eirsep dismissed lezzago’s stale review August 4, 2022 21:40

pushed new changes

@eirsep eirsep requested a review from getsaurabh02 August 4, 2022 21:40
…execution context

Signed-off-by: Surya Sashank Nistala <[email protected]>
@lezzago lezzago self-requested a review August 5, 2022 00:51
@eirsep
Copy link
Member Author

eirsep commented Jan 20, 2023

Will need to get input from the community on what is the best way to fix this issue. Closing PR until then

@eirsep eirsep closed this Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants