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

[APM] Cleanup alerting api tests #164438

Merged
merged 10 commits into from
Aug 24, 2023

Conversation

sorenlouv
Copy link
Member

@sorenlouv sorenlouv commented Aug 22, 2023

This PR cleans up and refactors the APM API tests for rules and alerting.

  • introduces some new helper methods like deleteRuleById
  • test all template variables using the index connector
  • improve flaky tests and ensure that tests can be run in isolation and in any order

@sorenlouv sorenlouv requested a review from a team as a code owner August 22, 2023 12:12
@botelastic botelastic bot added the Team:APM All issues that need APM UI Team support label Aug 22, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:APM)

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

Comment on lines -85 to -88
await supertest.delete(`/api/alerting/rule/${ruleId1}`).set('kbn-xsrf', 'foo');
await supertest.delete(`/api/actions/connector/${actionId1}`).set('kbn-xsrf', 'foo');
await supertest.delete(`/api/alerting/rule/${ruleId2}`).set('kbn-xsrf', 'foo');
await supertest.delete(`/api/actions/connector/${actionId2}`).set('kbn-xsrf', 'foo');
Copy link
Member Author

@sorenlouv sorenlouv Aug 22, 2023

Choose a reason for hiding this comment

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

This is problematic: rules and alerts are created per test but not deleted until all tests have run. This means that the rules and alerts created in the first test still exists when running the second test. This means that tests are required to run in a specific order, and it is not possible to run tests in isolation.

This was changed so rules and alerts are created per test, and also removed after each individual test. This ensures that subsequent tests are not polluted with state created in previous tests.

Comment on lines 106 to 110
actionId1 = await createIndexConnector({
supertest,
name: 'Transation error rate without filter query',
indexName: ALERT_ACTION_INDEX_NAME1,
});
Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed all reference to the index connector action. We don't need it to test whether an alert was produced since we can just query the alerts index directly

Copy link
Contributor

Choose a reason for hiding this comment

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

There are two things that we are testing:

  • whether an alert is triggered (and shown in Kibana UI).
  • alert notification was sent (with index connector in this case) with correct action variables.

I think the tests to check alert notifications are useful.

Copy link
Member Author

@sorenlouv sorenlouv Aug 22, 2023

Choose a reason for hiding this comment

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

alert notification was sent (with index connector in this case) with correct action variables.

Are we testing the APM rule in this case, or the connector functionality (and thus the alerting framework). By exercising the indexing connector it sounds like we are testing the latter where we should focus on the former.

Copy link
Member Author

Choose a reason for hiding this comment

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

.. or put another way: what is currently not covered anymore? What could break in the APM rule that would no longer go noticed?

Copy link
Contributor

Choose a reason for hiding this comment

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

We are setting context action variables during rule execution https://github.com/elastic/kibana/blob/f7e36a96d035e1cb4feec334a3bab270be9eac4e/x-pack/plugins/apm/server/routes/alerts/rule_types/transaction_duration/register_transaction_duration_rule_type.ts#L288C69-L288C69.

In the tests, we are checking if the action variables are set correctly in alert notification. Without it, any changes around context action variables would not be checked anymore.

Comment on lines -169 to -170
alertId = (resp.hits.hits[0]._source as any)['kibana.alert.uuid'];
startedAt = (resp.hits.hits[0]._source as any)['kibana.alert.start'];
Copy link
Member Author

Choose a reason for hiding this comment

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

This was also problematic: a variable was set in one test and consumed in another. This means that tests depend on each other and cannot be run in isolation.

