mirror of
https://github.com/elastic/kibana.git
synced 2025-06-29 03:24:45 -04:00
closes [#198015](https://github.com/elastic/kibana/issues/198015) ## Summary Migrate most of the infra APIs integration tests to the deployment-agnostic approach. >[!important] > - Metrics UI related tests were note migrated because the feature is not enabled on serverless. > - `Host with active alerts` test was not migrated because `es_archiver` fails to load the alerts data. This is because on serverless, the alerts indices are created as managed data streams and that causes the `es_archiver` to fail. We should probably try use synthtrace. - [x] Tested against MKI - [x] Tested against stateful --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
/*
|
|
* 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 { GetInfraMetricsRequestBodyPayloadClient } from '@kbn/infra-plugin/common/http_api/infra';
|
|
import { DATES } from './utils/constants';
|
|
import type { FtrProviderContext } from '../../ftr_provider_context';
|
|
|
|
const ENDPOINT = '/api/metrics/infra/host';
|
|
|
|
export default function ({ getService }: FtrProviderContext) {
|
|
const esArchiver = getService('esArchiver');
|
|
const supertest = getService('supertest');
|
|
|
|
const basePayload: GetInfraMetricsRequestBodyPayloadClient = {
|
|
limit: 10,
|
|
metrics: [
|
|
'cpu',
|
|
'cpuV2',
|
|
'diskSpaceUsage',
|
|
'memory',
|
|
'memoryFree',
|
|
'normalizedLoad1m',
|
|
'rx',
|
|
'tx',
|
|
],
|
|
from: new Date(DATES['8.0.0'].logs_and_metrics.min).toISOString(),
|
|
to: new Date(DATES['8.0.0'].logs_and_metrics.max).toISOString(),
|
|
query: { bool: { must_not: [], filter: [], should: [], must: [] } },
|
|
};
|
|
|
|
describe('Hosts', () => {
|
|
const makeRequest = async ({
|
|
body,
|
|
invalidBody,
|
|
expectedHTTPCode,
|
|
}: {
|
|
body?: GetInfraMetricsRequestBodyPayloadClient;
|
|
invalidBody?: any;
|
|
expectedHTTPCode: number;
|
|
}) => {
|
|
return supertest
|
|
.post(ENDPOINT)
|
|
.send(body ?? invalidBody)
|
|
.expect(expectedHTTPCode);
|
|
};
|
|
|
|
// TODO: This test fails on serverless because the alerts esarchiver is not loaded
|
|
// This happens because in serverless .alerts.* indicies are managed data streams
|
|
// and the esarchiver fails because the mapping.json is configured to create an index
|
|
describe('Host with active alerts', () => {
|
|
before(async () => {
|
|
await Promise.all([
|
|
esArchiver.load('x-pack/test/functional/es_archives/infra/alerts'),
|
|
esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs'),
|
|
]);
|
|
});
|
|
|
|
after(async () => {
|
|
await Promise.all([
|
|
esArchiver.unload('x-pack/test/functional/es_archives/infra/alerts'),
|
|
esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs'),
|
|
]);
|
|
});
|
|
|
|
describe('fetch hosts', () => {
|
|
it('should return metrics for a host with alert count', async () => {
|
|
const body: GetInfraMetricsRequestBodyPayloadClient = {
|
|
...basePayload,
|
|
from: '2018-10-17T19:42:21.208Z',
|
|
to: '2018-10-17T19:58:03.952Z',
|
|
limit: 1,
|
|
};
|
|
const response = await makeRequest({ body, expectedHTTPCode: 200 });
|
|
|
|
expect(response.body.nodes).length(1);
|
|
expect(response.body.nodes[0].alertsCount).eql(2);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|