Skip to content

Commit bc3714d

Browse files
committed
[Uptime] Improve refresh handling when generating test data
When generating test data we refresh excessively, this can fill up the ES queues and break the tests if we run massive tests. I originally ran into this with elastic#58078 which I closed due to finding a better approach. While none of our current tests have the scale to expose this problem, we certainly will add tests that do later, so we should keep this change.
1 parent d61ef26 commit bc3714d

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

x-pack/test/api_integration/apis/uptime/graphql/helpers/make_checks.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const makePing = async (
1313
es: any,
1414
monitorId: string,
1515
fields: { [key: string]: any },
16-
mogrify: (doc: any) => any
16+
mogrify: (doc: any) => any,
17+
refresh: boolean = true
1718
) => {
1819
const baseDoc = {
1920
tcp: {
@@ -103,7 +104,7 @@ export const makePing = async (
103104

104105
await es.index({
105106
index: INDEX_NAME,
106-
refresh: true,
107+
refresh,
107108
body: doc,
108109
});
109110

@@ -115,7 +116,8 @@ export const makeCheck = async (
115116
monitorId: string,
116117
numIps: number,
117118
fields: { [key: string]: any },
118-
mogrify: (doc: any) => any
119+
mogrify: (doc: any) => any,
120+
refresh: boolean = true
119121
) => {
120122
const cgFields = {
121123
monitor: {
@@ -137,11 +139,16 @@ export const makeCheck = async (
137139
if (i === numIps - 1) {
138140
pingFields.summary = summary;
139141
}
140-
const doc = await makePing(es, monitorId, pingFields, mogrify);
142+
const doc = await makePing(es, monitorId, pingFields, mogrify, false);
141143
docs.push(doc);
142144
// @ts-ignore
143145
summary[doc.monitor.status]++;
144146
}
147+
148+
if (refresh) {
149+
es.indices.refresh();
150+
}
151+
145152
return docs;
146153
};
147154

@@ -152,7 +159,8 @@ export const makeChecks = async (
152159
numIps: number,
153160
every: number, // number of millis between checks
154161
fields: { [key: string]: any } = {},
155-
mogrify: (doc: any) => any = d => d
162+
mogrify: (doc: any) => any = d => d,
163+
refresh: boolean = true
156164
) => {
157165
const checks = [];
158166
const oldestTime = new Date().getTime() - numChecks * every;
@@ -169,7 +177,11 @@ export const makeChecks = async (
169177
},
170178
},
171179
});
172-
checks.push(await makeCheck(es, monitorId, numIps, fields, mogrify));
180+
checks.push(await makeCheck(es, monitorId, numIps, fields, mogrify, false));
181+
}
182+
183+
if (refresh) {
184+
es.indices.refresh();
173185
}
174186

175187
return checks;
@@ -183,19 +195,29 @@ export const makeChecksWithStatus = async (
183195
every: number,
184196
fields: { [key: string]: any } = {},
185197
status: 'up' | 'down',
186-
mogrify: (doc: any) => any = d => d
198+
mogrify: (doc: any) => any = d => d,
199+
refresh: boolean = true
187200
) => {
188201
const oppositeStatus = status === 'up' ? 'down' : 'up';
189202

190-
return await makeChecks(es, monitorId, numChecks, numIps, every, fields, d => {
191-
d.monitor.status = status;
192-
if (d.summary) {
193-
d.summary[status] += d.summary[oppositeStatus];
194-
d.summary[oppositeStatus] = 0;
195-
}
196-
197-
return mogrify(d);
198-
});
203+
return await makeChecks(
204+
es,
205+
monitorId,
206+
numChecks,
207+
numIps,
208+
every,
209+
fields,
210+
d => {
211+
d.monitor.status = status;
212+
if (d.summary) {
213+
d.summary[status] += d.summary[oppositeStatus];
214+
d.summary[oppositeStatus] = 0;
215+
}
216+
217+
return mogrify(d);
218+
},
219+
refresh
220+
);
199221
};
200222

201223
// Helper for processing a list of checks to find the time picker bounds.

0 commit comments

Comments
 (0)