Skip to content

Commit

Permalink
adjusting failed_logs scenario with the new changes for failure store
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrdyn committed Jan 15, 2025
1 parent 2d188e2 commit 394320d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,21 @@ export class LogsSynthtraceEsClient extends SynthtraceEsClient<LogDocument> {
}
}

async createComponentTemplate(
name: string,
mappings?: MappingTypeMapping,
settings?: IndicesIndexSettings
) {
async createComponentTemplate({
name,
mappings,
settings,
dataStreamOptions,
}: {
name: string;
mappings?: MappingTypeMapping;
settings?: IndicesIndexSettings;
dataStreamOptions?: {
failure_store: {
enabled: boolean;
};
};
}) {
const isTemplateExisting = await this.client.cluster.existsComponentTemplate({ name });

if (isTemplateExisting) return this.logger.info(`Component template already exists: ${name}`);
Expand All @@ -71,6 +81,7 @@ export class LogsSynthtraceEsClient extends SynthtraceEsClient<LogDocument> {
template: {
...((mappings && { mappings }) || {}),
...((settings && { settings }) || {}),
...((dataStreamOptions && { data_stream_options: dataStreamOptions }) || {}),
},
});
this.logger.info(`Component template successfully created: ${name}`);
Expand Down
26 changes: 10 additions & 16 deletions packages/kbn-apm-synthtrace/src/scenarios/failed_logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import { LogDocument, log, generateShortId, generateLongId } from '@kbn/apm-synthtrace-client';
import { merge } from 'lodash';
import { Scenario } from '../cli/scenario';
import { IndexTemplateName } from '../lib/logs/custom_logsdb_index_templates';
import { withClient } from '../lib/utils/with_client';
Expand All @@ -20,7 +19,7 @@ import {
MORE_THAN_1024_CHARS,
} from './helpers/logs_mock_data';
import { parseLogsScenarioOpts } from './helpers/logs_scenario_opts_parser';
import { LogsIndex } from '../lib/logs/logs_synthtrace_es_client';
import { LogsCustom } from '../lib/logs/logs_synthtrace_es_client';

const processors = [
{
Expand Down Expand Up @@ -66,19 +65,14 @@ const scenario: Scenario<LogDocument> = async (runOptions) => {
await logsEsClient.createCustomPipeline(processors);
if (isLogsDb) await logsEsClient.createIndexTemplate(IndexTemplateName.LogsDb);

await logsEsClient.updateIndexTemplate(
isLogsDb ? IndexTemplateName.LogsDb : LogsIndex,
(template) => {
const next = {
name: LogsIndex,
data_stream: {
failure_store: true,
},
};

return merge({}, template, next);
}
);
await logsEsClient.createComponentTemplate({
name: LogsCustom,
dataStreamOptions: {
failure_store: {
enabled: true,
},
},
});
},
generate: ({ range, clients: { logsEsClient } }) => {
const { logger } = runOptions;
Expand Down Expand Up @@ -155,7 +149,7 @@ const scenario: Scenario<LogDocument> = async (runOptions) => {
commonLongEntryFields,
} = constructLogsCommonData();
const isMalformed = i % 10 === 0;
const isFailed = i % 80 === 0;
const isFailed = Math.floor(Math.random() * 100) % 80 === 0;
return log
.create({ isLogsDb })
.dataset('synth.3')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
describe('gets limit analysis for a given datastream and degraded field', () => {
before(async () => {
synthtraceLogsEsClient = await synthtrace.createLogsSynthtraceEsClient();
await synthtraceLogsEsClient.createComponentTemplate(
customComponentTemplateName,
logsSynthMappings(dataset)
);
await synthtraceLogsEsClient.createComponentTemplate({
name: customComponentTemplateName,
mappings: logsSynthMappings(dataset),
});
await esClient.indices.putIndexTemplate({
name: dataStreamName,
_meta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ export default function ({ getService, getPageObjects }: DatasetQualityFtrProvid
describe('detecting root cause for ignored fields', () => {
before(async () => {
// Create custom component template
await synthtrace.createComponentTemplate(
customComponentTemplateName,
logsSynthMappings(degradedDatasetWithLimitsName)
);
await synthtrace.createComponentTemplate({
name: customComponentTemplateName,
mappings: logsSynthMappings(degradedDatasetWithLimitsName),
});

// Create custom index template
await esClient.indices.putIndexTemplate({
Expand All @@ -132,10 +132,10 @@ export default function ({ getService, getPageObjects }: DatasetQualityFtrProvid
await PageObjects.observabilityLogsExplorer.installPackage(nginxPkg);

// Create custom component template to avoid issues with LogsDB
await synthtrace.createComponentTemplate(
customComponentTemplateNameNginx,
logsNginxMappings(nginxAccessDatasetName)
);
await synthtrace.createComponentTemplate({
name: customComponentTemplateNameNginx,
mappings: logsNginxMappings(nginxAccessDatasetName),
});

await synthtrace.index([
// Ingest Degraded Logs with 25 fields in degraded DataSet
Expand Down

0 comments on commit 394320d

Please sign in to comment.