Skip to content
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

[Fleet] Don't overwrite logs-* and metrics-* data views on every integration install #170188

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,21 @@ export async function installKibanaAssets(options: {
return [];
}

// As we use `import` to create our saved objects, we have to install
// their references (the index patterns) at the same time
// to prevent a reference error
// Create index patterns separately with `overwrite: false` to prevent blowing away users' runtime fields.
// These don't get retried on conflict, because we expect that they exist once an integration has been installed.
const indexPatternSavedObjects = getIndexPatternSavedObjects() as ArchiveAsset[];
await savedObjectsImporter.import({
overwrite: false,
readStream: createListStream(indexPatternSavedObjects),
createNewCopies: false,
refresh: false,
managed: true,
});

const installedAssets = await installKibanaSavedObjects({
logger,
savedObjectsImporter,
kibanaAssets: [...indexPatternSavedObjects, ...assetsToInstall],
kibanaAssets: assetsToInstall,
});

return installedAssets;
Expand Down
77 changes: 77 additions & 0 deletions x-pack/test/fleet_api_integration/apis/epm/data_views.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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';
import { setupFleetAndAgents } from '../agents/services';

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;

const supertest = getService('supertest');

const testPkgs = [
{
name: 'apache',
version: '0.1.4',
},
{
name: 'nginx',
version: '1.2.1',
},
];

const uninstallPackage = async (name: string, version: string) => {
await supertest.delete(`/api/fleet/epm/packages/${name}/${version}`).set('kbn-xsrf', 'xxxx');
};

const installPackage = async (name: string, version: string) => {
await supertest
.post(`/api/fleet/epm/packages/${name}/${version}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true });
};

const listDataViews = async () => {
const response = await supertest.get('/api/data_views');

return response.body.data_view;
};

describe('EPM - data views', () => {
skipIfNoDockerRegistry(providerContext);
setupFleetAndAgents(providerContext);

afterEach(async () => {
await Promise.all(testPkgs.map((pkg) => uninstallPackage(pkg.name, pkg.version)));
});

describe('with subsequent integration installation', async () => {
it('does not recreate managed data views', async () => {
await installPackage(testPkgs[0].name, testPkgs[0].version);
const initialDataViews: any[] = await listDataViews();
const initialLogsDataView = initialDataViews.find(({ title }) => title === 'logs-*');
const initialMetricsDataView = initialDataViews.find(({ title }) => title === 'metrics-*');

expect(initialLogsDataView).to.be.ok();
expect(initialMetricsDataView).to.be.ok();

await installPackage(testPkgs[1].name, testPkgs[1].version);
const subsequentDataViews: any[] = await listDataViews();
const subsequentLogsDataView = subsequentDataViews.find(({ title }) => title === 'logs-*');
const subsequentMetricsDataView = subsequentDataViews.find(
({ title }) => title === 'metrics-*'
);

// ID's should not have changed as the data views should not have been recreated
expect(initialLogsDataView.id).to.eql(subsequentLogsDataView.id);
expect(initialMetricsDataView.id).to.eql(subsequentMetricsDataView.id);
});
});
});
}
1 change: 1 addition & 0 deletions x-pack/test/fleet_api_integration/apis/epm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ export default function loadTests({ loadTestFile, getService }) {
loadTestFile(require.resolve('./routing_rules'));
loadTestFile(require.resolve('./install_runtime_field'));
loadTestFile(require.resolve('./get_templates_inputs'));
loadTestFile(require.resolve('./data_views'));
});
}
Loading