From fed808c2af9feb67dcfec19fdfbbce95fb7f93f4 Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Wed, 12 Jun 2019 18:31:11 +0200 Subject: [PATCH] [APM] Use transaction type from flyout instead of url params (#38782) * [APM] Use transaction type from flyout instead of url params * Use GET instead of HEAD to prevent kfetch from erroring out on invalid JSON * Remove unnecessary check for existence of transactionType --- .../MachineLearningFlyout/index.tsx | 24 ++++++++++++------- .../MachineLearningFlyout/view.tsx | 4 ++-- x-pack/plugins/apm/public/services/rest/ml.ts | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/MachineLearningFlyout/index.tsx b/x-pack/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/MachineLearningFlyout/index.tsx index 65b48b1127e0..aaad257ce4f0 100644 --- a/x-pack/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/MachineLearningFlyout/index.tsx +++ b/x-pack/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/MachineLearningFlyout/index.tsx @@ -52,21 +52,23 @@ export class MachineLearningFlyout extends Component { }, 0); } - public onClickCreate = async () => { + public onClickCreate = async ({ + transactionType + }: { + transactionType: string; + }) => { this.setState({ isCreatingJob: true }); try { - const { serviceName, transactionType } = this.props.urlParams; - if (!serviceName || !transactionType) { - throw new Error( - 'Service name and transaction type are required to create this ML job' - ); + const { serviceName } = this.props.urlParams; + if (!serviceName) { + throw new Error('Service name is required to create this ML job'); } const res = await startMLJob({ serviceName, transactionType }); const didSucceed = res.datafeeds[0].success && res.jobs[0].success; if (!didSucceed) { throw new Error('Creating ML job failed'); } - this.addSuccessToast(); + this.addSuccessToast({ transactionType }); } catch (e) { this.addErrorToast(); } @@ -104,9 +106,13 @@ export class MachineLearningFlyout extends Component { }); }; - public addSuccessToast = () => { + public addSuccessToast = ({ + transactionType + }: { + transactionType: string; + }) => { const { urlParams } = this.props; - const { serviceName, transactionType } = urlParams; + const { serviceName } = urlParams; if (!serviceName) { return; diff --git a/x-pack/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/MachineLearningFlyout/view.tsx b/x-pack/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/MachineLearningFlyout/view.tsx index 2541e92660f4..640214d4a708 100644 --- a/x-pack/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/MachineLearningFlyout/view.tsx +++ b/x-pack/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/MachineLearningFlyout/view.tsx @@ -31,7 +31,7 @@ import { TransactionSelect } from './TransactionSelect'; interface Props { hasIndexPattern: boolean; isCreatingJob: boolean; - onClickCreate: () => void; + onClickCreate: ({ transactionType }: { transactionType: string }) => void; onClose: () => void; serviceName: string; serviceTransactionTypes: string[]; @@ -212,7 +212,7 @@ export function MachineLearningFlyoutView({ onClickCreate({ transactionType })} fill disabled={ isCreatingJob || diff --git a/x-pack/plugins/apm/public/services/rest/ml.ts b/x-pack/plugins/apm/public/services/rest/ml.ts index de72255a1f04..6ce6ee36fdda 100644 --- a/x-pack/plugins/apm/public/services/rest/ml.ts +++ b/x-pack/plugins/apm/public/services/rest/ml.ts @@ -80,7 +80,7 @@ export async function getHasMLJob({ }) { try { await callApi({ - method: 'HEAD', + method: 'GET', pathname: `/api/ml/anomaly_detectors/${getMlJobId( serviceName, transactionType