Skip to content

Commit

Permalink
Converts the environment name to a compatible ML id string and persist
Browse files Browse the repository at this point in the history
in groups array. Also adds random token to the job ID to prevent
collisions for job ids where diffferent environment names convert to the
same string
  • Loading branch information
ogupte committed Jul 2, 2020
1 parent 79cc31f commit c29688c
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { Logger } from 'kibana/server';
// import uuid from 'uuid/v4';
import uuid from 'uuid/v4';
// import { Job as AnomalyDetectionJob } from '../../../../ml/server';
import { PromiseReturnType } from '../../../../observability/typings/common';
import { Setup } from '../helpers/setup_request';
Expand Down Expand Up @@ -51,11 +51,11 @@ async function configureAnomalyDetectionJob({
ml: Required<Setup>['ml'];
environment: string;
}) {
const convertedEnvironment = environment; // TODO convert to ML id compatible format
const randomToken = '1234'; // TODO use generated UUID
const convertedEnvironmentName = convertToMLIdentifier(environment);
const randomToken = uuid().substr(-4);
const moduleId = 'apm_transaction';
const prefix = `apm-${convertedEnvironment}-${randomToken}-`;
const groups = ['apm', convertedEnvironment];
const prefix = `apm-${convertedEnvironmentName}-${randomToken}-`;
const groups = ['apm', convertedEnvironmentName];
const indexPatternName = 'apm-*-transaction-*';
const query = {
bool: {
Expand Down Expand Up @@ -95,3 +95,7 @@ async function configureAnomalyDetectionJob({
datafeedOverrides
);
}

export function convertToMLIdentifier(value: string) {
return value.replace(/\s+/g, '_').toLowerCase();
}

0 comments on commit c29688c

Please sign in to comment.