Skip to content

Commit

Permalink
[Dataset Quality] Move /integrations/{id}/dashboards API Integratio…
Browse files Browse the repository at this point in the history
…n test to Deployment Agnostic (elastic#205256)

Move the `GET /internal/dataset_quality/integrations/{integration}/dashboards` API test to Deployment Agnostic.
  • Loading branch information
awahab07 authored and CAWilson94 committed Jan 10, 2025
1 parent 4e021b0 commit f2515cd
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
}
3 changes: 0 additions & 3 deletions x-pack/test/dataset_quality_api_integration/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
InheritedFtrProviderContext,
InheritedServices,
} from './ftr_provider_context';
import { PackageService } from './package_service';
import { RegistryProvider } from './registry';

export interface DatasetQualityFtrConfig {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +130,6 @@ export function createTestConfig(
servicesRequiredForTestAnalysis: ['datasetQualityFtrConfig', 'registry'],
services: {
...services,
packageService: PackageService,
datasetQualityFtrConfig: () => config,
registry: RegistryProvider,
logSynthtraceEsClient: (context: InheritedFtrProviderContext) =>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { Client } from '@elastic/elasticsearch';
import { IndicesIndexSettings } from '@elastic/elasticsearch/lib/api/types';

export async function addIntegrationToLogIndexTemplate({
esClient,
Expand Down Expand Up @@ -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,
});
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit f2515cd

Please sign in to comment.