Skip to content

Commit

Permalink
[Uptime] Update duration chart query filters (#63620)
Browse files Browse the repository at this point in the history
* updated duration query

* updated snapshot

* update fixtures

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
shahzad31 and elasticmachine authored Apr 16, 2020
1 parent 5ffdeb6 commit a3f4acf
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 324 deletions.
6 changes: 0 additions & 6 deletions x-pack/legacy/plugins/uptime/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ export interface LocationDurationLine {
export interface MonitorDurationResult {
/** The average values for the monitor duration. */
locationDurationLines: LocationDurationLine[];
/** The counts of up/down checks for the monitor. */
status: StatusData[];
/** The maximum status doc count in this chart. */
statusMaxCount: number;
/** The maximum duration value in this chart. */
durationMaxValue: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ describe('MonitorCharts component', () => {
],
},
],
status: [
{ x: 1548697620000, up: 74, down: null, total: 74 },
{ x: 1548697920000, up: 75, down: null, total: 75 },
{ x: 1548698220000, up: 75, down: null, total: 75 },
{ x: 1548698520000, up: 73, down: null, total: 73 },
{ x: 1548698820000, up: 75, down: null, total: 75 },
{ x: 1548699120000, up: 74, down: null, total: 74 },
{ x: 1548699420000, up: 75, down: null, total: 75 },
{ x: 1548699720000, up: 75, down: null, total: 75 },
{ x: 1548700020000, up: 75, down: null, total: 75 },
{ x: 1548700320000, up: 75, down: null, total: 75 },
{ x: 1548700620000, up: 75, down: null, total: 75 },
],
statusMaxCount: 75,
durationMaxValue: 6669234,
},
};

Expand Down
7 changes: 2 additions & 5 deletions x-pack/legacy/plugins/uptime/public/state/api/ml_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ export const createMLJob = async ({
query: {
bool: {
filter: [
{
term: {
'monitor.id': lowerCaseMonitorId,
},
},
{ term: { 'monitor.id': lowerCaseMonitorId } },
{ range: { 'monitor.duration.us': { gt: 0 } } },
],
},
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 3 additions & 33 deletions x-pack/plugins/uptime/server/lib/requests/get_monitor_duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,6 @@ export interface GetMonitorChartsParams {
dateEnd: string;
}

const formatStatusBuckets = (time: any, buckets: any, docCount: any) => {
let up = null;
let down = null;

buckets.forEach((bucket: any) => {
if (bucket.key === 'up') {
up = bucket.doc_count;
} else if (bucket.key === 'down') {
down = bucket.doc_count;
}
});

return {
x: time,
up,
down,
total: docCount,
};
};

/**
* Fetches data used to populate monitor charts
*/
Expand All @@ -55,7 +35,7 @@ export const getMonitorDurationChart: UMElasticsearchQueryFn<
filter: [
{ range: { '@timestamp': { gte: dateStart, lte: dateEnd } } },
{ term: { 'monitor.id': monitorId } },
{ term: { 'monitor.status': 'up' } },
{ range: { 'monitor.duration.us': { gt: 0 } } },
],
},
},
Expand All @@ -73,7 +53,6 @@ export const getMonitorDurationChart: UMElasticsearchQueryFn<
missing: 'N/A',
},
aggs: {
status: { terms: { field: 'monitor.status', size: 2, shard_size: 2 } },
duration: { stats: { field: 'monitor.duration.us' } },
},
},
Expand All @@ -94,15 +73,10 @@ export const getMonitorDurationChart: UMElasticsearchQueryFn<
*
* The third list is for an area chart expressing a range, and it requires an (x,y,y0) structure,
* where y0 is the min value for the point and y is the max.
*
* Additionally, we supply the maximum value for duration and status, so the corresponding charts know
* what the domain size should be.
*/

const monitorChartsData: MonitorDurationResult = {
locationDurationLines: [],
status: [],
durationMaxValue: 0,
statusMaxCount: 0,
};

/**
Expand All @@ -119,9 +93,9 @@ export const getMonitorDurationChart: UMElasticsearchQueryFn<
// a set of all the locations found for this result
const resultLocations = new Set<string>();
const linesByLocation: { [key: string]: LocationDurationLine } = {};

dateHistogramBuckets.forEach(dateHistogramBucket => {
const x = dateHistogramBucket.key;
const docCount = dateHistogramBucket?.doc_count ?? 0;
// a set of all the locations for the current bucket
const bucketLocations = new Set<string>();

Expand Down Expand Up @@ -161,10 +135,6 @@ export const getMonitorDurationChart: UMElasticsearchQueryFn<
}
});
}

monitorChartsData.status.push(
formatStatusBuckets(x, dateHistogramBucket?.status?.buckets ?? [], docCount)
);
});

return monitorChartsData;
Expand Down
Loading

0 comments on commit a3f4acf

Please sign in to comment.