Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvc committed Jun 4, 2020
1 parent 7e076a9 commit 642735f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ const fullyMatchingIds = async (
let matched = false;
for (const locBucket of monBucket.location.buckets) {
const location = locBucket.key;
const latestSource = locBucket.latest.hits.hits[0]._source;
const latestStillMatchingSource = locBucket.latest_matching.top.hits.hits[0]._source;
const latestSource = locBucket.summaries.latest.hits.hits[0]._source;
const latestStillMatchingSource = locBucket.latest_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
//
// We just check if the timestamp is greater. Note this may match an incomplete check group
// that has not yet sent a summary doc
if (latestStillMatchingSource['@timestamp'] >= latestSource['@timestamp']) {
matched = true;
}
Expand Down Expand Up @@ -112,8 +115,6 @@ export const mostRecentCheckGroups = async (
filter: [
await queryContext.dateRangeFilter(),
{ terms: { 'monitor.id': potentialMatchMonitorIDs } },
// only match summary docs because we only want the latest *complete* check group.
{ exists: { field: 'summary' } },
],
},
},
Expand All @@ -124,15 +125,27 @@ export const mostRecentCheckGroups = async (
location: {
terms: { field: 'observer.geo.name', missing: 'N/A', size: 100 },
aggs: {
latest: {
top_hits: {
sort: [{ '@timestamp': 'desc' }],
_source: {
includes: ['monitor.check_group', '@timestamp', 'summary.up', 'summary.down'],
summaries: {
// only match summary docs because we only want the latest *complete* check group.
filter: { exists: { field: 'summary' } },
aggs: {
latest: {
top_hits: {
sort: [{ '@timestamp': 'desc' }],
_source: {
includes: [
'monitor.check_group',
'@timestamp',
'summary.up',
'summary.down',
],
},
size: 1,
},
},
size: 1,
},
},
// We want to find the latest check group, even if it's not part of a summary
latest_matching: {
filter: queryContext.filterClause || { match_all: {} },
aggs: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default function ({ getService }: FtrProviderContext) {
const url = getBaseUrl(dateRangeStart, dateRangeEnd) + `&filters=${filters}`;
const apiResponse = await supertest.get(url);
const nonSummaryRes = apiResponse.body;
// expect(JSON.stringify(nonSummaryRes)).to.eql("foo");
expect(nonSummaryRes.summaries.length).to.eql(1);
});

Expand Down

0 comments on commit 642735f

Please sign in to comment.