Skip to content

[APM] Cleanup alerting api tests#164438

Merged
sorenlouv merged 10 commits intoelastic:mainfrom
sorenlouv:apm-alerting-improvements
Aug 24, 2023
Merged

[APM] Cleanup alerting api tests#164438
sorenlouv merged 10 commits intoelastic:mainfrom
sorenlouv:apm-alerting-improvements

Conversation

@sorenlouv
Copy link
Copy Markdown
Contributor

@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 August 22, 2023 12:12
@botelastic botelastic bot added the Team:APM - DEPRECATED Use Team:obs-ux-infra_services. label Aug 22, 2023
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@ghost
Copy link
Copy Markdown

ghost commented Aug 22, 2023

🤖 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
Copy link
Copy Markdown
Contributor 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
Copy link
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy link
Copy Markdown
Contributor 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.

Copy link
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown

💛 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 PR 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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
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":"soren.louv@elastic.co"},"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 <soren.louv@elastic.co>
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 PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:APM - DEPRECATED Use Team:obs-ux-infra_services. v8.10.0 v8.11.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants