Skip to content

[Response Ops][Alerting] Cannot read properties of undefined (reading 'getActiveCount')#221799

Merged
doakalexi merged 11 commits intoelastic:mainfrom
doakalexi:fix-undefined-alert-getting-active-count
Jun 17, 2025
Merged

[Response Ops][Alerting] Cannot read properties of undefined (reading 'getActiveCount')#221799
doakalexi merged 11 commits intoelastic:mainfrom
doakalexi:fix-undefined-alert-getting-active-count

Conversation

@doakalexi
Copy link
Contributor

@doakalexi doakalexi commented May 28, 2025

Resolves #208740

Summary

This error message comes from the code where we drop the oldest recovered alerts from being tracked in the task state when there are more than 1000 (or alert limit) recovered alerts. The flapping refactor fixed this specific error, but I noticed that the alert documents weren't being updated before the alerts were dropped. This PR just moves this logic to the function that gets all the alerts to serialize in the task state, which happens after the alert documents are updated.

Checklist

Check the PR satisfies following conditions.

To verify

  1. Set xpack.alerting.rules.run.alerts.max: 3 in kibana.yml
  2. Start kibana and create a rule that will generate 3 alerts
  3. Stop kibana and set the max alert limit to 2 in kibana.yml
  4. Start kibana and update the conditions to recover the alerts. Because there are 3 alerts recovering and we can only track 2, one alert will be dropped from the task state.
  5. Verify that all the alerts are marked as recovered. Let the rule run to verify that one of the alert's alert document is no longer updated.

@doakalexi doakalexi changed the title Updating code and tests for dropping tracked covered alerts at the al… [Response Ops][Alerting] Cannot read properties of undefined (reading 'getActiveCount') May 28, 2025
@doakalexi doakalexi added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v9.1.0 v8.19.0 labels Jun 5, 2025
@doakalexi doakalexi marked this pull request as ready for review June 6, 2025 15:17
@doakalexi doakalexi requested a review from a team as a code owner June 6, 2025 15:17
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@doakalexi doakalexi requested review from umbopepato and ymao1 June 6, 2025 15:17
@doakalexi doakalexi added the backport:version Backport to applied version labels label Jun 6, 2025
@doakalexi doakalexi marked this pull request as draft June 6, 2025 17:11
@doakalexi
Copy link
Contributor Author

I put this back to draft because the new test is failing. I will take a look, sorry for the noise

@doakalexi doakalexi marked this pull request as ready for review June 12, 2025 14:12
@doakalexi doakalexi requested a review from a team as a code owner June 12, 2025 14:12
Copy link
Contributor

@jbudz jbudz left a comment

Choose a reason for hiding this comment

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

.buildkite/ftr_platform_stateful_configs.yml LGTM

'--xpack.alerting.invalidateApiKeysTask.removalDelay="1s"',
'--xpack.alerting.healthCheck.interval="1s"',
'--xpack.alerting.rules.minimumScheduleInterval.value="1s"',
'--xpack.alerting.rules.run.alerts.max=110',
Copy link
Contributor

Choose a reason for hiding this comment

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

this was set to > 100 to test the maintenance window top hits fix :)

Copy link
Contributor

Choose a reason for hiding this comment

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

oh i see, you're configuring it now. all good

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
@kbn/test-suites-xpack-platform 340 341 +1

Total ESLint disabled count

id before after diff
@kbn/test-suites-xpack-platform 344 345 +1

History

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM

@doakalexi doakalexi merged commit fff8ae9 into elastic:main Jun 17, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/15697981627

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 221799

Questions ?

Please refer to the Backport tool documentation

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 19, 2025
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 221799 locally
cc: @doakalexi

2 similar comments
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 221799 locally
cc: @doakalexi

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 221799 locally
cc: @doakalexi

@doakalexi
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

