[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
This commit is contained in:
Dario Gieselaar 2019-06-12 18:31:11 +02:00 committed by GitHub
parent 42480a3944
commit fed808c2af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 12 deletions

View file

@ -52,21 +52,23 @@ export class MachineLearningFlyout extends Component<Props, State> {
}, 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<Props, State> {
});
};
public addSuccessToast = () => {
public addSuccessToast = ({
transactionType
}: {
transactionType: string;
}) => {
const { urlParams } = this.props;
const { serviceName, transactionType } = urlParams;
const { serviceName } = urlParams;
if (!serviceName) {
return;

View file

@ -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({
<EuiFlexItem grow={false}>
<EuiFormRow>
<EuiButton
onClick={onClickCreate}
onClick={() => onClickCreate({ transactionType })}
fill
disabled={
isCreatingJob ||

View file

@ -80,7 +80,7 @@ export async function getHasMLJob({
}) {
try {
await callApi<MLJobApiResponse>({
method: 'HEAD',
method: 'GET',
pathname: `/api/ml/anomaly_detectors/${getMlJobId(
serviceName,
transactionType