From 13c7885b35a62c585bacb56a51cf909c04811be1 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 13 Apr 2021 08:21:16 -0400 Subject: [PATCH] [7.x] [Rollups] Update API integration test (#96071) (#96508) * [Rollups] Update API integration test (#96071) * updated 7.x error handler Co-authored-by: Alison Goryachev Co-authored-by: Jean-Louis Leysens --- .../routes/api/jobs/register_start_route.ts | 17 +++++++---------- .../apis/management/rollup/rollup.js | 17 +++++++++++------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/rollup/server/routes/api/jobs/register_start_route.ts b/x-pack/plugins/rollup/server/routes/api/jobs/register_start_route.ts index cee0898073da8..d5081fa10e577 100644 --- a/x-pack/plugins/rollup/server/routes/api/jobs/register_start_route.ts +++ b/x-pack/plugins/rollup/server/routes/api/jobs/register_start_route.ts @@ -39,18 +39,15 @@ export const registerStartRoute = ({ return response.ok({ body: data }); } catch (err) { // There is an issue opened on ES to handle the following error correctly - // https://github.com/elastic/elasticsearch/issues/42908 - // Until then we'll modify the response here. - if ( - err?.meta && - err.body?.task_failures[0]?.reason?.reason?.includes( - 'Job must be [STOPPED] before deletion' - ) - ) { + // https://github.com/elastic/elasticsearch/issues/39845, which was addressed in 8.0 + // but not backported to 7.x because it's breaking. So we need to modify the response + // here for 7.x. + if (err.meta?.body?.error?.reason?.includes('Cannot start task for Rollup Job')) { err.meta.status = 400; err.meta.statusCode = 400; - err.meta.displayName = 'Bad request'; - err.message = err.body.task_failures[0].reason.reason; + err.body.error.status = 400; + err.body.status = 400; + err.meta.displayName = 'Bad Request'; } return handleEsError({ error: err, response }); } diff --git a/x-pack/test/api_integration/apis/management/rollup/rollup.js b/x-pack/test/api_integration/apis/management/rollup/rollup.js index 2b630ca7c3a4f..69c8ddfcc4197 100644 --- a/x-pack/test/api_integration/apis/management/rollup/rollup.js +++ b/x-pack/test/api_integration/apis/management/rollup/rollup.js @@ -24,8 +24,7 @@ export default function ({ getService }) { cleanUp, } = registerHelpers(getService); - // FAILING ES PROMOTION: https://github.com/elastic/kibana/issues/96002 - describe.skip('jobs', () => { + describe('jobs', () => { after(() => cleanUp()); describe('indices', () => { @@ -57,10 +56,16 @@ export default function ({ getService }) { expect(body.doesMatchIndices).to.be(true); expect(body.doesMatchRollupIndices).to.be(false); expect(body.dateFields).to.eql(['testCreatedField']); - expect(body.keywordFields).to.eql(['testTagField']); - - // Allowing the test to account for future addition of doc_count - expect(body.numericFields.indexOf('testTotalField')).to.be.greaterThan(-1); + // '_tier' is an expected metadata field from ES + // Order is not guaranteed, so we assert against individual field names + ['_tier', 'testTagField'].forEach((keywordField) => { + expect(body.keywordFields.includes(keywordField)).to.be(true); + }); + // '_doc_count' is an expected metadata field from ES + // Order is not guaranteed, so we assert against individual field names + ['_doc_count', 'testTotalField'].forEach((numericField) => { + expect(body.numericFields.includes(numericField)).to.be(true); + }); }); it("should not return any fields when the index pattern doesn't match any indices", async () => {