-
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.
[Security Solution] Add retry to getMetrics to reduce flake (#180704)
## Summary API integration tests added in #180094 fail occasionally on main, but pass consistently locally and in the flaky test runner. This PR adds a retry to the `getMetrics` request in hopes of removing the flakiness. Flake issues: #180530 #180641 --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
9e6617d
commit 59055c6
Showing
3 changed files
with
63 additions
and
24 deletions.
There are no files selected for viewing
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
41 changes: 41 additions & 0 deletions
41
...etection_engine/rule_execution_logic/trial_license_complete_tier/execution_logic/utils.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,41 @@ | ||
/* | ||
* 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 supertest from 'supertest'; | ||
|
||
import { NodeMetrics } from '@kbn/task-manager-plugin/server/routes/metrics'; | ||
import { RetryService } from '@kbn/ftr-common-functional-services'; | ||
|
||
export const getMetricsRequest = ( | ||
request: supertest.SuperTest<supertest.Test>, | ||
reset: boolean = false | ||
) => { | ||
return request | ||
.get(`/api/task_manager/metrics${reset ? '' : '?reset=false'}`) | ||
.set('kbn-xsrf', 'foo') | ||
.expect(200) | ||
.then((response) => response.body); | ||
}; | ||
|
||
export const getMetricsWithRetry = ( | ||
request: supertest.SuperTest<supertest.Test>, | ||
retry: RetryService, | ||
reset: boolean = false, | ||
callback?: (metrics: NodeMetrics) => boolean | ||
): Promise<NodeMetrics> => { | ||
return retry.try(async () => { | ||
const metrics = await getMetricsRequest(request, reset); | ||
|
||
if (metrics.metrics) { | ||
if ((callback && callback(metrics)) || !callback) { | ||
return metrics; | ||
} | ||
} | ||
|
||
throw new Error(`Expected metrics not received: ${JSON.stringify(metrics)}`); | ||
}); | ||
}; |