Skip to content

Commit

Permalink
[8.16] [Dataset Quality] Fix failing test on mki qa (elastic#196122) (e…
Browse files Browse the repository at this point in the history
…lastic#196816)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Dataset Quality] Fix failing test on mki qa
(elastic#196122)](elastic#196122)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Achyut
Jhunjhunwala","email":"achyut.jhunjhunwala@elastic.co"},"sourceCommit":{"committedDate":"2024-10-14T19:19:10Z","message":"[Dataset
Quality] Fix failing test on mki qa (elastic#196122)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/195466\r\n\r\nAs LogDB mode is
enabled on MKI QA environment, it causes mappings for\r\ncertain fields
like `host.name` to be set differently. Hence causing\r\ntests to
fail.\r\n\r\nAs part of the fix, before ingesting data, i am statically
setting the\r\nmappings so that it does not cause any collision with
something outside\r\nthe scope of the
tests","sha":"7237902fad6424d9556cff78e3f3ac7e62fa4bac","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport
missing","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-logs","Team:obs-ux-infra_services","Feature:Dataset
Health","apm:review"],"number":196122,"url":"https://github.com/elastic/kibana/pull/196122","mergeCommit":{"message":"[Dataset
Quality] Fix failing test on mki qa (elastic#196122)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/195466\r\n\r\nAs LogDB mode is
enabled on MKI QA environment, it causes mappings for\r\ncertain fields
like `host.name` to be set differently. Hence causing\r\ntests to
fail.\r\n\r\nAs part of the fix, before ingesting data, i am statically
setting the\r\nmappings so that it does not cause any collision with
something outside\r\nthe scope of the
tests","sha":"7237902fad6424d9556cff78e3f3ac7e62fa4bac"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196122","number":196122,"mergeCommit":{"message":"[Dataset
Quality] Fix failing test on mki qa (elastic#196122)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/195466\r\n\r\nAs LogDB mode is
enabled on MKI QA environment, it causes mappings for\r\ncertain fields
like `host.name` to be set differently. Hence causing\r\ntests to
fail.\r\n\r\nAs part of the fix, before ingesting data, i am statically
setting the\r\nmappings so that it does not cause any collision with
something outside\r\nthe scope of the
tests","sha":"7237902fad6424d9556cff78e3f3ac7e62fa4bac"}}]}] BACKPORT-->
  • Loading branch information
achyutjhunjhunwala authored Oct 18, 2024
1 parent 8094dd6 commit d7bbd0a
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 @@ -48,6 +48,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 d7bbd0a

Please sign in to comment.