Skip to content

Commit

Permalink
[Dataset Quality] /degraded_docs, /degraded_fields, /details an…
Browse files Browse the repository at this point in the history
…d `/values` deployment agnostic tests (#198277)

Move the following Dataset Quality API Integration test suites
to deployment agnostic test suites:
1. `/data_streams/degraded_docs.spec.ts`
2. `/data_streams/degraded_fields.spec.ts`
3. `/data_streams/data_stream_details.spec.ts`
4. `/data_streams/degraded_field_values.spec.ts` 

Note that individual tests (e.g. related to authorization in suites) or
test suites dependent on role management, or the ones which behave
differently on Serverless vs. Stateful, haven't been moved to deployment
agnostic.

----

After this commit, the remaining tests in Serlerless/Stateful directories
will be:

**Dataset Quality Serverless API Integration tests** (under
`x-pack/test_serverless/api_integration/test_suites/observability/dataset_quality_api_integration`):
1. `/data_stream_details.ts` _Only contains a single test which cannot
be moved to DA_

**Dataset Quality Stateful API Integration tests** (under
`x-pack/test/dataset_quality_api_integration/tests`):
1. `/data_streams/data_stream_details.spec.ts` _Only contains a single
test which cannot be moved to DA_
2. `/data_streams/degraded_docs.spec.ts` _Only contains a single test
which cannot be moved to DA_
3. `/data_streams/stats.spec.ts` _This suite whole cannot be moved to DA
as it depends on role management_
4. `/integrations/integration_dashboards.spec.ts` _Not moved in this PR_
  • Loading branch information
awahab07 authored Nov 12, 2024
1 parent 06986e4 commit d8710a4
Show file tree
Hide file tree
Showing 14 changed files with 441 additions and 447 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* 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 { LogsSynthtraceEsClient } from '@kbn/apm-synthtrace';
import expect from '@kbn/expect';
import { log, timerange } from '@kbn/apm-synthtrace-client';

import { SupertestWithRoleScopeType } from '../../../services';
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
const roleScopedSupertest = getService('roleScopedSupertest');
const synthtrace = getService('synthtrace');
const start = '2023-12-11T18:00:00.000Z';
const end = '2023-12-11T18:01:00.000Z';
const type = 'logs';
const dataset = 'nginx.access';
const namespace = 'default';
const serviceName = 'my-service';
const hostName = 'synth-host';

async function callApiAs(
roleScopedSupertestWithCookieCredentials: SupertestWithRoleScopeType,
dataStream: string
) {
return roleScopedSupertestWithCookieCredentials
.get(`/internal/dataset_quality/data_streams/${dataStream}/details`)
.query({
start,
end,
});
}

describe('DataStream Details', function () {
let synthtraceLogsEsClient: LogsSynthtraceEsClient;

before(async () => {
synthtraceLogsEsClient = await synthtrace.createLogsSynthtraceEsClient();

await synthtraceLogsEsClient.index([
timerange(start, end)
.interval('1m')
.rate(1)
.generator((timestamp) =>
log
.create()
.message('This is a log message')
.timestamp(timestamp)
.dataset(dataset)
.namespace(namespace)
.defaults({
'log.file.path': '/my-service.log',
'service.name': serviceName,
'host.name': hostName,
})
),
]);
});

after(async () => {
await synthtraceLogsEsClient.clean();
});

describe('Viewer User', function () {
let supertestViewerWithCookieCredentials: SupertestWithRoleScopeType;

before(async () => {
supertestViewerWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope(
'viewer',
{
useCookieHeader: true,
withInternalHeaders: true,
}
);
});

it('returns lastActivity as undefined when user does not have access to the data stream', async () => {
const resp = await callApiAs(
supertestViewerWithCookieCredentials,
`${type}-${dataset}-${namespace}`
);
expect(resp.body.lastActivity).to.be(undefined);

// userPrivileges.canMonitor should be false for readUser
expect(resp.body.userPrivileges?.canMonitor).to.be(false);
});
});

describe('Editor User', function () {
let supertestEditorWithCookieCredentials: SupertestWithRoleScopeType;

before(async () => {
supertestEditorWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope(
'editor',
{
useCookieHeader: true,
withInternalHeaders: true,
}
);
});

it('returns error when dataStream param is not provided', async () => {
const expectedMessage = 'Data Stream name cannot be empty';
const resp = await callApiAs(supertestEditorWithCookieCredentials, encodeURIComponent(' '));
expect(resp.status).to.be(400);
expect(resp.body.message.indexOf(expectedMessage)).to.greaterThan(-1);
});

it('returns {} if matching data stream is not available', async () => {
const nonExistentDataSet = 'Non-existent';
const nonExistentDataStream = `${type}-${nonExistentDataSet}-${namespace}`;
const resp = await callApiAs(supertestEditorWithCookieCredentials, nonExistentDataStream);
expect(resp.body).empty();
});

it('returns service.name and host.name correctly', async () => {
const resp = await callApiAs(
supertestEditorWithCookieCredentials,
`${type}-${dataset}-${namespace}`
);
expect(resp.body.services).to.eql({ ['service.name']: [serviceName] });
expect(resp.body.hosts?.['host.name']).to.eql([hostName]);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createBackingIndexNameWithoutVersion,
getDataStreamSettingsOfEarliestIndex,
rolloverDataStream,
} from './utils/es_utils';
} from './utils';
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials, SupertestWithRoleScopeType } from '../../../services';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/*
* 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 { LogsSynthtraceEsClient } from '@kbn/apm-synthtrace';
import expect from '@kbn/expect';
import rison from '@kbn/rison';
import { log, timerange } from '@kbn/apm-synthtrace-client';
import { DataStreamDocsStat } from '@kbn/dataset-quality-plugin/common/api_types';
import { SupertestWithRoleScopeType } from '../../../services';
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
const roleScopedSupertest = getService('roleScopedSupertest');
const synthtrace = getService('synthtrace');
const start = '2023-12-11T18:00:00.000Z';
const end = '2023-12-11T18:01:00.000Z';

async function callApiAs(roleScopedSupertestWithCookieCredentials: SupertestWithRoleScopeType) {
return roleScopedSupertestWithCookieCredentials
.get(`/internal/dataset_quality/data_streams/degraded_docs`)
.query({
types: rison.encodeArray(['logs']),
start,
end,
});
}

describe('Degraded docs', function () {
describe('Querying', function () {
let synthtraceLogsEsClient: LogsSynthtraceEsClient;
let supertestViewerWithCookieCredentials: SupertestWithRoleScopeType;

before(async () => {
synthtraceLogsEsClient = await synthtrace.createLogsSynthtraceEsClient();
supertestViewerWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope(
'viewer',
{
useCookieHeader: true,
withInternalHeaders: true,
}
);
});

describe('and there are log documents', () => {
before(async () => {
await synthtraceLogsEsClient.index([
timerange(start, end)
.interval('1m')
.rate(1)
.generator((timestamp) =>
log
.create()
.message('This is a log message')
.timestamp(timestamp)
.dataset('synth.1')
.defaults({
'log.file.path': '/my-service.log',
})
),
timerange(start, end)
.interval('1m')
.rate(1)
.generator((timestamp) =>
log
.create()
.message('This is a log message')
.timestamp(timestamp)
.dataset('synth.2')
.logLevel(MORE_THAN_1024_CHARS)
.defaults({
'log.file.path': '/my-service.log',
})
),
]);
});

it('returns stats correctly', async () => {
const stats = await callApiAs(supertestViewerWithCookieCredentials);
expect(stats.body.degradedDocs.length).to.be(1);

const degradedDocsStats = stats.body.degradedDocs.reduce(
(acc: Record<string, { count: number }>, curr: DataStreamDocsStat) => ({
...acc,
[curr.dataset]: {
count: curr.count,
},
}),
{}
);

expect(degradedDocsStats['logs-synth.2-default']).to.eql({
count: 1,
});
});

after(async () => {
await synthtraceLogsEsClient.clean();
});
});

describe('and there are not log documents', () => {
it('returns stats correctly', async () => {
const stats = await callApiAs(supertestViewerWithCookieCredentials);

expect(stats.body.degradedDocs.length).to.be(0);
});
});

describe('when there are data streams of different spaces', () => {
const spaces = ['default', 'space1', 'space2'];
const datasetsWithNoDegradedDocs = ['nginx.access', 'apache.access', 'mysql.access'];
const datasetsWithDegradedDocs = ['nginx.error', 'apache.error', 'mysql.error'];

before(async () => {
for (const space of spaces) {
for (const dataset of datasetsWithNoDegradedDocs) {
await synthtraceLogsEsClient.index([
timerange(start, end)
.interval('1m')
.rate(1)
.generator((timestamp) =>
log
.create()
.message('This is a log message')
.timestamp(timestamp)
.dataset(dataset)
.namespace(space)
),
]);
}

for (const dataset of datasetsWithDegradedDocs) {
await synthtraceLogsEsClient.index([
timerange(start, end)
.interval('1m')
.rate(2)
.generator((timestamp: number, index: number) =>
log
.create()
.message('This is a log message')
.timestamp(timestamp)
.dataset(dataset)
.namespace(space)
.logLevel(index % 2 === 0 ? MORE_THAN_1024_CHARS : 'This is a log message')
),
]);
}
}
});

it('returns counts and list of datasets correctly', async () => {
const stats = await callApiAs(supertestViewerWithCookieCredentials);
expect(stats.body.degradedDocs.length).to.be(9);

const expected = {
degradedDocs: [
{
dataset: 'logs-apache.error-default',
count: 1,
},
{
dataset: 'logs-apache.error-space1',
count: 1,
},
{
dataset: 'logs-apache.error-space2',
count: 1,
},
{
dataset: 'logs-mysql.error-default',
count: 1,
},
{
dataset: 'logs-mysql.error-space1',
count: 1,
},
{
dataset: 'logs-mysql.error-space2',
count: 1,
},
{
dataset: 'logs-nginx.error-default',
count: 1,
},
{
dataset: 'logs-nginx.error-space1',
count: 1,
},
{
dataset: 'logs-nginx.error-space2',
count: 1,
},
],
};

expect(stats.body).to.eql(expected);
});

after(async () => {
await synthtraceLogsEsClient.clean();
});
});
});
});
}

const MORE_THAN_1024_CHARS =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { log, timerange } from '@kbn/apm-synthtrace-client';
import { LogsSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { SupertestWithRoleScopeType } from '../../../services';
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
import { createBackingIndexNameWithoutVersion, setDataStreamSettings } from './utils/es_utils';
import { createBackingIndexNameWithoutVersion, setDataStreamSettings } from './utils';
import { logsSynthMappings } from './custom_mappings/custom_synth_mappings';

const MORE_THAN_1024_CHARS =
Expand Down
Loading

0 comments on commit d8710a4

Please sign in to comment.