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

[AO] Add API integration test scenarios to the Threshold rule #162501

Conversation

fkanout
Copy link
Contributor

@fkanout fkanout commented Jul 25, 2023

Summary

It fixes #162491

@fkanout fkanout added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" v8.10.0 labels Jul 25, 2023
@fkanout fkanout self-assigned this Jul 25, 2023
@fkanout fkanout marked this pull request as ready for review July 25, 2023 15:31
@fkanout fkanout requested a review from a team as a code owner July 25, 2023 15:31
@elasticmachine
Copy link
Contributor

Pinging @elastic/actionable-observability (Team: Actionable Observability)

@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.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@fkanout fkanout requested a review from a team as a code owner July 27, 2023 14:24
@kibana-ci
Copy link
Collaborator

kibana-ci commented Jul 27, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #30 / security APIs - Kerberos Kerberos authentication API access with expired access token. post-authentication stage expired access token should be automatically refreshed by the start-contract client even for multiple concurrent requests
  • [job] [logs] FTR Configs #36 / security APIs - Kerberos Kerberos authentication API access with expired access token. post-authentication stage expired access token should be automatically refreshed by the start-contract client even for multiple concurrent requests
  • [job] [logs] FTR Configs #30 / security APIs - Kerberos Kerberos authentication API access with expired access token. post-authentication stage expired access token should be automatically refreshed by the start-contract client even for multiple concurrent requests
  • [job] [logs] FTR Configs #36 / security APIs - Kerberos Kerberos authentication API access with expired access token. post-authentication stage expired access token should be automatically refreshed by the start-contract client even for multiple concurrent requests
  • [job] [logs] FTR Configs #49 / security APIs - OIDC (Authorization Code Flow) OpenID Connect authentication API access with expired access token. post-authentication stage expired access token should be automatically refreshed by the start-contract client even for multiple concurrent requests
  • [job] [logs] FTR Configs #49 / security APIs - OIDC (Authorization Code Flow) OpenID Connect authentication API access with expired access token. post-authentication stage expired access token should be automatically refreshed by the start-contract client even for multiple concurrent requests
  • [job] [logs] FTR Configs #51 / security APIs - SAML SAML authentication API access with expired access token. should refresh access token even if multiple concurrent requests try to refresh it
  • [job] [logs] FTR Configs #51 / security APIs - SAML SAML authentication API access with expired access token. should refresh access token even if multiple concurrent requests try to refresh it
  • [job] [logs] FTR Configs #5 / security APIs - Token session API access with expired access token. post-authentication stage expired access token should be automatically refreshed by the start-contract client even for multiple concurrent requests
  • [job] [logs] FTR Configs #5 / security APIs - Token session API access with expired access token. post-authentication stage expired access token should be automatically refreshed by the start-contract client even for multiple concurrent requests
  • [job] [logs] FTR Configs #35 / Synthetics API Tests SyncGlobalParams added an integration for previously added monitor
  • [job] [logs] FTR Configs #35 / Synthetics API Tests SyncGlobalParams added an integration for previously added monitor
  • [job] [logs] FTR Configs #24 / task_manager check_registered_task_types should check changes on all registered task types
  • [job] [logs] FTR Configs #24 / task_manager check_registered_task_types should check changes on all registered task types

Metrics [docs]

✅ unchanged

History

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

cc @fkanout

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

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

LGTM, left a few comments ...

});

after(async () => {
await supertest.delete(`/api/alerting/rule/${ruleId}`).set('kbn-xsrf', 'foo');
Copy link
Member

Choose a reason for hiding this comment

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

We have a utility ObjectRemover which may simplify some of this sort of stuff - or not! Example usage here.

});

