Skip to content

Commit 5c13e90

Browse files
authored
[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.
1 parent 9cccd30 commit 5c13e90

File tree

9 files changed

+146
-219
lines changed

9 files changed

+146
-219
lines changed

x-pack/test/api_integration/deployment_agnostic/apis/observability/dataset_quality/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_cont
1010
export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) {
1111
describe('Dataset quality', () => {
1212
loadTestFile(require.resolve('./integrations'));
13+
loadTestFile(require.resolve('./integration_dashboards'));
1314
loadTestFile(require.resolve('./degraded_field_analyze'));
1415
loadTestFile(require.resolve('./data_stream_settings'));
1516
loadTestFile(require.resolve('./data_stream_rollover'));
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import expect from '@kbn/expect';
9+
import { CustomIntegration } from '../../../services/package_api';
10+
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
11+
import { RoleCredentials, SupertestWithRoleScopeType } from '../../../services';
12+
13+
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
14+
const samlAuth = getService('samlAuth');
15+
const roleScopedSupertest = getService('roleScopedSupertest');
16+
const packageApi = getService('packageApi');
17+
18+
const integrationPackages = ['nginx', 'apache'];
19+
const customIntegrations: CustomIntegration[] = [
20+
{
21+
integrationName: 'my.custom.integration',
22+
datasets: [
23+
{
24+
name: 'my.custom.integration',
25+
type: 'logs',
26+
},
27+
],
28+
},
29+
];
30+
31+
async function callApiAs(
32+
roleScopedSupertestWithCookieCredentials: SupertestWithRoleScopeType,
33+
integration: string
34+
) {
35+
return roleScopedSupertestWithCookieCredentials.get(
36+
`/internal/dataset_quality/integrations/${integration}/dashboards`
37+
);
38+
}
39+
40+
describe('Integration dashboards', () => {
41+
let adminRoleAuthc: RoleCredentials;
42+
before(async () => {
43+
adminRoleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('admin');
44+
await Promise.all(
45+
integrationPackages.map((pkg) =>
46+
packageApi.installPackage({
47+
roleAuthc: adminRoleAuthc,
48+
pkg,
49+
})
50+
)
51+
);
52+
53+
await Promise.all(
54+
customIntegrations.map((customIntegration) =>
55+
packageApi.installCustomIntegration({
56+
roleAuthc: adminRoleAuthc,
57+
customIntegration,
58+
})
59+
)
60+
);
61+
});
62+
63+
after(async () => {
64+
await Promise.all(
65+
integrationPackages.map((pkg) =>
66+
packageApi.uninstallPackage({ roleAuthc: adminRoleAuthc, pkg })
67+
)
68+
);
69+
70+
await Promise.all(
71+
customIntegrations.map((customIntegration) =>
72+
packageApi.uninstallPackage({
73+
roleAuthc: adminRoleAuthc,
74+
pkg: customIntegration.integrationName,
75+
})
76+
)
77+
);
78+
79+
await samlAuth.invalidateM2mApiKeyWithRoleScope(adminRoleAuthc);
80+
});
81+
82+
describe('gets the installed integration dashboards', () => {
83+
let supertestViewerWithCookieCredentials: SupertestWithRoleScopeType;
84+
before(async () => {
85+
supertestViewerWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope(
86+
'viewer',
87+
{
88+
useCookieHeader: true,
89+
withInternalHeaders: true,
90+
}
91+
);
92+
});
93+
94+
it('returns a non-empty body', async () => {
95+
const resp = await callApiAs(supertestViewerWithCookieCredentials, integrationPackages[0]);
96+
expect(resp.body).not.empty();
97+
});
98+
99+
it('returns correct number of dashboard', async () => {
100+
const resp = await callApiAs(supertestViewerWithCookieCredentials, integrationPackages[1]);
101+
expect(resp.body.dashboards.length).to.eql(2);
102+
});
103+
104+
it('returns a list of dashboards in the correct format', async () => {
105+
const expectedResult = {
106+
dashboards: [
107+
{
108+
id: 'nginx-023d2930-f1a5-11e7-a9ef-93c69af7b129',
109+
title: '[Metrics Nginx] Overview',
110+
},
111+
{
112+
id: 'nginx-046212a0-a2a1-11e7-928f-5dbe6f6f5519',
113+
title: '[Logs Nginx] Access and error logs',
114+
},
115+
{
116+
id: 'nginx-55a9e6e0-a29e-11e7-928f-5dbe6f6f5519',
117+
title: '[Logs Nginx] Overview',
118+
},
119+
],
120+
};
121+
const resp = await callApiAs(supertestViewerWithCookieCredentials, integrationPackages[0]);
122+
expect(resp.body).to.eql(expectedResult);
123+
});
124+
125+
it('returns an empty array for an integration without dashboards', async () => {
126+
const expectedResult = {
127+
dashboards: [],
128+
};
129+
const resp = await callApiAs(
130+
supertestViewerWithCookieCredentials,
131+
customIntegrations[0].integrationName
132+
);
133+
expect(resp.body).to.eql(expectedResult);
134+
});
135+
136+
it('returns an empty array for an invalid integration', async () => {
137+
const expectedResult = {
138+
dashboards: [],
139+
};
140+
const resp = await callApiAs(supertestViewerWithCookieCredentials, 'invalid');
141+
expect(resp.body).to.eql(expectedResult);
142+
});
143+
});
144+
});
145+
}

x-pack/test/dataset_quality_api_integration/common/config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
InheritedFtrProviderContext,
2929
InheritedServices,
3030
} from './ftr_provider_context';
31-
import { PackageService } from './package_service';
3231
import { RegistryProvider } from './registry';
3332

3433
export interface DatasetQualityFtrConfig {
@@ -81,7 +80,6 @@ export interface CreateTest {
8180
context: InheritedFtrProviderContext
8281
) => SyntheticsSynthtraceEsClient;
8382
datasetQualityApiClient: (context: InheritedFtrProviderContext) => DatasetQualityApiClient;
84-
packageService: ({ getService }: FtrProviderContext) => ReturnType<typeof PackageService>;
8583
};
8684
junit: { reportName: string };
8785
esTestCluster: any;
@@ -132,7 +130,6 @@ export function createTestConfig(
132130
servicesRequiredForTestAnalysis: ['datasetQualityFtrConfig', 'registry'],
133131
services: {
134132
...services,
135-
packageService: PackageService,
136133
datasetQualityFtrConfig: () => config,
137134
registry: RegistryProvider,
138135
logSynthtraceEsClient: (context: InheritedFtrProviderContext) =>

x-pack/test/dataset_quality_api_integration/common/package_service.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

x-pack/test/dataset_quality_api_integration/tests/data_streams/es_utils.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import { Client } from '@elastic/elasticsearch';
9-
import { IndicesIndexSettings } from '@elastic/elasticsearch/lib/api/types';
109

1110
export async function addIntegrationToLogIndexTemplate({
1211
esClient,
@@ -53,35 +52,3 @@ export async function cleanLogIndexTemplate({ esClient }: { esClient: Client })
5352
},
5453
});
5554
}
56-
57-
function getCurrentDateFormatted() {
58-
const date = new Date();
59-
const year = date.getFullYear();
60-
const month = String(date.getMonth() + 1).padStart(2, '0');
61-
const day = String(date.getDate()).padStart(2, '0');
62-
63-
return `${year}.${month}.${day}`;
64-
}
65-
66-
export function createBackingIndexNameWithoutVersion({
67-
type,
68-
dataset,
69-
namespace = 'default',
70-
}: {
71-
type: string;
72-
dataset: string;
73-
namespace: string;
74-
}) {
75-
return `.ds-${type}-${dataset}-${namespace}-${getCurrentDateFormatted()}`;
76-
}
77-
78-
export async function setDataStreamSettings(
79-
esClient: Client,
80-
name: string,
81-
settings: IndicesIndexSettings
82-
) {
83-
return esClient.indices.putSettings({
84-
index: name,
85-
settings,
86-
});
87-
}

x-pack/test/dataset_quality_api_integration/tests/integrations/integration_dashboards.spec.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

x-pack/test/dataset_quality_api_integration/tests/integrations/package_utils.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)