-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test_serverless/api_integration] convert alerting_wait_for_helpers i…
…nto FTR service (#162623) ## Summary This PR converts helpers into FTR services that should provide better test capabilities and improve stability/error output. Before change: ``` └-> should be active └-> "before each" hook: global before each for "should be active" └- ✖ fail: serverless observability API Threshold rule - AVG - PCT - FIRED Rule creation should be active │ Error: Timeout of 360000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/dmle/github/kibana/x-pack/test_serverless/api_integration/test_suites/observability/threshold_rule/avg_pct_fired.ts) │ at listOnTimeout (node:internal/timers:559:17) │ at processTimers (node:internal/timers:502:7) ``` The test is not handling its state properly and fails on mocha timeout (6 minutes) without proper error message. It leads the test suite usually taking ~**5** min keep running for over [1 hour](https://buildkite.com/elastic/appex-qa-kibana-serverless-ftr-tests/builds/30#01898d63-a0e1-4cb0-b460-b4824ce2d5b1) After change: ``` 2) serverless observability API │ Threshold rule - AVG - PCT - FIRED │ Rule creation │ should be active: │ │ Error: 'ruleId' is undefined │ at Object.waitForRuleStatus (alerting_api.ts:31:15) │ at Context.apply (avg_pct_fired.ts:122:51) │ at Object.apply (wrap_function.js:73:30) ``` Since the follow-up tests depend on the first test to success, we can either move Rule creation to before hook or check for `ruleId` to be defined. If it is defined, `retry` service will pull for status up to 90 sec (important to keep below Mocha timeout so you can get error) and fail if it is not matching expected one.
- Loading branch information
1 parent
d0d3127
commit c4692b3
Showing
7 changed files
with
118 additions
and
41 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
x-pack/test_serverless/api_integration/services/alerting_api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { | ||
AggregationsAggregate, | ||
SearchResponse, | ||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
|
||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
|
||
export function AlertingApiProvider({ getService }: FtrProviderContext) { | ||
const retry = getService('retry'); | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
const requestTimeout = 30 * 1000; | ||
const retryTimeout = 120 * 1000; | ||
|
||
return { | ||
async waitForRuleStatus({ | ||
ruleId, | ||
expectedStatus, | ||
}: { | ||
ruleId: string; | ||
expectedStatus: string; | ||
}) { | ||
if (!ruleId) { | ||
throw new Error(`'ruleId' is undefined`); | ||
} | ||
return await retry.tryForTime(retryTimeout, async () => { | ||
const response = await supertest | ||
.get(`/api/alerting/rule/${ruleId}`) | ||
.set('kbn-xsrf', 'foo') | ||
.set('x-elastic-internal-origin', 'foo') | ||
.timeout(requestTimeout); | ||
const { execution_status: executionStatus } = response.body || {}; | ||
const { status } = executionStatus || {}; | ||
if (status !== expectedStatus) { | ||
throw new Error(`waitForStatus(${expectedStatus}): got ${status}`); | ||
} | ||
return executionStatus?.status; | ||
}); | ||
}, | ||
|
||
async waitForDocumentInIndex<T>({ | ||
indexName, | ||
}: { | ||
indexName: string; | ||
}): Promise<SearchResponse<T, Record<string, AggregationsAggregate>>> { | ||
return await retry.tryForTime(retryTimeout, async () => { | ||
const response = await es.search<T>({ index: indexName }); | ||
if (response.hits.hits.length === 0) { | ||
throw new Error('No hits found'); | ||
} | ||
return response; | ||
}); | ||
}, | ||
|
||
async waitForAlertInIndex<T>({ | ||
indexName, | ||
ruleId, | ||
}: { | ||
indexName: string; | ||
ruleId: string; | ||
}): Promise<SearchResponse<T, Record<string, AggregationsAggregate>>> { | ||
if (!ruleId) { | ||
throw new Error(`'ruleId' is undefined`); | ||
} | ||
return await retry.tryForTime(retryTimeout, async () => { | ||
const response = await es.search<T>({ | ||
index: indexName, | ||
body: { | ||
query: { | ||
term: { | ||
'kibana.alert.rule.uuid': ruleId, | ||
}, | ||
}, | ||
}, | ||
}); | ||
if (response.hits.hits.length === 0) { | ||
throw new Error('No hits found'); | ||
} | ||
return response; | ||
}); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters