diff --git a/packages/kbn-apm-synthtrace/src/lib/logs/logs_synthtrace_es_client.ts b/packages/kbn-apm-synthtrace/src/lib/logs/logs_synthtrace_es_client.ts index a9807e66eb49a..3e95383d9dbb9 100644 --- a/packages/kbn-apm-synthtrace/src/lib/logs/logs_synthtrace_es_client.ts +++ b/packages/kbn-apm-synthtrace/src/lib/logs/logs_synthtrace_es_client.ts @@ -52,6 +52,33 @@ export class LogsSynthtraceEsClient extends SynthtraceEsClient { } } + 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 }); diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/dataset_quality/custom_mappings/custom_synth_mappings.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/dataset_quality/custom_mappings/custom_synth_mappings.ts new file mode 100644 index 0000000000000..b94f5e0ca1135 --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/dataset_quality/custom_mappings/custom_synth_mappings.ts @@ -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', + }, + }, + }, + }, +}); diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/dataset_quality/degraded_field_analyze.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/dataset_quality/degraded_field_analyze.ts index 056bde27fc33c..592d4c160dd9f 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/dataset_quality/degraded_field_analyze.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/dataset_quality/degraded_field_analyze.ts @@ -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?'; @@ -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 }, @@ -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') @@ -151,6 +177,8 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { after(async () => { await synthtrace.clean(); + await esClient.indices.deleteIndexTemplate({ name: dataStreamName }); + await synthtrace.deleteComponentTemplate(customComponentTemplateName); }); }); }); diff --git a/x-pack/test/functional/apps/dataset_quality/custom_mappings/custom_synth_mappings.ts b/x-pack/test/functional/apps/dataset_quality/custom_mappings/custom_synth_mappings.ts new file mode 100644 index 0000000000000..4ae4a39cb121d --- /dev/null +++ b/x-pack/test/functional/apps/dataset_quality/custom_mappings/custom_synth_mappings.ts @@ -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, + }, + }, + }, + }, +}); diff --git a/x-pack/test/functional/apps/dataset_quality/degraded_field_flyout.ts b/x-pack/test/functional/apps/dataset_quality/degraded_field_flyout.ts index 517a7f2ad93fc..2506201aa3b85 100644 --- a/x-pack/test/functional/apps/dataset_quality/degraded_field_flyout.ts +++ b/x-pack/test/functional/apps/dataset_quality/degraded_field_flyout.ts @@ -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([ @@ -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 () => { @@ -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)) @@ -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); }); }); }); diff --git a/x-pack/test_serverless/functional/test_suites/observability/dataset_quality/custom_mappings/custom_synth_mappings.ts b/x-pack/test_serverless/functional/test_suites/observability/dataset_quality/custom_mappings/custom_synth_mappings.ts new file mode 100644 index 0000000000000..4ae4a39cb121d --- /dev/null +++ b/x-pack/test_serverless/functional/test_suites/observability/dataset_quality/custom_mappings/custom_synth_mappings.ts @@ -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, + }, + }, + }, + }, +}); diff --git a/x-pack/test_serverless/functional/test_suites/observability/dataset_quality/degraded_field_flyout.ts b/x-pack/test_serverless/functional/test_suites/observability/dataset_quality/degraded_field_flyout.ts index 263dc8652ad75..0ca3163e9d879 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/dataset_quality/degraded_field_flyout.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/dataset_quality/degraded_field_flyout.ts @@ -10,13 +10,13 @@ import moment from 'moment'; import { generateShortId, log, timerange } from '@kbn/apm-synthtrace-client'; import { createDegradedFieldsRecord, - datasetNames, defaultNamespace, getInitialTestLogs, ANOTHER_1024_CHARS, MORE_THAN_1024_CHARS, } from './data'; import { FtrProviderContext } from '../../../ftr_provider_context'; +import { logsSynthMappings } from './custom_mappings/custom_synth_mappings'; export default function ({ getService, getPageObjects }: FtrProviderContext) { const PageObjects = getPageObjects([ @@ -28,15 +28,17 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ]); const testSubjects = getService('testSubjects'); const synthtrace = getService('svlLogsSynthtraceClient'); + 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 () => { @@ -112,6 +114,32 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { 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)) @@ -411,6 +439,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { after(async () => { await synthtrace.clean(); + await esClient.indices.deleteIndexTemplate({ + name: degradedDatasetWithLimitDataStreamName, + }); + await synthtrace.deleteComponentTemplate(customComponentTemplateName); }); }); });