Skip to content

Commit

Permalink
[APM] Use transaction indices to create ML job (#43750) (#43811)
Browse files Browse the repository at this point in the history
* [APM] Use transaction indices to create ML job

Closes #43509.

* Remove unused translations
  • Loading branch information
dgieselaar authored Aug 23, 2019
1 parent 4d9be9e commit cbbf2fc
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 73 deletions.
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/apm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export const apm: LegacyPluginInitializer = kibana => {
const config = server.config();
return {
apmUiEnabled: config.get('xpack.apm.ui.enabled'),
apmIndexPatternTitle: config.get('apm_oss.indexPattern') // TODO: rename to apm_oss.indexPatternTitle in 7.0 (breaking change)
// TODO: rename to apm_oss.indexPatternTitle in 7.0 (breaking change)
apmIndexPatternTitle: config.get('apm_oss.indexPattern'),
apmTransactionIndices: config.get('apm_oss.transactionIndices')
};
},
hacks: ['plugins/apm/hacks/toggle_app_link_in_nav'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { i18n } from '@kbn/i18n';
import React, { Component } from 'react';
import { toastNotifications } from 'ui/notify';
import { startMLJob } from '../../../../../services/rest/ml';
import { getAPMIndexPattern } from '../../../../../services/rest/savedObjects';
import { IUrlParams } from '../../../../../context/UrlParamsContext/types';
import { MLJobLink } from '../../../../shared/Links/MachineLearningLinks/MLJobLink';
import { MachineLearningFlyoutView } from './view';
Expand All @@ -21,35 +20,12 @@ interface Props {

interface State {
isCreatingJob: boolean;
hasIndexPattern: boolean;
}

export class MachineLearningFlyout extends Component<Props, State> {
public state: State = {
isCreatingJob: false,
hasIndexPattern: false
isCreatingJob: false
};
public mounted = false;

public componentWillUnmount() {
this.mounted = false;
}

public async componentDidMount() {
this.mounted = true;
const indexPattern = await getAPMIndexPattern();

// setTimeout:0 hack forces the state update to wait for next tick
// in case the component is mid-unmount :/
setTimeout(() => {
if (!this.mounted) {
return;
}
this.setState({
hasIndexPattern: !!indexPattern
});
}, 0);
}

public onClickCreate = async ({
transactionType
Expand Down Expand Up @@ -156,15 +132,14 @@ export class MachineLearningFlyout extends Component<Props, State> {
public render() {
const { isOpen, onClose, urlParams } = this.props;
const { serviceName } = urlParams;
const { isCreatingJob, hasIndexPattern } = this.state;
const { isCreatingJob } = this.state;

if (!isOpen || !serviceName) {
return null;
}

return (
<MachineLearningFlyoutView
hasIndexPattern={hasIndexPattern}
isCreatingJob={isCreatingJob}
onClickCreate={this.onClickCreate}
onClose={onClose}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,20 @@ import React, { useState, useEffect } from 'react';
import { isEmpty } from 'lodash';
import { FETCH_STATUS, useFetcher } from '../../../../../hooks/useFetcher';
import { getHasMLJob } from '../../../../../services/rest/ml';
import { KibanaLink } from '../../../../shared/Links/KibanaLink';
import { MLJobLink } from '../../../../shared/Links/MachineLearningLinks/MLJobLink';
import { MLLink } from '../../../../shared/Links/MachineLearningLinks/MLLink';
import { TransactionSelect } from './TransactionSelect';
import { IUrlParams } from '../../../../../context/UrlParamsContext/types';
import { useServiceTransactionTypes } from '../../../../../hooks/useServiceTransactionTypes';

interface Props {
hasIndexPattern: boolean;
isCreatingJob: boolean;
onClickCreate: ({ transactionType }: { transactionType: string }) => void;
onClose: () => void;
urlParams: IUrlParams;
}

export function MachineLearningFlyoutView({
hasIndexPattern,
isCreatingJob,
onClickCreate,
onClose,
Expand Down Expand Up @@ -128,37 +125,6 @@ export function MachineLearningFlyoutView({
<EuiSpacer size="m" />
</div>
)}

{!hasIndexPattern && (
<div>
<EuiCallOut
title={
<span>
<FormattedMessage
id="xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.noPatternTitle"
defaultMessage="No APM index pattern available. To create a job, please import the APM index pattern via the {setupInstructionLink}"
values={{
setupInstructionLink: (
<KibanaLink path={`/home/tutorial/apm`}>
{i18n.translate(
'xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.noPatternTitle.setupInstructionLinkText',
{
defaultMessage: 'Setup Instructions'
}
)}
</KibanaLink>
)
}}
/>
</span>
}
color="warning"
iconType="alert"
/>
<EuiSpacer size="m" />
</div>
)}

<EuiText>
<p>
<FormattedMessage
Expand Down Expand Up @@ -233,12 +199,7 @@ export function MachineLearningFlyoutView({
onClickCreate({ transactionType: selectedTransactionType })
}
fill
disabled={
isCreatingJob ||
hasMLJob ||
!hasIndexPattern ||
isLoadingMLJob
}
disabled={isCreatingJob || hasMLJob || isLoadingMLJob}
>
{i18n.translate(
'xpack.apm.serviceDetails.enableAnomalyDetectionPanel.createNewJobButtonLabel',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/apm/public/services/rest/ml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function startMLJob({
transactionType: string;
}) {
const indexPatternName = core.injectedMetadata.getInjectedVar(
'apmIndexPatternTitle'
'apmTransactionIndices'
);
const groups = ['apm', serviceName.toLowerCase()];
const filter: ESFilter[] = [
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -3765,8 +3765,6 @@
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.jobExistsDescription": "現在 {serviceName} ({transactionType}) の実行中のジョブがあります。",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.jobExistsDescription.viewJobLinkText": "既存のジョブを表示",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.jobExistsTitle": "ジョブが既に存在します",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.noPatternTitle": "利用可能な APM インデックスパターンがありません。ジョブを作成するには、{setupInstructionLink} で APM インデックスパターンをインポートしてください",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.noPatternTitle.setupInstructionLinkText": "セットアップの手順",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.createMLJobDescription": "ここでは、{serviceName} 数列内の APM トランザクションの期間の異常スコアを計算する機械学習ジョブを作成できます。有効にすると、{transactionDurationGraphText} が予測バウンドを表示し、異常スコアが >=75 の場合グラフに注釈が追加されます。",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.createMLJobDescription.transactionDurationGraphText": "トランザクション時間のグラフ",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.createNewJobButtonLabel": "新規ジョブを作成",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -3766,8 +3766,6 @@
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.jobExistsDescription": "当前有 {serviceName}({transactionType})的作业正在运行。",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.jobExistsDescription.viewJobLinkText": "查看现有作业",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.jobExistsTitle": "作业已存在",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.noPatternTitle": "没有可用的 APM 索引模式。要创建作业,请通过{setupInstructionLink}导入 APM 索引模式",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.callout.noPatternTitle.setupInstructionLinkText": "设置说明",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.createMLJobDescription": "在这里可以创建 Machine Learning 作业以基于 {serviceName} 服务内 APM 事务的持续时间计算异常分数。启用后,一旦异常分数 >=75,{transactionDurationGraphText}将显示预期边界并标注图表。",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.createMLJobDescription.transactionDurationGraphText": "事务持续时间图表",
"xpack.apm.serviceDetails.enableAnomalyDetectionPanel.createNewJobButtonLabel": "创建新作业",
Expand Down

0 comments on commit cbbf2fc

Please sign in to comment.