From 417bd9b3e330fee101678ab0e97a9e64c55ba32f Mon Sep 17 00:00:00 2001 From: Joel Griffith Date: Wed, 12 Dec 2018 14:39:26 -0800 Subject: [PATCH] Reporting regression: reports always retrying regardless of outcome (#26995) (#27082) * This fixes an issue where reports are always retried regardless of status --- .../server/lib/esqueue/__tests__/worker.js | 12 +++++++++--- .../reporting/server/lib/esqueue/worker.js | 17 ++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/reporting/server/lib/esqueue/__tests__/worker.js b/x-pack/plugins/reporting/server/lib/esqueue/__tests__/worker.js index 57698e81ff43..d86125d6c4c9 100644 --- a/x-pack/plugins/reporting/server/lib/esqueue/__tests__/worker.js +++ b/x-pack/plugins/reporting/server/lib/esqueue/__tests__/worker.js @@ -354,7 +354,7 @@ describe('Worker class', function () { }); describe('query body', function () { - const conditionPath = 'query.constant_score.filter.bool'; + const conditionPath = 'query.bool.filter.bool'; const jobtype = 'test_jobtype'; beforeEach(() => { @@ -377,7 +377,7 @@ describe('Worker class', function () { it('should search by job type', function () { const { body } = getSearchParams(jobtype); const conditions = get(body, conditionPath); - expect(conditions.filter).to.eql({ term: { jobtype: jobtype } }); + expect(conditions.must).to.eql({ term: { jobtype: jobtype } }); }); it('should search for pending or expired jobs', function () { @@ -388,7 +388,7 @@ describe('Worker class', function () { // this works because we are stopping the clock, so all times match const nowTime = moment().toISOString(); const pending = { term: { status: 'pending' } }; - const expired = { bool: { filter: [ + const expired = { bool: { must: [ { term: { status: 'processing' } }, { range: { process_expiration: { lte: nowTime } } } ] } }; @@ -400,6 +400,12 @@ describe('Worker class', function () { expect(expiredMatch).to.not.be(undefined); }); + it('specify that there should be at least one match', function () { + const { body } = getSearchParams(jobtype); + const conditions = get(body, conditionPath); + expect(conditions).to.have.property('minimum_should_match', 1); + }); + it('should use default size', function () { const { body } = getSearchParams(jobtype); expect(body).to.have.property('size', defaults.size); diff --git a/x-pack/plugins/reporting/server/lib/esqueue/worker.js b/x-pack/plugins/reporting/server/lib/esqueue/worker.js index 97439b571357..c1236b8c9cd7 100644 --- a/x-pack/plugins/reporting/server/lib/esqueue/worker.js +++ b/x-pack/plugins/reporting/server/lib/esqueue/worker.js @@ -350,17 +350,20 @@ export class Worker extends events.EventEmitter { excludes: [ 'output.content' ] }, query: { - constant_score: { + bool: { filter: { bool: { - filter: { term: { jobtype: this.jobtype } }, + minimum_should_match: 1, + must: { term: { jobtype: this.jobtype } }, should: [ { term: { status: 'pending' } }, - { bool: { - filter: [ - { term: { status: 'processing' } }, - { range: { process_expiration: { lte: nowTime } } } - ] } + { + bool: { + must: [ + { term: { status: 'processing' } }, + { range: { process_expiration: { lte: nowTime } } } + ] + } } ] }