-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Finer-grained error information from install/upgrade API (#95649
) * Intercept installation errors and add meta info. * Adjust mock. * Catch errors in all steps of install/upgrade. * Adjust handler for direct package upload. * Don't throw not-found errors on assets during rollback. * Correctly catch errors from _installPackage() * Propagate error from installResult in bulk install case. * Add tests for rollback. * Remove unused code. * Skipping test that doesn't test what it says. * Fix and reenable test.
- Loading branch information
Showing
15 changed files
with
327 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
x-pack/test/fleet_api_integration/apis/epm/install_error_rollback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; | ||
import { skipIfNoDockerRegistry } from '../../helpers'; | ||
|
||
export default function (providerContext: FtrProviderContext) { | ||
const { getService } = providerContext; | ||
const supertest = getService('supertest'); | ||
const esArchiver = getService('esArchiver'); | ||
const goodPackage = 'error_handling-0.1.0'; | ||
const badPackage = 'error_handling-0.2.0'; | ||
|
||
const installPackage = async (pkgkey: string) => { | ||
await supertest | ||
.post(`/api/fleet/epm/packages/${pkgkey}`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ force: true }); | ||
}; | ||
|
||
const getPackageInfo = async (pkgkey: string) => { | ||
return await supertest.get(`/api/fleet/epm/packages/${pkgkey}`).set('kbn-xsrf', 'xxxx'); | ||
}; | ||
|
||
describe('package installation error handling and rollback', async () => { | ||
skipIfNoDockerRegistry(providerContext); | ||
beforeEach(async () => { | ||
await esArchiver.load('empty_kibana'); | ||
}); | ||
afterEach(async () => { | ||
await esArchiver.unload('empty_kibana'); | ||
}); | ||
|
||
it('on a fresh install, it should uninstall a broken package during rollback', async function () { | ||
await supertest | ||
.post(`/api/fleet/epm/packages/${badPackage}`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.expect(422); // the broken package contains a broken visualization triggering a 422 from Kibana | ||
|
||
const pkgInfoResponse = await getPackageInfo(badPackage); | ||
expect(JSON.parse(pkgInfoResponse.text).response.status).to.be('not_installed'); | ||
}); | ||
|
||
it('on an upgrade, it should fall back to the previous good version during rollback', async function () { | ||
await installPackage(goodPackage); | ||
await supertest | ||
.post(`/api/fleet/epm/packages/${badPackage}`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.expect(422); // the broken package contains a broken visualization triggering a 422 from Kibana | ||
|
||
const goodPkgInfoResponse = await getPackageInfo(goodPackage); | ||
expect(JSON.parse(goodPkgInfoResponse.text).response.status).to.be('installed'); | ||
expect(JSON.parse(goodPkgInfoResponse.text).response.version).to.be('0.1.0'); | ||
}); | ||
}); | ||
} |
3 changes: 3 additions & 0 deletions
3
...api_integration/apis/fixtures/test_packages/error_handling/0.1.0/docs/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This package should install without errors. | ||
|
||
Version 0.2.0 of this package should fail during installation. We need this good version to test rollback. |
14 changes: 14 additions & 0 deletions
14
...ixtures/test_packages/error_handling/0.1.0/kibana/visualization/sample_visualization.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"attributes": { | ||
"description": "sample visualization", | ||
"title": "sample vis title", | ||
"uiStateJSON": "{}", | ||
"version": 1, | ||
"visState": "{\"aggs\":[{\"enabled\":true,\"id\":\"1\",\"params\":{},\"schema\":\"metric\",\"type\":\"count\"},{\"enabled\":true,\"id\":\"2\",\"params\":{\"extended_bounds\":{},\"field\":\"@timestamp\",\"interval\":\"auto\",\"min_doc_count\":1},\"schema\":\"segment\",\"type\":\"date_histogram\"},{\"enabled\":true,\"id\":\"3\",\"params\":{\"customLabel\":\"Log Level\",\"field\":\"log.level\",\"order\":\"desc\",\"orderBy\":\"1\",\"size\":5},\"schema\":\"group\",\"type\":\"terms\"}],\"params\":{\"addLegend\":true,\"addTimeMarker\":false,\"addTooltip\":true,\"categoryAxes\":[{\"id\":\"CategoryAxis-1\",\"labels\":{\"show\":true,\"truncate\":100},\"position\":\"bottom\",\"scale\":{\"type\":\"linear\"},\"show\":true,\"style\":{},\"title\":{\"text\":\"@timestamp per day\"},\"type\":\"category\"}],\"grid\":{\"categoryLines\":false,\"style\":{\"color\":\"#eee\"}},\"legendPosition\":\"right\",\"seriesParams\":[{\"data\":{\"id\":\"1\",\"label\":\"Count\"},\"drawLinesBetweenPoints\":true,\"mode\":\"stacked\",\"show\":\"true\",\"showCircles\":true,\"type\":\"histogram\",\"valueAxis\":\"ValueAxis-1\"}],\"times\":[],\"type\":\"histogram\",\"valueAxes\":[{\"id\":\"ValueAxis-1\",\"labels\":{\"filter\":false,\"rotate\":0,\"show\":true,\"truncate\":100},\"name\":\"LeftAxis-1\",\"position\":\"left\",\"scale\":{\"mode\":\"normal\",\"type\":\"linear\"},\"show\":true,\"style\":{},\"title\":{\"text\":\"Count\"},\"type\":\"value\"}]},\"title\":\"Log levels over time [Logs Kafka] ECS\",\"type\":\"histogram\"}" | ||
}, | ||
"id": "sample_visualization", | ||
"type": "visualization", | ||
"migrationVersion": { | ||
"visualization": "7.7.0" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
.../test/fleet_api_integration/apis/fixtures/test_packages/error_handling/0.1.0/manifest.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
format_version: 1.0.0 | ||
name: error_handling | ||
title: Error handling | ||
description: tests error handling and rollback | ||
version: 0.1.0 | ||
categories: [] | ||
release: beta | ||
type: integration | ||
license: basic | ||
|
||
requirement: | ||
elasticsearch: | ||
versions: '>7.7.0' | ||
kibana: | ||
versions: '>7.7.0' | ||
|
||
icons: | ||
- src: '/img/logo_overrides_64_color.svg' | ||
size: '16x16' | ||
type: 'image/svg+xml' |
5 changes: 5 additions & 0 deletions
5
...api_integration/apis/fixtures/test_packages/error_handling/0.2.0/docs/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This package should fail during installation. | ||
|
||
Version 0.1.0 of this package should install without errors, and be rolled back to without errors. | ||
|
||
This package contains one Kibana visualization that requires a non-existent version of Kibana in order to trigger an error during installation. |
14 changes: 14 additions & 0 deletions
14
...ixtures/test_packages/error_handling/0.2.0/kibana/visualization/sample_visualization.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"attributes": { | ||
"description": "sample visualization", | ||
"title": "sample vis title", | ||
"uiStateJSON": "{}", | ||
"version": 1, | ||
"visState": "{\"aggs\":[{\"enabled\":true,\"id\":\"1\",\"params\":{},\"schema\":\"metric\",\"type\":\"count\"},{\"enabled\":true,\"id\":\"2\",\"params\":{\"extended_bounds\":{},\"field\":\"@timestamp\",\"interval\":\"auto\",\"min_doc_count\":1},\"schema\":\"segment\",\"type\":\"date_histogram\"},{\"enabled\":true,\"id\":\"3\",\"params\":{\"customLabel\":\"Log Level\",\"field\":\"log.level\",\"order\":\"desc\",\"orderBy\":\"1\",\"size\":5},\"schema\":\"group\",\"type\":\"terms\"}],\"params\":{\"addLegend\":true,\"addTimeMarker\":false,\"addTooltip\":true,\"categoryAxes\":[{\"id\":\"CategoryAxis-1\",\"labels\":{\"show\":true,\"truncate\":100},\"position\":\"bottom\",\"scale\":{\"type\":\"linear\"},\"show\":true,\"style\":{},\"title\":{\"text\":\"@timestamp per day\"},\"type\":\"category\"}],\"grid\":{\"categoryLines\":false,\"style\":{\"color\":\"#eee\"}},\"legendPosition\":\"right\",\"seriesParams\":[{\"data\":{\"id\":\"1\",\"label\":\"Count\"},\"drawLinesBetweenPoints\":true,\"mode\":\"stacked\",\"show\":\"true\",\"showCircles\":true,\"type\":\"histogram\",\"valueAxis\":\"ValueAxis-1\"}],\"times\":[],\"type\":\"histogram\",\"valueAxes\":[{\"id\":\"ValueAxis-1\",\"labels\":{\"filter\":false,\"rotate\":0,\"show\":true,\"truncate\":100},\"name\":\"LeftAxis-1\",\"position\":\"left\",\"scale\":{\"mode\":\"normal\",\"type\":\"linear\"},\"show\":true,\"style\":{},\"title\":{\"text\":\"Count\"},\"type\":\"value\"}]},\"title\":\"Log levels over time [Logs Kafka] ECS\",\"type\":\"histogram\"}" | ||
}, | ||
"id": "sample_visualization", | ||
"type": "visualization", | ||
"migrationVersion": { | ||
"visualization": "12.7.0" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../test/fleet_api_integration/apis/fixtures/test_packages/error_handling/0.2.0/manifest.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
format_version: 1.0.0 | ||
name: error_handling | ||
title: Error handling | ||
description: tests error handling and rollback | ||
version: 0.2.0 | ||
categories: [] | ||
release: beta | ||
type: integration | ||
license: basic | ||
|
||
requirement: | ||
elasticsearch: | ||
versions: '>7.7.0' | ||
kibana: | ||
versions: '>7.7.0' | ||
|
||
icons: | ||
- src: '/img/logo_overrides_64_color.svg' | ||
size: '16x16' |