Skip to content

Commit

Permalink
[Dataset Quality] Fix failing test on mki qa (#196122)
Browse files Browse the repository at this point in the history
## Summary

Closes #195466

As LogDB mode is enabled on MKI QA environment, it causes mappings for
certain fields like `host.name` to be set differently. Hence causing
tests to fail.

As part of the fix, before ingesting data, i am statically setting the
mappings so that it does not cause any collision with something outside
the scope of the tests

(cherry picked from commit 7237902)

# Conflicts:
#	x-pack/test/api_integration/deployment_agnostic/apis/observability/dataset_quality/degraded_field_analyze.ts
#	x-pack/test_serverless/functional/test_suites/observability/dataset_quality/degraded_field_flyout.ts
  • Loading branch information
achyutjhunjhunwala committed Oct 21, 2024
1 parent db599d1 commit b9622ef
Show file tree
Hide file tree
Showing 7 changed files with 455 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ export class LogsSynthtraceEsClient extends SynthtraceEsClient<LogDocument> {
}
}

async createComponentTemplate(name: string, mappings: MappingTypeMapping) {
const isTemplateExisting = await this.client.cluster.existsComponentTemplate({ name });

if (isTemplateExisting) return this.logger.info(`Component template already exists: ${name}`);

try {
await this.client.cluster.putComponentTemplate({
name,
template: {
mappings,
},
});
this.logger.info(`Component template successfully created: ${name}`);
} catch (err) {
this.logger.error(`Component template creation failed: ${name} - ${err.message}`);
}
}

async deleteComponentTemplate(name: string) {
try {
await this.client.cluster.deleteComponentTemplate({ name });
this.logger.info(`Component template successfully deleted: ${name}`);
} catch (err) {
this.logger.error(`Component template deletion failed: ${name} - ${err.message}`);
}
}

