-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Ingest Manager] Remove fields from index pattern during package uninstall #80082
Changes from all commits
fd3fd01
7dfce8f
0819cbb
e974c48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,9 @@ export default function (providerContext: FtrProviderContext) { | |
before(async () => { | ||
await installPackage(pkgKey); | ||
}); | ||
after(async () => { | ||
await uninstallPackage(pkgKey); | ||
}); | ||
it('should have installed the ILM policy', async function () { | ||
const resPolicy = await es.transport.request({ | ||
method: 'GET', | ||
|
@@ -218,6 +221,9 @@ export default function (providerContext: FtrProviderContext) { | |
describe('uninstalls all assets when uninstalling a package', async () => { | ||
skipIfNoDockerRegistry(providerContext); | ||
before(async () => { | ||
// these tests ensure that uninstall works properly so make sure that the package gets installed and uninstalled | ||
// and then we'll test that not artifacts are left behind. | ||
await installPackage(pkgKey); | ||
await uninstallPackage(pkgKey); | ||
}); | ||
it('should have uninstalled the index templates', async function () { | ||
|
@@ -342,6 +348,48 @@ export default function (providerContext: FtrProviderContext) { | |
} | ||
expect(resSearch.response.data.statusCode).equal(404); | ||
}); | ||
it('should have removed the fields from the index patterns', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused about which branch we expect to execute. The try or the catch? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both could happen. If a test case in another file calls If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, interesting. Maybe we could add that as a comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah sure I'll put it as a comment. |
||
// The reason there is an expect inside the try and inside the catch in this test case is to guard against two | ||
// different scenarios. | ||
// | ||
// If a test case in another file calls /setup then the system and endpoint packages will be installed and | ||
// will be present for the remainder of the tests (because they cannot be removed). If that is the case the | ||
// expect in the try will work because the logs-* and metrics-* index patterns will still be present even | ||
// after this test uninstalls its package. | ||
// | ||
// If /setup was never called prior to this test, when the test package is uninstalled the index pattern code | ||
// checks to see if there are no packages installed and completely removes the logs-* and metrics-* index | ||
// patterns. If that happens this code will throw an error and indicate that the index pattern being searched | ||
// for was completely removed. In this case the catch's expect will test to make sure the error thrown was | ||
// a 404 because all of the packages have been removed. | ||
try { | ||
const resIndexPatternLogs = await kibanaServer.savedObjects.get({ | ||
type: 'index-pattern', | ||
id: 'logs-*', | ||
}); | ||
const fields = JSON.parse(resIndexPatternLogs.attributes.fields); | ||
const exists = fields.find((field: { name: string }) => field.name === 'logs_test_name'); | ||
expect(exists).to.be(undefined); | ||
} catch (err) { | ||
// if all packages are uninstalled there won't be a logs-* index pattern | ||
expect(err.response.data.statusCode).equal(404); | ||
} | ||
|
||
try { | ||
const resIndexPatternMetrics = await kibanaServer.savedObjects.get({ | ||
type: 'index-pattern', | ||
id: 'metrics-*', | ||
}); | ||
const fieldsMetrics = JSON.parse(resIndexPatternMetrics.attributes.fields); | ||
const existsMetrics = fieldsMetrics.find( | ||
(field: { name: string }) => field.name === 'metrics_test_name' | ||
); | ||
expect(existsMetrics).to.be(undefined); | ||
} catch (err) { | ||
// if all packages are uninstalled there won't be a metrics-* index pattern | ||
expect(err.response.data.statusCode).equal(404); | ||
} | ||
}); | ||
it('should have removed the saved object', async function () { | ||
let res; | ||
try { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it adds then immediately removes the package. Is that what's happening?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is just ensuring that the package was installed to begin with so the fields get added and then immediately removes it to setup the tests to validate the uninstall scenario. I got in a weird state locally when running the tests where the package was never actually installed the first time.