Skip to content

Commit 1377661

Browse files
committed
1 parent 02cba10 commit 1377661

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/MachineLearningFlyout/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export class MachineLearningFlyout extends Component<Props, State> {
5757
};
5858

5959
public addErrorToast = () => {
60-
const core = this.context;
60+
const { core } = this.context;
61+
6162
const { urlParams } = this.props;
6263
const { serviceName } = urlParams;
6364

x-pack/legacy/plugins/apm/public/services/rest/ml.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
} from '../../../../../../plugins/apm/common/elasticsearch_fieldnames';
1313
import {
1414
getMlJobId,
15-
getMlPrefix
15+
getMlPrefix,
16+
encodeForMlApi
1617
} from '../../../../../../plugins/apm/common/ml_job_constants';
1718
import { callApi } from './callApi';
1819
import { ESFilter } from '../../../../../../plugins/apm/typings/elasticsearch';
@@ -53,13 +54,16 @@ export async function startMLJob({
5354
http: HttpSetup;
5455
}) {
5556
const transactionIndices = await getTransactionIndices(http);
56-
const groups = ['apm', serviceName.toLowerCase()];
57+
const groups = [
58+
'apm',
59+
encodeForMlApi(serviceName),
60+
encodeForMlApi(transactionType)
61+
];
5762
const filter: ESFilter[] = [
5863
{ term: { [SERVICE_NAME]: serviceName } },
5964
{ term: { [PROCESSOR_EVENT]: 'transaction' } },
6065
{ term: { [TRANSACTION_TYPE]: transactionType } }
6166
];
62-
groups.push(transactionType.toLowerCase());
6367
return callApi<StartedMLJobApiResponse>(http, {
6468
method: 'POST',
6569
pathname: `/api/ml/modules/setup/apm_transaction`,

x-pack/plugins/apm/common/ml_job_constants.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ describe('ml_job_constants', () => {
2121
expect(getMlJobId('myServiceName', 'myTransactionType')).toBe(
2222
'myservicename-mytransactiontype-high_mean_response_time'
2323
);
24+
expect(getMlJobId('my service name')).toBe(
25+
'my_service_name-high_mean_response_time'
26+
);
27+
expect(getMlJobId('my service name', 'my transaction type')).toBe(
28+
'my_service_name-my_transaction_type-high_mean_response_time'
29+
);
2430
});
2531

2632
it('getMlIndex', () => {

x-pack/plugins/apm/common/ml_job_constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
export function getMlPrefix(serviceName: string, transactionType?: string) {
88
const maybeTransactionType = transactionType ? `${transactionType}-` : '';
9-
return `${serviceName}-${maybeTransactionType}`.toLowerCase();
9+
return encodeForMlApi(`${serviceName}-${maybeTransactionType}`);
1010
}
1111

1212
export function getMlJobId(serviceName: string, transactionType?: string) {
@@ -16,3 +16,7 @@ export function getMlJobId(serviceName: string, transactionType?: string) {
1616
export function getMlIndex(serviceName: string, transactionType?: string) {
1717
return `.ml-anomalies-${getMlJobId(serviceName, transactionType)}`;
1818
}
19+
20+
export function encodeForMlApi(value: string) {
21+
return value.replace(/\s+/g, '_').toLowerCase();
22+
}

0 commit comments

Comments
 (0)