Skip to content

Commit

Permalink
[Ingest Manager] stop creating events-* index pattern and placeholder…
Browse files Browse the repository at this point in the history
… index (elastic#74683)

* stop creating events-* index pattern and indices

* add integration test to check for placeholder indices
# Conflicts:
#	x-pack/test/ingest_manager_api_integration/apis/epm/install_remove_assets.ts
  • Loading branch information
neptunian committed Aug 10, 2020
1 parent bcf3379 commit 0a57acd
Show file tree
Hide file tree
Showing 2 changed files with 268 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export interface IndexPatternField {
export enum IndexPatternType {
logs = 'logs',
metrics = 'metrics',
events = 'events',
}
// TODO: use a function overload and make pkgName and pkgVersion required for install/update
// and not for an update removal. or separate out the functions
Expand Down Expand Up @@ -111,11 +110,7 @@ export async function installIndexPatterns(
const installedPackagesInfo = await Promise.all(installedPackagesFetchInfoPromise);

// for each index pattern type, create an index pattern
const indexPatternTypes = [
IndexPatternType.logs,
IndexPatternType.metrics,
IndexPatternType.events,
];
const indexPatternTypes = [IndexPatternType.logs, IndexPatternType.metrics];
indexPatternTypes.forEach(async (indexPatternType) => {
// if this is an update because a package is being unisntalled (no pkgkey argument passed) and no other packages are installed, remove the index pattern
if (!pkgName && installedPackages.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

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 kibanaServer = getService('kibanaServer');
const supertest = getService('supertest');
const es = getService('es');
const pkgName = 'all_assets';
const pkgVersion = '0.1.0';
const pkgKey = `${pkgName}-${pkgVersion}`;
const logsTemplateName = `logs-${pkgName}.test_logs`;
const metricsTemplateName = `metrics-${pkgName}.test_metrics`;

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

describe('installs and uninstalls all assets', async () => {
describe('installs all assets when installing a package for the first time', async () => {
skipIfNoDockerRegistry(providerContext);
before(async () => {
await installPackage(pkgKey);
});
it('should have installed the ILM policy', async function () {
const resPolicy = await es.transport.request({
method: 'GET',
path: `/_ilm/policy/all_assets`,
});
expect(resPolicy.statusCode).equal(200);
});
it('should have installed the index templates', async function () {
const resLogsTemplate = await es.transport.request({
method: 'GET',
path: `/_index_template/${logsTemplateName}`,
});
expect(resLogsTemplate.statusCode).equal(200);

const resMetricsTemplate = await es.transport.request({
method: 'GET',
path: `/_index_template/${metricsTemplateName}`,
});
expect(resMetricsTemplate.statusCode).equal(200);
});
it('should have installed the pipelines', async function () {
const res = await es.transport.request({
method: 'GET',
path: `/_ingest/pipeline/${logsTemplateName}-${pkgVersion}`,
});
expect(res.statusCode).equal(200);
});
it('should have installed the template components', async function () {
const res = await es.transport.request({
method: 'GET',
path: `/_component_template/${logsTemplateName}-mappings`,
});
expect(res.statusCode).equal(200);
const resSettings = await es.transport.request({
method: 'GET',
path: `/_component_template/${logsTemplateName}-settings`,
});
expect(resSettings.statusCode).equal(200);
});
it('should have installed the kibana assets', async function () {
const resIndexPatternLogs = await kibanaServer.savedObjects.get({
type: 'index-pattern',
id: 'logs-*',
});
expect(resIndexPatternLogs.id).equal('logs-*');
const resIndexPatternMetrics = await kibanaServer.savedObjects.get({
type: 'index-pattern',
id: 'metrics-*',
});
expect(resIndexPatternMetrics.id).equal('metrics-*');
const resDashboard = await kibanaServer.savedObjects.get({
type: 'dashboard',
id: 'sample_dashboard',
});
expect(resDashboard.id).equal('sample_dashboard');
const resDashboard2 = await kibanaServer.savedObjects.get({
type: 'dashboard',
id: 'sample_dashboard2',
});
expect(resDashboard2.id).equal('sample_dashboard2');
const resVis = await kibanaServer.savedObjects.get({
type: 'visualization',
id: 'sample_visualization',
});
expect(resVis.id).equal('sample_visualization');
const resSearch = await kibanaServer.savedObjects.get({
type: 'search',
id: 'sample_search',
});
expect(resSearch.id).equal('sample_search');
});
it('should have installed placeholder indices', async function () {
const resLogsIndexPatternPlaceholder = await es.transport.request({
method: 'GET',
path: `/logs-index_pattern_placeholder`,
});
expect(resLogsIndexPatternPlaceholder.statusCode).equal(200);
const resMetricsIndexPatternPlaceholder = await es.transport.request({
method: 'GET',
path: `/metrics-index_pattern_placeholder`,
});
expect(resMetricsIndexPatternPlaceholder.statusCode).equal(200);
});
it('should have created the correct saved object', async function () {
const res = await kibanaServer.savedObjects.get({
type: 'epm-packages',
id: 'all_assets',
});
expect(res.attributes).eql({
installed_kibana: [
{
id: 'sample_dashboard',
type: 'dashboard',
},
{
id: 'sample_dashboard2',
type: 'dashboard',
},
{
id: 'sample_search',
type: 'search',
},
{
id: 'sample_visualization',
type: 'visualization',
},
],
installed_es: [
{
id: 'logs-all_assets.test_logs-0.1.0',
type: 'ingest_pipeline',
},
{
id: 'logs-all_assets.test_logs',
type: 'index_template',
},
{
id: 'metrics-all_assets.test_metrics',
type: 'index_template',
},
],
es_index_patterns: {
test_logs: 'logs-all_assets.test_logs-*',
test_metrics: 'metrics-all_assets.test_metrics-*',
},
name: 'all_assets',
version: '0.1.0',
internal: false,
removable: true,
});
});
});

describe('uninstalls all assets when uninstalling a package', async () => {
skipIfNoDockerRegistry(providerContext);
before(async () => {
await uninstallPackage(pkgKey);
});
it('should have uninstalled the index templates', async function () {
const resLogsTemplate = await es.transport.request(
{
method: 'GET',
path: `/_index_template/${logsTemplateName}`,
},
{
ignore: [404],
}
);
expect(resLogsTemplate.statusCode).equal(404);

const resMetricsTemplate = await es.transport.request(
{
method: 'GET',
path: `/_index_template/${metricsTemplateName}`,
},
{
ignore: [404],
}
);
expect(resMetricsTemplate.statusCode).equal(404);
});
it('should have uninstalled the pipelines', async function () {
const res = await es.transport.request(
{
method: 'GET',
path: `/_ingest/pipeline/${logsTemplateName}-${pkgVersion}`,
},
{
ignore: [404],
}
);
expect(res.statusCode).equal(404);
});
it('should have uninstalled the kibana assets', async function () {
let resDashboard;
try {
resDashboard = await kibanaServer.savedObjects.get({
type: 'dashboard',
id: 'sample_dashboard',
});
} catch (err) {
resDashboard = err;
}
expect(resDashboard.response.data.statusCode).equal(404);
let resDashboard2;
try {
resDashboard2 = await kibanaServer.savedObjects.get({
type: 'dashboard',
id: 'sample_dashboard2',
});
} catch (err) {
resDashboard2 = err;
}
expect(resDashboard2.response.data.statusCode).equal(404);
let resVis;
try {
resVis = await kibanaServer.savedObjects.get({
type: 'visualization',
id: 'sample_visualization',
});
} catch (err) {
resVis = err;
}
expect(resVis.response.data.statusCode).equal(404);
let resSearch;
try {
resVis = await kibanaServer.savedObjects.get({
type: 'search',
id: 'sample_search',
});
} catch (err) {
resSearch = err;
}
expect(resSearch.response.data.statusCode).equal(404);
});
it('should have removed the saved object', async function () {
let res;
try {
res = await kibanaServer.savedObjects.get({
type: 'epm-packages',
id: 'all_assets',
});
} catch (err) {
res = err;
}
expect(res.response.data.statusCode).equal(404);
});
});
});
}

0 comments on commit 0a57acd

Please sign in to comment.