[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:
parent
42480a3944
commit
fed808c2af
|
@ -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;
|
||||
|
|
|
@ -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 ||
|
||||
|
|
|
@ -80,7 +80,7 @@ export async function getHasMLJob({
|
|||
}) {
|
||||
try {
|
||||
await callApi<MLJobApiResponse>({
|
||||
method: 'HEAD',
|
||||
method: 'GET',
|
||||
pathname: `/api/ml/anomaly_detectors/${getMlJobId(
|
||||
serviceName,
|
||||
transactionType
|
||||
|
|
Loading…
Reference in a new issue