it('should be active', async () => {
const executionStatus = await waitForRuleStatus({
Copy link
Member

Choose a reason for hiding this comment

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

Kinda up to you, since you own these tests, but we generally treat each test as stand-alone, so that you could change it(... to it.only(... when diagnosing tests. I think we'd more generally write a function here to create the rule / connector, and call it from each test, and then delete it (somehow - ObjectRemover or other) in an afterEach().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pmuellr, thank you for the feedback!
I wrote these tests as a file-per-scenario as we are sharing the same tests in serverless and stateful env to maintain them easily (copy/paste 😄) with minimum dependencies until we can share one test suite across ENVs (agnostic tests)

Copy link
Member

Choose a reason for hiding this comment

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

Ya, will be interesting to see how serverless / stateful test sharing will go!

maintain them easily (copy/paste 😄)

Probably more of a risk of these being problematic, in that each test depends on the previous to work. Small number of tests here though, so hard to imagine it going wrong in this file, now. Something to think about if these get more complex.

Copy link
Member

@maryam-saeidi maryam-saeidi left a comment

Choose a reason for hiding this comment

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

Overall LGTM 👍🏻

Just added some clarification questions :)

timeSize: 1,
timeUnit: 'm',
customMetrics: [
{ name: 'A', field: 'system.network.in.bytes', aggType: Aggregators.AVERAGE },
Copy link
Member

Choose a reason for hiding this comment

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

For the system.network.in.bytes and system.network.out.bytes, do we have hard coded value in the @kbn/infra-forge, or are they a random number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neither, it's incremental.

Copy link
Member

Choose a reason for hiding this comment

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

So it means the reason will be different on each execution, right?
Probably, when we test action variables and check the reason, we need to make this value more predictable.

const esDeleteAllIndices = getService('esDeleteAllIndices');
const logger = getService('log');

describe('Threshold rule - AVG - PCT - FIRED', () => {
Copy link
Member

Choose a reason for hiding this comment

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

What are the differences between Threshold rule - AVG - PCT - FIRED and Threshold rule - AVG - US - FIRED?
Initially, I was thinking about having multiple scenarios to check the reason to make sure they are properly formatted, I am curious to know what other differences we can test.

FYI, I created another ticket for the action variables, then we can also check the reason to ensure the correct formating is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are the differences between Threshold rule - AVG - PCT - FIRED and Threshold rule - AVG - US - FIRED?

Field data type % and microseconds

Initially, I was thinking about having multiple scenarios to check the reason to make sure they are properly formatted, I am curious to know what other differences we can test.

I am not sure If understand what you mean, but please create a ticket with the check you want to do with the scenarios you have in mind.

Copy link
Member

@maryam-saeidi maryam-saeidi Aug 3, 2023

Choose a reason for hiding this comment

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

My question is, what do we test for different field data types related to their type? Can you please point me to the code that is different between these two tests related to their field types?

Copy link
Contributor Author

@fkanout fkanout Aug 4, 2023

Choose a reason for hiding this comment

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

@maryam-saeidi, I'm fulfilling the 1st scenario you requested in your issue:

Multiple conditions with different types of fields (such as number, string, percent) without grouping (Can we have one condition for every condition type? 😄)

I thought you knew the difference, so you asked to cover it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing the field type will make many areas of code to be tested. I will list some files to answer the question
x-pack/plugins/observability/server/lib/rules/threshold/lib/get_data.ts
x-pack/plugins/observability/server/lib/rules/threshold/lib/metric_query.ts
x-pack/plugins/observability/server/lib/rules/threshold/threshold_executor.ts
x-pack/plugins/observability/server/lib/rules/threshold/lib/create_percentile_aggregation.ts
... and maybe others

As this is an integration test (not a unit test), asking about what lines of code are covered is inadequate and hard to answer.

Copy link
Member

Choose a reason for hiding this comment

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

I thought you knew the difference, so you asked to cover it.

Yes, the difference was the reason message that we are not checking at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

As this is an integration test (not a unit test), asking about what lines of code are covered is inadequate and hard to answer.

By the line of code, I meant related to the new tests that you added, not the code behind the scene, something maybe like: the value that is saved in AAD is formatted differently for different field types.

Copy link
Member

@maryam-saeidi maryam-saeidi left a comment

Choose a reason for hiding this comment

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

I've added some comments that probably we need to change when we test the action variables and specifically the reason message, but I think this PR is good to go!

@fkanout fkanout merged commit 6902008 into elastic:main Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AO] Add API integration test scenarios to the Threshold rule
6 participants