Skip to content

Commit

Permalink
[Uptime] Improve refresh handling when generating test data
Browse files Browse the repository at this point in the history
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 #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.
  • Loading branch information
andrewvc committed Feb 21, 2020
1 parent d61ef26 commit bc3714d
Showing 1 changed file with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const makePing = async (
es: any,
monitorId: string,
fields: { [key: string]: any },
mogrify: (doc: any) => any
mogrify: (doc: any) => any,
refresh: boolean = true
) => {
const baseDoc = {
tcp: {
Expand Down Expand Up @@ -103,7 +104,7 @@ export const makePing = async (

await es.index({
index: INDEX_NAME,
refresh: true,
refresh,
body: doc,
});

Expand All @@ -115,7 +116,8 @@ export const makeCheck = async (
monitorId: string,
numIps: number,
fields: { [key: string]: any },
mogrify: (doc: any) => any
mogrify: (doc: any) => any,
refresh: boolean = true
) => {
const cgFields = {
monitor: {
Expand All @@ -137,11 +139,16 @@ export const makeCheck = async (
if (i === numIps - 1) {
pingFields.summary = summary;
}
const doc = await makePing(es, monitorId, pingFields, mogrify);
const doc = await makePing(es, monitorId, pingFields, mogrify, false);
docs.push(doc);
// @ts-ignore
summary[doc.monitor.status]++;
}

if (refresh) {
es.indices.refresh();
}

return docs;
};

Expand All @@ -152,7 +159,8 @@ export const makeChecks = async (
numIps: number,
every: number, // number of millis between checks
fields: { [key: string]: any } = {},
mogrify: (doc: any) => any = d => d
mogrify: (doc: any) => any = d => d,
refresh: boolean = true
) => {
const checks = [];
const oldestTime = new Date().getTime() - numChecks * every;
Expand All @@ -169,7 +177,11 @@ export const makeChecks = async (
},
},
});
checks.push(await makeCheck(es, monitorId, numIps, fields, mogrify));
checks.push(await makeCheck(es, monitorId, numIps, fields, mogrify, false));
}

if (refresh) {
es.indices.refresh();
}

return checks;
Expand All @@ -183,19 +195,29 @@ export const makeChecksWithStatus = async (
every: number,
fields: { [key: string]: any } = {},
status: 'up' | 'down',
mogrify: (doc: any) => any = d => d
mogrify: (doc: any) => any = d => d,
refresh: boolean = true
) => {
const oppositeStatus = status === 'up' ? 'down' : 'up';

return await makeChecks(es, monitorId, numChecks, numIps, every, fields, d => {
d.monitor.status = status;
if (d.summary) {
d.summary[status] += d.summary[oppositeStatus];
d.summary[oppositeStatus] = 0;
}

return mogrify(d);
});
return await makeChecks(
es,
monitorId,
numChecks,
numIps,
every,
fields,
d => {
d.monitor.status = status;
if (d.summary) {
d.summary[status] += d.summary[oppositeStatus];
d.summary[oppositeStatus] = 0;
}

return mogrify(d);
},
refresh
);
};

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

0 comments on commit bc3714d

Please sign in to comment.