async createIndex(index: string, mappings?: MappingTypeMapping) {
try {
const isIndexExisting = await this.client.indices.exists({ index });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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 { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types';

export const logsSynthMappings = (dataset: string): MappingTypeMapping => ({
properties: {
'@timestamp': {
type: 'date',
ignore_malformed: false,
},
data_stream: {
properties: {
dataset: {
type: 'constant_keyword',
value: dataset,
},
namespace: {
type: 'constant_keyword',
value: 'default',
},
type: {
type: 'constant_keyword',
value: 'logs',
},
},
},
event: {
properties: {
dataset: {
type: 'keyword',
ignore_above: 1024,
},
},
},
host: {
properties: {
name: {
type: 'keyword',
fields: {
text: {
type: 'match_only_text',
},
},
},
},
},
input: {
properties: {
type: {
type: 'keyword',
ignore_above: 1024,
},
},
},
log: {
properties: {
file: {
properties: {
path: {
type: 'keyword',
fields: {
text: {
type: 'match_only_text',
},
},
},
},
},
},
},
message: {
type: 'match_only_text',
},
network: {
properties: {
bytes: {
type: 'long',
},
},
},
service: {
properties: {
name: {
type: 'keyword',
fields: {
text: {
type: 'match_only_text',
},
},
},
},
},
test_field: {
type: 'keyword',
ignore_above: 1024,
},
tls: {
properties: {
established: {
type: 'boolean',
},
},
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { log, timerange } from '@kbn/apm-synthtrace-client';
import { SupertestWithRoleScopeType } from '../../../services';
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
import { createBackingIndexNameWithoutVersion, setDataStreamSettings } from './es_utils';
import { logsSynthMappings } from './custom_mappings/custom_synth_mappings';

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?';
Expand All @@ -27,6 +28,8 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
const hostName = 'synth-host';
const dataStreamName = `${type}-${dataset}-${namespace}`;

const customComponentTemplateName = 'logs-synth@mappings';

async function callApiAs({
roleScopedSupertestWithCookieCredentials,
apiParams: { dataStream, degradedField, lastBackingIndex },
Expand Down Expand Up @@ -60,6 +63,29 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {

describe('gets limit analysis for a given datastream and degraded field', () => {
before(async () => {
await synthtrace.createComponentTemplate(
customComponentTemplateName,
logsSynthMappings(dataset)
);
await esClient.indices.putIndexTemplate({
name: dataStreamName,
_meta: {
managed: false,
description: 'custom synth template created by synthtrace tool.',
},
priority: 500,
index_patterns: [dataStreamName],
composed_of: [
customComponentTemplateName,
'logs@mappings',
'logs@settings',
'ecs@mappings',
],
allow_auto_create: true,
data_stream: {
hidden: false,
},
});
await synthtrace.index([
timerange(start, end)
.interval('1m')
Expand Down Expand Up @@ -151,6 +177,8 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {

after(async () => {
await synthtrace.clean();
await esClient.indices.deleteIndexTemplate({ name: dataStreamName });
await synthtrace.deleteComponentTemplate(customComponentTemplateName);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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 { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types';

export const logsSynthMappings = (dataset: string): MappingTypeMapping => ({
properties: {
'@timestamp': {
type: 'date',
ignore_malformed: false,
},
data_stream: {
properties: {
dataset: {
type: 'constant_keyword',
value: 'degraded.dataset.rca',
},
namespace: {
type: 'constant_keyword',
value: 'default',
},
type: {
type: 'constant_keyword',
value: 'logs',
},
},
},
event: {
properties: {
dataset: {
type: 'keyword',
ignore_above: 1024,
},
},
},
host: {
properties: {
name: {
type: 'keyword',
fields: {
text: {
type: 'match_only_text',
},
},
},
},
},
input: {
properties: {
type: {
type: 'keyword',
ignore_above: 1024,
},
},
},
log: {
properties: {
level: {
type: 'keyword',
ignore_above: 1024,
},
},
},
message: {
type: 'match_only_text',
},
network: {
properties: {
bytes: {
type: 'long',
},
},
},
service: {
properties: {
name: {
type: 'keyword',
fields: {
text: {
type: 'match_only_text',
},
},
},
},
},
test_field: {
type: 'keyword',
ignore_above: 1024,
},
tls: {
properties: {
established: {
type: 'boolean',
},
},
},
trace: {
properties: {
id: {
type: 'keyword',
ignore_above: 1024,
},
},
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { generateShortId, log, timerange } from '@kbn/apm-synthtrace-client';
import { DatasetQualityFtrProviderContext } from './config';
import {
createDegradedFieldsRecord,
datasetNames,
defaultNamespace,
getInitialTestLogs,
ANOTHER_1024_CHARS,
MORE_THAN_1024_CHARS,
} from './data';
import { logsSynthMappings } from './custom_mappings/custom_synth_mappings';

export default function ({ getService, getPageObjects }: DatasetQualityFtrProviderContext) {
const PageObjects = getPageObjects([
Expand All @@ -27,15 +27,17 @@ export default function ({ getService, getPageObjects }: DatasetQualityFtrProvid
]);
const testSubjects = getService('testSubjects');
const synthtrace = getService('logSynthtraceEsClient');
const esClient = getService('es');
const retry = getService('retry');
const to = new Date().toISOString();
const degradedDatasetName = datasetNames[2];
const degradedDatasetName = 'synth.degraded';
const degradedDataStreamName = `logs-${degradedDatasetName}-${defaultNamespace}`;

const degradedDatasetWithLimitsName = 'degraded.dataset.rca';
const degradedDatasetWithLimitsName = 'synth.degraded.rca';
const degradedDatasetWithLimitDataStreamName = `logs-${degradedDatasetWithLimitsName}-${defaultNamespace}`;
const serviceName = 'test_service';
const count = 5;
const customComponentTemplateName = 'logs-synth@mappings';

describe('Degraded fields flyout', () => {
before(async () => {
Expand Down Expand Up @@ -114,6 +116,32 @@ export default function ({ getService, getPageObjects }: DatasetQualityFtrProvid

describe('testing root cause for ignored fields', () => {
before(async () => {
// Create custom component template
await synthtrace.createComponentTemplate(
customComponentTemplateName,
logsSynthMappings(degradedDatasetWithLimitsName)
);

// Create custom index template
await esClient.indices.putIndexTemplate({
name: degradedDatasetWithLimitDataStreamName,
_meta: {
managed: false,
description: 'custom synth template created by synthtrace tool.',
},
priority: 500,
index_patterns: [degradedDatasetWithLimitDataStreamName],
composed_of: [
customComponentTemplateName,
'logs@mappings',
'logs@settings',
'ecs@mappings',
],
allow_auto_create: true,
data_stream: {
hidden: false,
},
});
// Ingest Degraded Logs with 25 fields
await synthtrace.index([
timerange(moment(to).subtract(count, 'minute'), moment(to))
Expand Down Expand Up @@ -413,6 +441,10 @@ export default function ({ getService, getPageObjects }: DatasetQualityFtrProvid

after(async () => {
await synthtrace.clean();
await esClient.indices.deleteIndexTemplate({
name: degradedDatasetWithLimitDataStreamName,
});
await synthtrace.deleteComponentTemplate(customComponentTemplateName);
});
});
});
Expand Down
Loading

0 comments on commit b9622ef

Please sign in to comment.