[Dataset Quality] Move /integrations/{id}/dashboards API Integration test to Deployment Agnostic (#205256)

Move the `GET /internal/dataset_quality/integrations/{integration}/dashboards` API test to Deployment Agnostic.
This commit is contained in:
Abdul Wahab Zahid 2025-01-08 11:31:16 +01:00 committed by GitHub
parent 9cccd303ef
commit 5c13e901ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 146 additions and 219 deletions

View file

@ -10,6 +10,7 @@ import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_cont
export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) {
describe('Dataset quality', () => {
loadTestFile(require.resolve('./integrations'));
loadTestFile(require.resolve('./integration_dashboards'));
loadTestFile(require.resolve('./degraded_field_analyze'));
loadTestFile(require.resolve('./data_stream_settings'));
loadTestFile(require.resolve('./data_stream_rollover'));

View file

@ -0,0 +1,145 @@
/*
* 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 { CustomIntegration } from '../../../services/package_api';
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials, SupertestWithRoleScopeType } from '../../../services';
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
const samlAuth = getService('samlAuth');
const roleScopedSupertest = getService('roleScopedSupertest');
const packageApi = getService('packageApi');
const integrationPackages = ['nginx', 'apache'];
const customIntegrations: CustomIntegration[] = [
{
integrationName: 'my.custom.integration',
datasets: [
{
name: 'my.custom.integration',
type: 'logs',
},
],
},
];
async function callApiAs(
roleScopedSupertestWithCookieCredentials: SupertestWithRoleScopeType,
integration: string
) {
return roleScopedSupertestWithCookieCredentials.get(
`/internal/dataset_quality/integrations/${integration}/dashboards`
);
}
describe('Integration dashboards', () => {
let adminRoleAuthc: RoleCredentials;
before(async () => {
adminRoleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('admin');
await Promise.all(
integrationPackages.map((pkg) =>
packageApi.installPackage({
roleAuthc: adminRoleAuthc,
pkg,
})
)
);
await Promise.all(
customIntegrations.map((customIntegration) =>
packageApi.installCustomIntegration({
roleAuthc: adminRoleAuthc,
customIntegration,
})
)
);
});
after(async () => {
await Promise.all(
integrationPackages.map((pkg) =>
packageApi.uninstallPackage({ roleAuthc: adminRoleAuthc, pkg })
)
);
await Promise.all(
customIntegrations.map((customIntegration) =>
packageApi.uninstallPackage({
roleAuthc: adminRoleAuthc,
pkg: customIntegration.integrationName,
})
)
);
await samlAuth.invalidateM2mApiKeyWithRoleScope(adminRoleAuthc);
});
describe('gets the installed integration dashboards', () => {
let supertestViewerWithCookieCredentials: SupertestWithRoleScopeType;
before(async () => {
supertestViewerWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope(
'viewer',
{
useCookieHeader: true,
withInternalHeaders: true,
}
);
});
it('returns a non-empty body', async () => {
const resp = await callApiAs(supertestViewerWithCookieCredentials, integrationPackages[0]);
expect(resp.body).not.empty();
});
it('returns correct number of dashboard', async () => {
const resp = await callApiAs(supertestViewerWithCookieCredentials, integrationPackages[1]);
expect(resp.body.dashboards.length).to.eql(2);
});
it('returns a list of dashboards in the correct format', async () => {
const expectedResult = {
dashboards: [
{
id: 'nginx-023d2930-f1a5-11e7-a9ef-93c69af7b129',
title: '[Metrics Nginx] Overview',
},
{
id: 'nginx-046212a0-a2a1-11e7-928f-5dbe6f6f5519',
title: '[Logs Nginx] Access and error logs',
},
{
id: 'nginx-55a9e6e0-a29e-11e7-928f-5dbe6f6f5519',
title: '[Logs Nginx] Overview',
},
],
};
const resp = await callApiAs(supertestViewerWithCookieCredentials, integrationPackages[0]);
expect(resp.body).to.eql(expectedResult);
});
it('returns an empty array for an integration without dashboards', async () => {
const expectedResult = {
dashboards: [],
};
const resp = await callApiAs(
supertestViewerWithCookieCredentials,
customIntegrations[0].integrationName
);
expect(resp.body).to.eql(expectedResult);
});
it('returns an empty array for an invalid integration', async () => {
const expectedResult = {
dashboards: [],
};
const resp = await callApiAs(supertestViewerWithCookieCredentials, 'invalid');
expect(resp.body).to.eql(expectedResult);
});
});
});
}

View file

@ -28,7 +28,6 @@ import {
InheritedFtrProviderContext,
InheritedServices,
} from './ftr_provider_context';
import { PackageService } from './package_service';
import { RegistryProvider } from './registry';
export interface DatasetQualityFtrConfig {
@ -81,7 +80,6 @@ export interface CreateTest {
context: InheritedFtrProviderContext
) => SyntheticsSynthtraceEsClient;
datasetQualityApiClient: (context: InheritedFtrProviderContext) => DatasetQualityApiClient;
packageService: ({ getService }: FtrProviderContext) => ReturnType<typeof PackageService>;
};
junit: { reportName: string };
esTestCluster: any;
@ -132,7 +130,6 @@ export function createTestConfig(
servicesRequiredForTestAnalysis: ['datasetQualityFtrConfig', 'registry'],
services: {
...services,
packageService: PackageService,
datasetQualityFtrConfig: () => config,
registry: RegistryProvider,
logSynthtraceEsClient: (context: InheritedFtrProviderContext) =>

View file

@ -1,30 +0,0 @@
/*
* 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 { FtrProviderContext } from './ftr_provider_context';
interface IntegrationPackage {
name: string;
version: string;
}
export function PackageService({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
function uninstallPackage({ name, version }: IntegrationPackage) {
return supertest.delete(`/api/fleet/epm/packages/${name}/${version}`).set('kbn-xsrf', 'xxxx');
}
function installPackage({ name, version }: IntegrationPackage) {
return supertest
.post(`/api/fleet/epm/packages/${name}/${version}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true });
}
return { uninstallPackage, installPackage };
}

View file

@ -6,7 +6,6 @@
*/
import { Client } from '@elastic/elasticsearch';
import { IndicesIndexSettings } from '@elastic/elasticsearch/lib/api/types';
export async function addIntegrationToLogIndexTemplate({
esClient,
@ -53,35 +52,3 @@ export async function cleanLogIndexTemplate({ esClient }: { esClient: Client })
},
});
}
function getCurrentDateFormatted() {
const date = new Date();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}.${month}.${day}`;
}
export function createBackingIndexNameWithoutVersion({
type,
dataset,
namespace = 'default',
}: {
type: string;
dataset: string;
namespace: string;
}) {
return `.ds-${type}-${dataset}-${namespace}-${getCurrentDateFormatted()}`;
}
export async function setDataStreamSettings(
esClient: Client,
name: string,
settings: IndicesIndexSettings
) {
return esClient.indices.putSettings({
index: name,
settings,
});
}

View file

@ -1,86 +0,0 @@
/*
* 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 { DatasetQualityApiClientKey } from '../../common/config';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { installPackage, uninstallPackage } from './package_utils';
export default function ApiTest({ getService }: FtrProviderContext) {
const registry = getService('registry');
const supertest = getService('supertest');
const datasetQualityApiClient = getService('datasetQualityApiClient');
const integrationPackages = ['nginx', 'apm'];
async function callApiAs(integration: string) {
const user = 'datasetQualityMonitorUser' as DatasetQualityApiClientKey;
return await datasetQualityApiClient[user]({
endpoint: 'GET /internal/dataset_quality/integrations/{integration}/dashboards',
params: {
path: {
integration,
},
},
});
}
registry.when('Integration dashboards', { config: 'basic' }, () => {
describe('gets the installed integration dashboards', () => {
before(async () => {
await Promise.all(integrationPackages.map((pkg) => installPackage({ supertest, pkg })));
});
it('returns a non-empty body', async () => {
const resp = await callApiAs(integrationPackages[0]);
expect(resp.body).not.empty();
});
it('returns a list of dashboards in the correct format', async () => {
const expectedResult = {
dashboards: [
{
id: 'nginx-023d2930-f1a5-11e7-a9ef-93c69af7b129',
title: '[Metrics Nginx] Overview',
},
{
id: 'nginx-046212a0-a2a1-11e7-928f-5dbe6f6f5519',
title: '[Logs Nginx] Access and error logs',
},
{
id: 'nginx-55a9e6e0-a29e-11e7-928f-5dbe6f6f5519',
title: '[Logs Nginx] Overview',
},
],
};
const resp = await callApiAs(integrationPackages[0]);
expect(resp.body).to.eql(expectedResult);
});
it('returns an empty array for an integration without dashboards', async () => {
const expectedResult = {
dashboards: [],
};
const resp = await callApiAs(integrationPackages[1]);
expect(resp.body).to.eql(expectedResult);
});
it('returns an empty array for an invalid integration', async () => {
const expectedResult = {
dashboards: [],
};
const resp = await callApiAs('invalid');
expect(resp.body).to.eql(expectedResult);
});
after(
async () =>
await Promise.all(integrationPackages.map((pkg) => uninstallPackage({ supertest, pkg })))
);
});
});
}

View file

@ -1,40 +0,0 @@
/*
* 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 { Agent as SuperTestAgent } from 'supertest';
export async function installPackage({
supertest,
pkg,
}: {
supertest: SuperTestAgent;
pkg: string;
}) {
const {
body: {
item: { latestVersion: version },
},
} = await supertest
.get(`/api/fleet/epm/packages/${pkg}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true });
return supertest
.post(`/api/fleet/epm/packages/${pkg}/${version}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true });
}
export async function uninstallPackage({
supertest,
pkg,
}: {
supertest: SuperTestAgent;
pkg: string;
}) {
return supertest.delete(`/api/fleet/epm/packages/${pkg}`).set('kbn-xsrf', 'xxxx');
}

View file

@ -1,26 +0,0 @@
/*
* 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 { Client } from '@elastic/elasticsearch';
export async function rolloverDataStream(es: Client, name: string) {
return es.indices.rollover({ alias: name });
}
export async function getDataStreamSettingsOfEarliestIndex(es: Client, name: string) {
const matchingIndexesObj = await es.indices.getSettings({ index: name });
const matchingIndexes = Object.keys(matchingIndexesObj ?? {});
matchingIndexes.sort((a, b) => {
return (
Number(matchingIndexesObj[a].settings?.index?.creation_date) -
Number(matchingIndexesObj[b].settings?.index?.creation_date)
);
});
return matchingIndexesObj[matchingIndexes[0]].settings;
}

View file

@ -8,4 +8,3 @@
export { joinByKey } from './join_by_key';
export { maybe } from './maybe';
export { expectToReject } from './expect_to_reject';
export * from './data_stream';