Repository navigation
test: Correct the cause recorded for the acknowledged-alert test and drop the redundant action - #2316
Conversation
…the redundant action Addresses review feedback on opensearch-project#2315. The comment that PR added named the wrong cause and the fix carried a second change that was not needed. PER_EXECUTION actions do advance lastNotificationTime: that branch adds every deduped, new and completed alert to alertsToUpdate (BucketLevelMonitorRunner.kt:395-409), so an all-PER_EXECUTION trigger was never the problem. The actual cause is that randomActionsForBucketLevelTrigger(min = 1) returned an empty list, and randomBucketLevelTrigger replaces an empty actions list with freshly generated ones (TestHelpers.kt:370). Those never pass through the rewrite the test applies, so a PER_ALERT policy without COMPLETED reaches the trigger; at the seed from the original failure the regenerated actions were [PerAlertActionScope{DEDUPED}, PerAlertActionScope{}]. Making min a floor therefore fixes this on its own. The PER_ALERT action opensearch-project#2315 prepended is removed: it was justified by the wrong explanation, and because it guaranteed a PER_ALERT action carrying COMPLETED on every run, it stopped this test from ever exercising an all-PER_EXECUTION trigger. It also duplicated the ActionExecutionPolicy expression within one statement. Verified with the prepend removed: the test passes at the seed from the original failing CI job (F63F1F740575292F, locale ki, timezone ACT) and on 10 further random seeds, 10/10. ktlint clean. The KDoc now also warns that an empty result is not harmless for callers that post-process it, which is the trap that produced the original failure. Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (67.71%) is below the target coverage (70.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2316 +/- ##
============================================
- Coverage 67.72% 67.71% -0.02%
- Complexity 105 1795 +1690
============================================
Files 160 169 +9
Lines 10343 14269 +3926
Branches 1522 2077 +555
============================================
+ Hits 7005 9662 +2657
- Misses 2672 3728 +1056
- Partials 666 879 +213 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| // The rewrite below has to leave a non-empty list. randomBucketLevelTrigger replaces an empty | ||
| // actions list with freshly generated ones, and those never pass through this rewrite, so a | ||
| // PER_ALERT policy without COMPLETED can reach the trigger and leave the completed alert's | ||
| // lastNotificationTime untouched. |
There was a problem hiding this comment.
nit: Regenerated actions can also lack DEDUPED (e.g. PerAlertActionScope{NEW}), and then the test fails earlier, at "Active alert was not updated", rather than at the completed-alert check. Maybe: "...so a PER_ALERT policy missing DEDUPED or COMPLETED can reach the trigger and leave lastNotificationTime untouched."
| // actions list with freshly generated ones, and those never pass through this rewrite, so a | ||
| // PER_ALERT policy without COMPLETED can reach the trigger and leave the completed alert's | ||
| // lastNotificationTime untouched. | ||
| val actions = randomActionsForBucketLevelTrigger(min = 1).map { |
There was a problem hiding this comment.
nit: The non-empty guarantee the comment above depends on lives in the helper's maxOf(min, 1), which the description suggests revisiting. An assertTrue(actions.isNotEmpty()) after building actions would make this test fail clearly instead of flaking again if that helper changes.
Description
Follow-up to #2315, addressing @lezzago's review. That PR recorded the wrong cause and carried a
second change that was not needed.
The explanation was wrong. PER_EXECUTION actions do advance
lastNotificationTime— that branchadds every deduped, new and completed alert to
alertsToUpdate(
BucketLevelMonitorRunner.kt:395-409). An all-PER_EXECUTION trigger was never the problem, and thecomment #2315 left in the test said it was.
The actual cause is that
randomActionsForBucketLevelTrigger(min = 1)returned an empty list, andrandomBucketLevelTriggerreplaces an empty actions list with freshly generated ones(
TestHelpers.kt:370):Those regenerated actions never pass through the rewrite the test applies, so a PER_ALERT policy
without
COMPLETEDreaches the trigger. At the seed from the original failure they were[PerAlertActionScope{DEDUPED}, PerAlertActionScope{}].Change
Making
mina floor — the other half of #2315 — fixes this on its own, so the PER_ALERT action that PRprepended is removed. Besides being unnecessary, it guaranteed a PER_ALERT action carrying
COMPLETEDon every run, which stopped this test from ever exercising an all-PER_EXECUTION trigger: it narrowed
coverage to buy nothing. It also duplicated the
ActionExecutionPolicyexpression within one statement.The test comment now states the real cause, and the helper's KDoc warns that an empty result is not
harmless for callers that post-process it, since that is the trap behind the original failure.
Testing
With the prepend removed:
F63F1F740575292F, localeki, timezoneACT)ktlintclean. No production code is touched.Still open
maxOf(min, 1)means an explicitmin = 0can no longer yield zero actions, which the PR bot flaggedon #2315. Given
TestHelpers.kt:370treats an empty list as "regenerate", zero actions is notreachable through
randomBucketLevelTriggereither way. Making it genuinely reachable means stoppingthat silent regeneration, which changes every caller's action distribution and belongs in its own
change rather than here.
Check List
--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.