Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Uptime] Improve refresh handling when generating test data #58285

Merged
merged 2 commits into from
Feb 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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