Adds processor filter to ML query (#30284) (#30370)

This commit is contained in:
Jason Rhodes 2019-02-07 08:20:51 -05:00 committed by GitHub
parent 27b5cc7136
commit 1087d8b473
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View file

@ -77,14 +77,17 @@ export class MachineLearningFlyout extends Component<FlyoutProps, FlyoutState> {
this.setState({ isLoading: true });
try {
const { serviceName, transactionType } = this.props.urlParams;
if (serviceName) {
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();
if (!serviceName || !transactionType) {
throw new Error(
'Service name and transaction type are 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();
} catch (e) {
this.addErrorToast();
}

View file

@ -7,6 +7,7 @@
import { ESFilter } from 'elasticsearch';
import chrome from 'ui/chrome';
import {
PROCESSOR_EVENT,
SERVICE_NAME,
TRANSACTION_TYPE
} from '../../../common/elasticsearch_fieldnames';
@ -40,15 +41,16 @@ export async function startMLJob({
transactionType
}: {
serviceName: string;
transactionType?: string;
transactionType: string;
}) {
const indexPatternName = chrome.getInjected('apmIndexPatternTitle');
const groups = ['apm', serviceName.toLowerCase()];
const filter: ESFilter[] = [{ term: { [SERVICE_NAME]: serviceName } }];
if (transactionType) {
groups.push(transactionType.toLowerCase());
filter.push({ term: { [TRANSACTION_TYPE]: transactionType } });
}
const filter: ESFilter[] = [
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [PROCESSOR_EVENT]: 'transaction' } },
{ term: { [TRANSACTION_TYPE]: transactionType } }
];
groups.push(transactionType.toLowerCase());
return callApi<StartedMLJobApiResponse>({
method: 'POST',
pathname: `/api/ml/modules/setup/apm_transaction`,