Skip to content

Commit

Permalink
[Stack Monitoring] api tests for kibana (#145230)
Browse files Browse the repository at this point in the history
## Summary
Part of #119658

Add api integration tests for kibana routes to validate behavior when
reading data ingested by elastic-agent.

We currently have a testing suite for legacy and another one for
metricbeat. Since metricbeat and agent documents only differ in their
metadata, for example agent will populate a `data_stream.*` property to
identify the document types while metricbeat uses `metricset.*`, the
tests assertion validating _business_ data should pass regardless of the
documents source. With this in mind the metricbeat tests were updated to
run the tests twice, one time with metricbeat data and a second time
with package data.

To generate the archives the `metrics-*` mappings were extracted with
esArchiver from an elasticsearch with the package installed, and the
documents were transformed from the metricbeat documents with [this
script](https://gist.github.com/klacabane/654497ff86053c60af6df15fa6f6f657).

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
klacabane and kibanamachine authored Nov 17, 2022
1 parent 4fb9922 commit 90f0ae2
Show file tree
Hide file tree
Showing 9 changed files with 14,409 additions and 116 deletions.
51 changes: 27 additions & 24 deletions x-pack/test/api_integration/apis/monitoring/kibana/instance_mb.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,37 @@ export default function ({ getService }) {
const supertest = getService('supertest');
const { setup, tearDown } = getLifecycleMethods(getService);

describe('instance detail mb', () => {
const archive =
'x-pack/test/functional/es_archives/monitoring/singlecluster_yellow_platinum_mb';
const timeRange = {
min: '2017-08-29T17:24:17.000Z',
max: '2017-08-29T17:26:08.000Z',
};
describe('instance detail - metricbeat and package', () => {
['mb', 'package'].forEach((source) => {
describe(`instance detail ${source}`, () => {
const archive = `x-pack/test/functional/es_archives/monitoring/singlecluster_yellow_platinum_${source}`;
const timeRange = {
min: '2017-08-29T17:24:17.000Z',
max: '2017-08-29T17:26:08.000Z',
};

before('load archive', () => {
return setup(archive);
});
before('load archive', () => {
return setup(archive);
});

after('unload archive', () => {
return tearDown();
});
after('unload archive', () => {
return tearDown(archive);
});

it('should summarize single kibana instance with metrics', async () => {
const { body } = await supertest
.post(
'/api/monitoring/v1/clusters/DFDDUmKHR0Ge0mkdYW2bew/kibana/de3b8f2a-7bb9-4931-9bf3-997ba7824cf9'
)
.set('kbn-xsrf', 'xxx')
.send({ timeRange })
.expect(200);
it('should summarize single kibana instance with metrics', async () => {
const { body } = await supertest
.post(
'/api/monitoring/v1/clusters/DFDDUmKHR0Ge0mkdYW2bew/kibana/de3b8f2a-7bb9-4931-9bf3-997ba7824cf9'
)
.set('kbn-xsrf', 'xxx')
.send({ timeRange })
.expect(200);

body.metrics = normalizeDataTypeDifferences(body.metrics, instanceFixture);
instanceFixture.metrics = setIndicesFound(instanceFixture.metrics, true);
expect(body).to.eql(instanceFixture);
body.metrics = normalizeDataTypeDifferences(body.metrics, instanceFixture);
instanceFixture.metrics = setIndicesFound(instanceFixture.metrics, true);
expect(body).to.eql(instanceFixture);
});
});
});
});
}
63 changes: 33 additions & 30 deletions x-pack/test/api_integration/apis/monitoring/kibana/listing_mb.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,39 @@ export default function ({ getService }) {
const supertest = getService('supertest');
const { setup, tearDown } = getLifecycleMethods(getService);

describe('listing mb', () => {
const archive =
'x-pack/test/functional/es_archives/monitoring/singlecluster_yellow_platinum_mb';
const timeRange = {
min: '2017-08-29T17:24:17.000Z',
max: '2017-08-29T17:26:08.000Z',
};

before('load archive', () => {
return setup(archive);
});

after('unload archive', () => {
return tearDown();
});

it('should summarize list of kibana instances with stats', async () => {
const { body } = await supertest
.post('/api/monitoring/v1/clusters/DFDDUmKHR0Ge0mkdYW2bew/kibana/instances')
.set('kbn-xsrf', 'xxx')
.send({ timeRange })
.expect(200);

// Fixture is shared between internal and Metricbeat collection tests
// But timestamps of documents differ by a few miliseconds
const lastSeenTimestamp = body.kibanas[0].lastSeenTimestamp;
delete body.kibanas[0].lastSeenTimestamp;

expect(body).to.eql(listingFixture);
expect(lastSeenTimestamp).to.eql('2017-08-29T17:25:43.192Z');
describe('listing - metricbeat and package', () => {
['mb', 'package'].forEach((source) => {
describe(`listing ${source}`, () => {
const archive = `x-pack/test/functional/es_archives/monitoring/singlecluster_yellow_platinum_${source}`;
const timeRange = {
min: '2017-08-29T17:24:17.000Z',
max: '2017-08-29T17:26:08.000Z',
};

before('load archive', () => {
return setup(archive);
});

after('unload archive', () => {
return tearDown(archive);
});

it('should summarize list of kibana instances with stats', async () => {
const { body } = await supertest
.post('/api/monitoring/v1/clusters/DFDDUmKHR0Ge0mkdYW2bew/kibana/instances')
.set('kbn-xsrf', 'xxx')
.send({ timeRange })
.expect(200);

// Fixture is shared between internal and Metricbeat collection tests
// But timestamps of documents differ by a few miliseconds
const lastSeenTimestamp = body.kibanas[0].lastSeenTimestamp;
delete body.kibanas[0].lastSeenTimestamp;

expect(body).to.eql(listingFixture);
expect(lastSeenTimestamp).to.eql('2017-08-29T17:25:43.192Z');
});
});
});
});
}
47 changes: 25 additions & 22 deletions x-pack/test/api_integration/apis/monitoring/kibana/overview_mb.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,35 @@ export default function ({ getService }) {
const supertest = getService('supertest');
const { setup, tearDown } = getLifecycleMethods(getService);

describe('overview mb', () => {
const archive =
'x-pack/test/functional/es_archives/monitoring/singlecluster_yellow_platinum_mb';
const timeRange = {
min: '2017-08-29T17:24:17.000Z',
max: '2017-08-29T17:26:08.000Z',
};
describe('overview - metricbeat and package', () => {
['mb', 'package'].forEach((source) => {
describe(`overview ${source}`, () => {
const archive = `x-pack/test/functional/es_archives/monitoring/singlecluster_yellow_platinum_${source}`;
const timeRange = {
min: '2017-08-29T17:24:17.000Z',
max: '2017-08-29T17:26:08.000Z',
};

before('load archive', () => {
return setup(archive);
});
before('load archive', () => {
return setup(archive);
});

after('unload archive', () => {
return tearDown();
});
after('unload archive', () => {
return tearDown(archive);
});

it('should summarize kibana instances with stats', async () => {
const { body } = await supertest
.post('/api/monitoring/v1/clusters/DFDDUmKHR0Ge0mkdYW2bew/kibana')
.set('kbn-xsrf', 'xxx')
.send({ timeRange })
.expect(200);
it('should summarize kibana instances with stats', async () => {
const { body } = await supertest
.post('/api/monitoring/v1/clusters/DFDDUmKHR0Ge0mkdYW2bew/kibana')
.set('kbn-xsrf', 'xxx')
.send({ timeRange })
.expect(200);

body.metrics = normalizeDataTypeDifferences(body.metrics, overviewFixture);
overviewFixture.metrics = setIndicesFound(overviewFixture.metrics, true);
expect(body).to.eql(overviewFixture);
body.metrics = normalizeDataTypeDifferences(body.metrics, overviewFixture);
overviewFixture.metrics = setIndicesFound(overviewFixture.metrics, true);
expect(body).to.eql(overviewFixture);
});
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,34 @@ export default function ({ getService }) {
const supertest = getService('supertest');
const { setup, tearDown } = getLifecycleMethods(getService);

describe('instance detail', () => {
const archive = 'x-pack/test/functional/es_archives/monitoring/kibana/rules_and_actions';
const timeRange = {
min: '2022-05-31T18:44:19.267Z',
max: '2022-05-31T19:59:19.267Z',
};
describe('instance detail - metricbeat and package', () => {
['rules_and_actions', 'rules_and_actions_package'].forEach((source) => {
describe(`instance detail ${source}`, () => {
const archive = `x-pack/test/functional/es_archives/monitoring/kibana/${source}`;
const timeRange = {
min: '2022-05-31T18:44:19.267Z',
max: '2022-05-31T19:59:19.267Z',
};

before('load archive', () => {
return setup(archive);
});
before('load archive', () => {
return setup(archive);
});

after('unload archive', () => {
return tearDown();
});
after('unload archive', () => {
return tearDown(archive);
});

it('should get data for the kibana instance view', async () => {
const { body } = await supertest
.post(
'/api/monitoring/v1/clusters/SvjwrFv6Rvuqjm9-cSSVEg/kibana/5b2de169-2785-441b-ae8c-186a1936b17d'
)
.set('kbn-xsrf', 'xxx')
.send({ timeRange })
.expect(200);
expect(body).to.eql(fixture);
it('should get data for the kibana instance view', async () => {
const { body } = await supertest
.post(
'/api/monitoring/v1/clusters/SvjwrFv6Rvuqjm9-cSSVEg/kibana/5b2de169-2785-441b-ae8c-186a1936b17d'
)
.set('kbn-xsrf', 'xxx')
.send({ timeRange })
.expect(200);
expect(body).to.eql(fixture);
});
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,33 @@ export default function ({ getService }) {
const supertest = getService('supertest');
const { setup, tearDown } = getLifecycleMethods(getService);

describe('overview', () => {
const archive = 'x-pack/test/functional/es_archives/monitoring/kibana/rules_and_actions';
const timeRange = {
min: '2022-05-31T18:44:19.267Z',
max: '2022-05-31T19:59:19.267Z',
};
describe('overview - metricbeat and package', () => {
['rules_and_actions', 'rules_and_actions_package'].forEach((source) => {
describe(`overview ${source}`, () => {
const archive = `x-pack/test/functional/es_archives/monitoring/kibana/${source}`;
const timeRange = {
min: '2022-05-31T18:44:19.267Z',
max: '2022-05-31T19:59:19.267Z',
};

before('load archive', () => {
return setup(archive);
});
before('load archive', () => {
return setup(archive);
});

after('unload archive', () => {
return tearDown();
});
after('unload archive', () => {
return tearDown(archive);
});

it('should get kibana rules at cluster level', async () => {
const { body } = await supertest
.post('/api/monitoring/v1/clusters/SvjwrFv6Rvuqjm9-cSSVEg')
.set('kbn-xsrf', 'xxx')
.send({ timeRange, codePaths: ['all'] })
.expect(200);
it('should get kibana rules at cluster level', async () => {
const { body } = await supertest
.post('/api/monitoring/v1/clusters/SvjwrFv6Rvuqjm9-cSSVEg')
.set('kbn-xsrf', 'xxx')
.send({ timeRange, codePaths: ['all'] })
.expect(200);

expect(body[0].kibana.rules).to.eql(fixture[0].kibana.rules);
expect(body[0].kibana.rules).to.eql(fixture[0].kibana.rules);
});
});
});
});
}
Binary file not shown.
Loading

0 comments on commit 90f0ae2

Please sign in to comment.