Skip to content

Commit

Permalink
process processors in kibana as yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Jul 31, 2023
1 parent fa01462 commit 159fd79
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@

import { NewPackagePolicy } from '@kbn/fleet-plugin/common';
import { cloneDeep } from 'lodash';
import { processorsFormatter } from './processors_formatter';
import { LegacyConfigKey } from '../../../../common/constants/monitor_management';
import { ConfigKey, DataStream, MonitorFields } from '../../../../common/runtime_types';
import { throttlingFormatter } from './browser_formatters';
import { replaceStringWithParams } from '../formatting_utils';
import { syntheticsPolicyFormatters } from './formatters';
import { PARAMS_KEYS_TO_SKIP } from '../common';

export interface ProcessorFields {
location_name: string;
location_id: string;
'monitor.project.name': string;
'monitor.project.id': string;
'monitor.id': string;
test_run_id: string;
run_once: boolean;
}

export const formatSyntheticsPolicy = (
newPolicy: NewPackagePolicy,
monitorType: DataStream,
config: Partial<
MonitorFields & {
location_name: string;
location_id: string;
'monitor.project.name': string;
'monitor.project.id': string;
'monitor.id': string;
test_run_id: string;
run_once: boolean;
}
>,
config: Partial<MonitorFields & ProcessorFields>,
params: Record<string, string>,
isLegacy?: boolean
) => {
Expand Down Expand Up @@ -67,6 +68,11 @@ export const formatSyntheticsPolicy = (
}
});

const processorItem = dataStream?.vars?.processors;
if (processorItem) {
processorItem.value = processorsFormatter(config);
}

// TODO: remove this once we remove legacy support
const throttling = dataStream?.vars?.[LegacyConfigKey.THROTTLING_CONFIG];
if (throttling) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 { ProcessorFields } from './format_synthetics_policy';
import { MonitorFields } from '../../../../common/runtime_types';

type Fields = Record<string, string | boolean>;

interface FieldProcessor {
add_fields: {
target: string;
fields: Fields;
};
}

export const processorsFormatter = (config: Partial<MonitorFields & ProcessorFields>) => {
const fields: Fields = {
'monitor.fleet_managed': true,
};
if (config.test_run_id) {
fields.test_run_id = config.test_run_id;
}
if (config['monitor.project.name']) {
fields['monitor.project.name'] = config['monitor.project.name'];
}
if (config['monitor.project.id']) {
fields['monitor.project.id'] = config['monitor.project.id'];
}
if (config['monitor.id']) {
fields['monitor.id'] = config['monitor.id'];
}
const processors: FieldProcessor[] = [
{
add_fields: {
fields,
target: '',
},
},
];

return JSON.stringify(processors);
};

0 comments on commit 159fd79

Please sign in to comment.