Skip to content

Commit 1109b60

Browse files
authored
[Fleet] Fix delete by query conflict (#241001)
1 parent c0ad03a commit 1109b60

File tree

1 file changed

+74
-50
lines changed
  • x-pack/platform/test/fleet_api_integration/apis/space_awareness

1 file changed

+74
-50
lines changed

x-pack/platform/test/fleet_api_integration/apis/space_awareness/helpers.ts

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import type { Client } from '@elastic/elasticsearch';
99
import expect from '@kbn/expect';
1010
import { asyncForEach } from '@kbn/std';
11+
import pRetry from 'p-retry';
1112

1213
import {
1314
AGENT_ACTIONS_INDEX,
@@ -21,6 +22,8 @@ import type { FtrProviderContext } from '../../../api_integration/ftr_provider_c
2122

2223
const ES_INDEX_OPTIONS = { headers: { 'X-elastic-product-origin': 'fleet' } };
2324

25+
const DELETE_RETRIES = 3;
26+
2427
export async function expectToRejectWithNotFound(fn: any) {
2528
await expectToRejectWithError(fn, /404 "Not Found"/);
2629
}
@@ -38,68 +41,89 @@ export async function expectToRejectWithError(fn: any, errRegexp: RegExp) {
3841

3942
export async function cleanFleetIndices(esClient: Client) {
4043
await Promise.all([
41-
esClient.deleteByQuery({
42-
index: ENROLLMENT_API_KEYS_INDEX,
43-
q: '*',
44-
ignore_unavailable: true,
45-
refresh: true,
46-
conflicts: 'proceed',
47-
}),
48-
esClient.deleteByQuery({
49-
index: AGENTS_INDEX,
50-
q: '*',
51-
ignore_unavailable: true,
52-
refresh: true,
53-
conflicts: 'proceed',
54-
}),
55-
esClient.deleteByQuery({
56-
index: AGENT_ACTIONS_INDEX,
57-
q: '*',
58-
ignore_unavailable: true,
59-
refresh: true,
60-
conflicts: 'proceed',
61-
}),
44+
pRetry(
45+
() =>
46+
esClient.deleteByQuery({
47+
index: ENROLLMENT_API_KEYS_INDEX,
48+
q: '*',
49+
ignore_unavailable: true,
50+
refresh: true,
51+
}),
52+
{ retries: DELETE_RETRIES }
53+
),
54+
pRetry(
55+
() =>
56+
esClient.deleteByQuery({
57+
index: AGENTS_INDEX,
58+
q: '*',
59+
ignore_unavailable: true,
60+
refresh: true,
61+
}),
62+
{ retries: DELETE_RETRIES }
63+
),
64+
pRetry(
65+
() =>
66+
esClient.deleteByQuery({
67+
index: AGENT_ACTIONS_INDEX,
68+
q: '*',
69+
ignore_unavailable: true,
70+
refresh: true,
71+
}),
72+
{ retries: DELETE_RETRIES }
73+
),
6274
]);
6375
}
6476

6577
export async function cleanFleetAgents(esClient: Client) {
66-
await esClient.deleteByQuery({
67-
index: AGENTS_INDEX,
68-
q: '*',
69-
ignore_unavailable: true,
70-
refresh: true,
71-
conflicts: 'proceed',
72-
});
78+
await pRetry(
79+
() =>
80+
esClient.deleteByQuery({
81+
index: AGENTS_INDEX,
82+
q: '*',
83+
ignore_unavailable: true,
84+
refresh: true,
85+
}),
86+
{ retries: DELETE_RETRIES }
87+
);
7388
}
7489

7590
export async function cleanFleetAgentPolicies(esClient: Client) {
76-
await esClient.deleteByQuery({
77-
index: AGENT_POLICY_INDEX,
78-
q: '*',
79-
refresh: true,
80-
ignore_unavailable: true,
81-
conflicts: 'proceed',
82-
});
91+
await pRetry(
92+
() =>
93+
esClient.deleteByQuery({
94+
index: AGENT_POLICY_INDEX,
95+
q: '*',
96+
refresh: true,
97+
ignore_unavailable: true,
98+
}),
99+
{ retries: DELETE_RETRIES }
100+
);
83101
}
84102

85103
export async function cleanFleetActionIndices(esClient: Client) {
86104
try {
87105
await Promise.all([
88-
esClient.deleteByQuery({
89-
index: AGENT_ACTIONS_INDEX,
90-
q: '*',
91-
ignore_unavailable: true,
92-
refresh: true,
93-
conflicts: 'proceed',
94-
}),
95-
esClient.deleteByQuery(
96-
{
97-
index: AGENT_ACTIONS_RESULTS_INDEX,
98-
q: '*',
99-
refresh: true,
100-
conflicts: 'proceed',
101-
},
102-
ES_INDEX_OPTIONS
106+
pRetry(
107+
() =>
108+
esClient.deleteByQuery({
109+
index: AGENT_ACTIONS_INDEX,
110+
q: '*',
111+
ignore_unavailable: true,
112+
refresh: true,
113+
}),
114+
{ retries: DELETE_RETRIES }
115+
),
116+
pRetry(
117+
() =>
118+
esClient.deleteByQuery(
119+
{
120+
index: AGENT_ACTIONS_RESULTS_INDEX,
121+
q: '*',
122+
refresh: true,
123+
},
124+
ES_INDEX_OPTIONS
125+
),
126+
{ retries: DELETE_RETRIES }
103127
),
104128
]);
105129
} catch (error) {

0 commit comments

Comments
 (0)