doakalexi added a commit to doakalexi/kibana that referenced this pull request Jun 23, 2025
… 'getActiveCount') (elastic#221799)

Resolves elastic#208740

## Summary

This error message comes from the code where we drop the oldest
recovered alerts from being tracked in the task state when there are
more than 1000 (or alert limit) recovered alerts. The flapping refactor
fixed this specific error, but I noticed that the alert documents
weren't being updated before the alerts were dropped. This PR just moves
this logic to the function that gets all the alerts to serialize in the
task state, which happens after the alert documents are updated.

### Checklist

Check the PR satisfies following conditions.

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### To verify
1. Set `xpack.alerting.rules.run.alerts.max: 3` in kibana.yml
2. Start kibana and create a rule that will generate 3 alerts
3. Stop kibana and set the max alert limit to 2 in kibana.yml
4. Start kibana and update the conditions to recover the alerts. Because
there are 3 alerts recovering and we can only track 2, one alert will be
dropped from the task state.
5. Verify that all the alerts are marked as recovered. Let the rule run
to verify that one of the alert's alert document is no longer updated.

(cherry picked from commit fff8ae9)
doakalexi added a commit that referenced this pull request Jun 23, 2025
…reading 'getActiveCount') (#221799) (#224881)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Response Ops][Alerting] Cannot read properties of undefined (reading
'getActiveCount')
(#221799)](#221799)

<!--- Backport version: 10.0.1 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Alexi
Doak","email":"109488926+doakalexi@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-06-17T04:13:36Z","message":"[Response
Ops][Alerting] Cannot read properties of undefined (reading
'getActiveCount') (#221799)\n\nResolves
https://github.com/elastic/kibana/issues/208740\n\n## Summary\n\nThis
error message comes from the code where we drop the oldest\nrecovered
alerts from being tracked in the task state when there are\nmore than
1000 (or alert limit) recovered alerts. The flapping refactor\nfixed
this specific error, but I noticed that the alert documents\nweren't
being updated before the alerts were dropped. This PR just moves\nthis
logic to the function that gets all the alerts to serialize in the\ntask
state, which happens after the alert documents are updated.\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\n- [ ]
[Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n\n### To verify\n1.
Set `xpack.alerting.rules.run.alerts.max: 3` in kibana.yml\n2. Start
kibana and create a rule that will generate 3 alerts\n3. Stop kibana and
set the max alert limit to 2 in kibana.yml\n4. Start kibana and update
the conditions to recover the alerts. Because\nthere are 3 alerts
recovering and we can only track 2, one alert will be\ndropped from the
task state.\n5. Verify that all the alerts are marked as recovered. Let
the rule run\nto verify that one of the alert's alert document is no
longer
updated.","sha":"fff8ae9bcce73d6ae7a76ec4a9fd75babc08c5bf","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport
missing","backport:version","v9.1.0","v8.19.0"],"title":"[Response
Ops][Alerting] Cannot read properties of undefined (reading
'getActiveCount')","number":221799,"url":"https://github.com/elastic/kibana/pull/221799","mergeCommit":{"message":"[Response
Ops][Alerting] Cannot read properties of undefined (reading
'getActiveCount') (#221799)\n\nResolves
https://github.com/elastic/kibana/issues/208740\n\n## Summary\n\nThis
error message comes from the code where we drop the oldest\nrecovered
alerts from being tracked in the task state when there are\nmore than
1000 (or alert limit) recovered alerts. The flapping refactor\nfixed
this specific error, but I noticed that the alert documents\nweren't
being updated before the alerts were dropped. This PR just moves\nthis
logic to the function that gets all the alerts to serialize in the\ntask
state, which happens after the alert documents are updated.\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\n- [ ]
[Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n\n### To verify\n1.
Set `xpack.alerting.rules.run.alerts.max: 3` in kibana.yml\n2. Start
kibana and create a rule that will generate 3 alerts\n3. Stop kibana and
set the max alert limit to 2 in kibana.yml\n4. Start kibana and update
the conditions to recover the alerts. Because\nthere are 3 alerts
recovering and we can only track 2, one alert will be\ndropped from the
task state.\n5. Verify that all the alerts are marked as recovered. Let
the rule run\nto verify that one of the alert's alert document is no
longer
updated.","sha":"fff8ae9bcce73d6ae7a76ec4a9fd75babc08c5bf"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/221799","number":221799,"mergeCommit":{"message":"[Response
Ops][Alerting] Cannot read properties of undefined (reading
'getActiveCount') (#221799)\n\nResolves
https://github.com/elastic/kibana/issues/208740\n\n## Summary\n\nThis
error message comes from the code where we drop the oldest\nrecovered
alerts from being tracked in the task state when there are\nmore than
1000 (or alert limit) recovered alerts. The flapping refactor\nfixed
this specific error, but I noticed that the alert documents\nweren't
being updated before the alerts were dropped. This PR just moves\nthis
logic to the function that gets all the alerts to serialize in the\ntask
state, which happens after the alert documents are updated.\n\n\n###
Checklist\n\nCheck the PR satisfies following conditions. \n\n- [ ]
[Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n\n### To verify\n1.
Set `xpack.alerting.rules.run.alerts.max: 3` in kibana.yml\n2. Start
kibana and create a rule that will generate 3 alerts\n3. Stop kibana and
set the max alert limit to 2 in kibana.yml\n4. Start kibana and update
the conditions to recover the alerts. Because\nthere are 3 alerts
recovering and we can only track 2, one alert will be\ndropped from the
task state.\n5. Verify that all the alerts are marked as recovered. Let
the rule run\nto verify that one of the alert's alert document is no
longer
updated.","sha":"fff8ae9bcce73d6ae7a76ec4a9fd75babc08c5bf"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Response Ops][Alerting] Cannot read properties of undefined (reading 'getActiveCount')

5 participants