Skip to content

Commit

Permalink
[Uptime] Fix race on overview page query
Browse files Browse the repository at this point in the history
Fixes elastic#67842 by requerying
during the refine phase to see if a newer matching doc has come in.
  • Loading branch information
andrewvc committed Jun 1, 2020
1 parent 96e0e91 commit 2acbb20
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ const fullyMatchingIds = async (
const monitorId: string = monBucket.key;
const groups: MonitorLocCheckGroup[] = [];

// Did at least one location match?
let matched = false;
for (const locBucket of monBucket.location.buckets) {
const location = locBucket.key;
const topSource = locBucket.top.hits.hits[0]._source;
const stillMatchingTopSource = locBucket.still_matching.top.hits.hits[0]._source;
// If the most recent document still matches the most recent document matching the current filters
// we can include this in the result
if (stillMatchingTopSource['@timestamp'] >= topSource['@timestamp']) {
matched = true;
}
const checkGroup = topSource.monitor.check_group;
const status = topSource.summary.down > 0 ? 'down' : 'up';

Expand All @@ -82,8 +90,8 @@ const fullyMatchingIds = async (
});
}

// We only truly match the monitor if one of the most recent check groups was found in the potential matches phase
if (groups.some((g) => potentialMatchCheckGroups.has(g.checkGroup))) {
// If one location matched, include data from all locations in the result set
if (matched) {
matching.set(monitorId, groups);
}
}
Expand Down Expand Up @@ -125,6 +133,25 @@ export const mostRecentCheckGroups = async (
size: 1,
},
},
still_matching: {
filter: queryContext.filterClause || { match_all: {} },
aggs: {
top: {
top_hits: {
sort: [{ '@timestamp': 'desc' }],
_source: {
includes: [
'monitor.check_group',
'@timestamp',
'summary.up',
'summary.down',
],
},
size: 1,
},
},
},
},
},
},
},
Expand Down

0 comments on commit 2acbb20

Please sign in to comment.