Skip to content

Commit

Permalink
Fix summary querying
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Oct 1, 2020
1 parent 418bdb3 commit 628e3a2
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions x-pack/plugins/uptime/server/lib/requests/get_pings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,43 @@ import {

const DEFAULT_PAGE_SIZE = 25;

/**
* This branch of filtering is used for monitors of type `browser`. This monitor
* type represents an unbounded set of steps, with each `check_group` representing
* a distinct journey. The document containing the `summary` field is indexed last, and
* contains the data necessary for querying a journey.
*
* Because of this, when querying for "pings", it is important that we treat `browser` summary
* checks as the "ping" we want. Without this filtering, we will receive >= N pings for a journey
* of N steps, because an individual step may also contain multiple documents.
*/
const REMOVE_NON_SUMMARY_BROWSER_CHECKS = {
must_not: [
{
bool: {
filter: [
{
term: {
'monitor.type': 'browser',
},
},
{
bool: {
must_not: [
{
exists: {
field: 'summary',
},
},
],
},
},
],
},
},
],
};

export const getPings: UMElasticsearchQueryFn<GetPingsParams, PingsResponse> = async ({
callES,
dynamicSettings,
Expand All @@ -27,10 +64,7 @@ export const getPings: UMElasticsearchQueryFn<GetPingsParams, PingsResponse> = a
}) => {
const size = sizeParam ?? DEFAULT_PAGE_SIZE;
const sortParam = { sort: [{ '@timestamp': { order: sort ?? 'desc' } }] };
const filter: any[] = [
{ range: { '@timestamp': { gte: from, lte: to } } },
{ exists: { field: 'summary' } },
];
const filter: any[] = [{ range: { '@timestamp': { gte: from, lte: to } } }];
if (monitorId) {
filter.push({ term: { 'monitor.id': monitorId } });
}
Expand All @@ -42,7 +76,12 @@ export const getPings: UMElasticsearchQueryFn<GetPingsParams, PingsResponse> = a
if (location) {
postFilterClause = { post_filter: { term: { 'observer.geo.name': location } } };
}
const queryContext = { bool: { filter } };
const queryContext = {
bool: {
filter,
...REMOVE_NON_SUMMARY_BROWSER_CHECKS,
},
};
const params: any = {
index: dynamicSettings.heartbeatIndices,
body: {
Expand Down

0 comments on commit 628e3a2

Please sign in to comment.