const serviceInventoryAlertCounts = await fetchServiceInventoryAlertCounts(apmApiClient);
expect(serviceInventoryAlertCounts).to.eql({
'opbeans-node': 1,
'opbeans-java': 1,
'opbeans-java': 0,
Copy link
Member Author

Choose a reason for hiding this comment

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

This was an incorrect assertion caused by the alert pollution. Now alerts are cleaned up between runs.

@sorenlouv sorenlouv force-pushed the apm-alerting-improvements branch from daa0e75 to 3ca87f3 Compare August 22, 2023 13:12
@sorenlouv sorenlouv added v8.11.0 release_note:skip Skip the PR/issue when compiling release notes labels Aug 22, 2023
Copy link
Contributor

@benakansara benakansara left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for addressing the issues and cleaning up the tests.
As discussed offline, tests around context variables will be added in a separate PR.

Copy link
Contributor

@kpatticha kpatticha left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for pushing this work forward. I left only 2 comments.

Also, have you run the flaky test runner?

@sorenlouv
Copy link
Member Author

sorenlouv commented Aug 23, 2023

@sorenlouv sorenlouv force-pushed the apm-alerting-improvements branch from 953aa0c to 0927bcd Compare August 23, 2023 22:57
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

History

  • 💔 Build #152969 failed 953aa0c39fc32baa903995304c7a4722bd771f39
  • 💔 Build #152892 failed e24caf570e61e8ea26b9e245a33d5339c4f993c7
  • 💔 Build #152776 failed 87dddd3bb2b28373814f0739ceb832cc0aa5db3e
  • 💚 Build #152381 succeeded 981116f87338a6885dc8700ae0d7e34692f68418

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@sorenlouv sorenlouv merged commit d440288 into elastic:main Aug 24, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Aug 24, 2023
@sorenlouv sorenlouv deleted the apm-alerting-improvements branch August 24, 2023 00:22
jloleysens added a commit that referenced this pull request Aug 24, 2023
* main: (3152 commits)
  [Security Solution][Detection Engine] fixes 410 error on index legacy template call (#164682)
  [SavedObjects] Create serverless roots for jest integration tests (#164157)
  Create upselling package and implement EntityAnalytics serverless upselling (#164136)
  [Fleet] Change 'Out-of-date' to 'Outdated policy' in agent list table (#164673)
  [IndexManagement] Use internal base path for API (#164665)
  [Profiling] removing ~ symbol (#164595)
  [Telemetry] Fetch snapshot: allow specifying the version via querystring (#164670)
  [Cases] Show warning when all cases table reaches 10k cases message (#164323)
  [ML] Removing token list from text expansion model testing (#164560)
  [Fleet] Add secrets package API integration test (#164583)
  [Fleet] Fix security solution tag id (#164582)
  [Security Solution] Modal says "duplicating 0 rules" when you duplicate an individual rule (#163908)
  [api-docs] 2023-08-24 Daily api_docs build (#164658)
  [APM] Cleanup alerting api tests (#164438)
  Upgrade EUI to 87.2.0 (#164385)
  [ML] Fix query bar autocompletion for ML and AIOps embeddables (#164485)
  [Fleet] Fix flaky unit test for the details page (#164641)
  [Security Solution] update codeowner for serverless security subdir (#164640)
  [Security Solution] Fixes Assistant Connector and Actions RBAC Flow (#164382)
  [Discover] Removing large string truncation from doc viewer (#164236)
  ...
@sorenlouv
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.10

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

Questions ?

Please refer to the Backport tool documentation

sorenlouv added a commit to sorenlouv/kibana that referenced this pull request Aug 26, 2023
This PR cleans up and refactors the APM API tests for rules and
alerting.

- introduces some new helper methods like `deleteRuleById`
- removes dependency on index actions to test alerts (we can just use
the alert index)
- improve flaky tests and ensure that tests can be run in isolation and
in any order

(cherry picked from commit d440288)
@sorenlouv
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.10

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

Questions ?

Please refer to the Backport tool documentation

@sorenlouv
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.10

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

Questions ?

Please refer to the Backport tool documentation

@sorenlouv
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.10

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

Questions ?

Please refer to the Backport tool documentation

@sorenlouv
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.10

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

Questions ?

Please refer to the Backport tool documentation

sorenlouv added a commit to sorenlouv/kibana that referenced this pull request Aug 26, 2023
This PR cleans up and refactors the APM API tests for rules and
alerting.

- introduces some new helper methods like `deleteRuleById`
- removes dependency on index actions to test alerts (we can just use
the alert index)
- improve flaky tests and ensure that tests can be run in isolation and
in any order

(cherry picked from commit d440288)
@sorenlouv
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.10

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

Questions ?

Please refer to the Backport tool documentation

@sorenlouv
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.10

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

Questions ?

Please refer to the Backport tool documentation

sorenlouv added a commit to sorenlouv/kibana that referenced this pull request Aug 26, 2023
This PR cleans up and refactors the APM API tests for rules and
alerting.

- introduces some new helper methods like `deleteRuleById`
- removes dependency on index actions to test alerts (we can just use
the alert index)
- improve flaky tests and ensure that tests can be run in isolation and
in any order

(cherry picked from commit d440288)
@sorenlouv sorenlouv added auto-backport Deprecated - use backport:version if exact versions are needed v8.10.0 labels Aug 26, 2023
kibanamachine pushed a commit that referenced this pull request Aug 26, 2023
This PR cleans up and refactors the APM API tests for rules and
alerting.

- introduces some new helper methods like `deleteRuleById`
- removes dependency on index actions to test alerts (we can just use
the alert index)
- improve flaky tests and ensure that tests can be run in isolation and
in any order

(cherry picked from commit d440288)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.10

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

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

kibanamachine added a commit that referenced this pull request Aug 27, 2023
# Backport

This will backport the following commits from `main` to `8.10`:
- [[APM] Cleanup alerting api tests
(#164438)](#164438)

<!--- Backport version: 8.9.7 -->

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

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-24T00:22:26Z","message":"[APM]
Cleanup alerting api tests (#164438)\n\nThis PR cleans up and refactors
the APM API tests for rules and\r\nalerting.\r\n\r\n- introduces some
new helper methods like `deleteRuleById`\r\n- removes dependency on
index actions to test alerts (we can just use\r\nthe alert index)\r\n-
improve flaky tests and ensure that tests can be run in isolation
and\r\nin any
order","sha":"d4402886a12e6c429d72f441ee988b384645fd57","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:APM","release_note:skip","backport:skip","auto-backport","v8.10.0","v8.11.0"],"number":164438,"url":"https://github.com/elastic/kibana/pull/164438","mergeCommit":{"message":"[APM]
Cleanup alerting api tests (#164438)\n\nThis PR cleans up and refactors
the APM API tests for rules and\r\nalerting.\r\n\r\n- introduces some
new helper methods like `deleteRuleById`\r\n- removes dependency on
index actions to test alerts (we can just use\r\nthe alert index)\r\n-
improve flaky tests and ensure that tests can be run in isolation
and\r\nin any
order","sha":"d4402886a12e6c429d72f441ee988b384645fd57"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164438","number":164438,"mergeCommit":{"message":"[APM]
Cleanup alerting api tests (#164438)\n\nThis PR cleans up and refactors
the APM API tests for rules and\r\nalerting.\r\n\r\n- introduces some
new helper methods like `deleteRuleById`\r\n- removes dependency on
index actions to test alerts (we can just use\r\nthe alert index)\r\n-
improve flaky tests and ensure that tests can be run in isolation
and\r\nin any
order","sha":"d4402886a12e6c429d72f441ee988b384645fd57"}}]}] BACKPORT-->

Co-authored-by: Søren Louv-Jansen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support v8.10.0 v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants