Skip to content

Commit f61b21e

Browse files
Merge branch 'master' into kertal-pr-2020-06-08-improve-discover-histogram-test
2 parents 526f10c + 58cdbf0 commit f61b21e

File tree

414 files changed

+2618
-1239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

414 files changed

+2618
-1239
lines changed

src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/header/__snapshots__/header.test.tsx.snap

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/header/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const Header = ({
7171
<p>
7272
<FormattedMessage
7373
id="indexPatternManagement.createIndexPattern.description"
74-
defaultMessage="An index pattern can match a single source, for example, {single}, or {multiple} data souces, {star}."
74+
defaultMessage="An index pattern can match a single source, for example, {single}, or {multiple} data sources, {star}."
7575
values={{
7676
multiple: <strong>multiple</strong>,
7777
single: <EuiCode>filebeat-4-3-22</EuiCode>,

x-pack/plugins/apm/common/utils/range_filter.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export function rangeFilter(
8-
start: number,
9-
end: number,
10-
timestampField = '@timestamp'
11-
) {
7+
export function rangeFilter(start: number, end: number) {
128
return {
13-
[timestampField]: {
9+
'@timestamp': {
1410
gte: start,
1511
lte: end,
1612
format: 'epoch_millis',

x-pack/plugins/apm/public/components/app/Settings/AgentConfigurations/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function AgentConfigurations() {
2525
(callApmApi) =>
2626
callApmApi({ pathname: '/api/apm/settings/agent-configuration' }),
2727
[],
28-
{ preservePreviousData: false }
28+
{ preservePreviousData: false, showToastOnError: false }
2929
);
3030

3131
useTrackPageview({ app: 'apm', path: 'agent_configuration' });

x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,29 @@ import { i18n } from '@kbn/i18n';
1010
import { EuiPanel } from '@elastic/eui';
1111
import { JobsList } from './jobs_list';
1212
import { AddEnvironments } from './add_environments';
13-
import { useFetcher, FETCH_STATUS } from '../../../../hooks/useFetcher';
13+
import { useFetcher } from '../../../../hooks/useFetcher';
1414
import { LicensePrompt } from '../../../shared/LicensePrompt';
1515
import { useLicense } from '../../../../hooks/useLicense';
16+
import { APIReturnType } from '../../../../services/rest/createCallApmApi';
17+
18+
const DEFAULT_VALUE: APIReturnType<'/api/apm/settings/anomaly-detection'> = {
19+
jobs: [],
20+
hasLegacyJobs: false,
21+
};
1622

1723
export const AnomalyDetection = () => {
1824
const license = useLicense();
1925
const hasValidLicense = license?.isActive && license?.hasAtLeast('platinum');
2026

2127
const [viewAddEnvironments, setViewAddEnvironments] = useState(false);
2228

23-
const { refetch, data = [], status } = useFetcher(
29+
const { refetch, data = DEFAULT_VALUE, status } = useFetcher(
2430
(callApmApi) =>
2531
callApmApi({ pathname: `/api/apm/settings/anomaly-detection` }),
2632
[],
27-
{ preservePreviousData: false }
33+
{ preservePreviousData: false, showToastOnError: false }
2834
);
2935

30-
const isLoading =
31-
status === FETCH_STATUS.PENDING || status === FETCH_STATUS.LOADING;
32-
const hasFetchFailure = status === FETCH_STATUS.FAILURE;
33-
3436
if (!hasValidLicense) {
3537
return (
3638
<EuiPanel>
@@ -66,7 +68,7 @@ export const AnomalyDetection = () => {
6668
<EuiSpacer size="l" />
6769
{viewAddEnvironments ? (
6870
<AddEnvironments
69-
currentEnvironments={data.map(({ environment }) => environment)}
71+
currentEnvironments={data.jobs.map(({ environment }) => environment)}
7072
onCreateJobSuccess={() => {
7173
refetch();
7274
setViewAddEnvironments(false);
@@ -77,9 +79,9 @@ export const AnomalyDetection = () => {
7779
/>
7880
) : (
7981
<JobsList
80-
isLoading={isLoading}
81-
hasFetchFailure={hasFetchFailure}
82-
anomalyDetectionJobsByEnv={data}
82+
status={status}
83+
anomalyDetectionJobsByEnv={data.jobs}
84+
hasLegacyJobs={data.hasLegacyJobs}
8385
onAddEnvironments={() => {
8486
setViewAddEnvironments(true);
8587
}}

x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import {
1616
} from '@elastic/eui';
1717
import { i18n } from '@kbn/i18n';
1818
import { FormattedMessage } from '@kbn/i18n/react';
19+
import { FETCH_STATUS } from '../../../../hooks/useFetcher';
1920
import { ITableColumn, ManagedTable } from '../../../shared/ManagedTable';
2021
import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt';
2122
import { AnomalyDetectionJobByEnv } from '../../../../../typings/anomaly_detection';
2223
import { MLJobLink } from '../../../shared/Links/MachineLearningLinks/MLJobLink';
2324
import { MLLink } from '../../../shared/Links/MachineLearningLinks/MLLink';
2425
import { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values';
26+
import { LegacyJobsCallout } from './legacy_jobs_callout';
2527

2628
const columns: Array<ITableColumn<AnomalyDetectionJobByEnv>> = [
2729
{
@@ -60,17 +62,22 @@ const columns: Array<ITableColumn<AnomalyDetectionJobByEnv>> = [
6062
];
6163

6264
interface Props {
63-
isLoading: boolean;
64-
hasFetchFailure: boolean;
65+
status: FETCH_STATUS;
6566
onAddEnvironments: () => void;
6667
anomalyDetectionJobsByEnv: AnomalyDetectionJobByEnv[];
68+
hasLegacyJobs: boolean;
6769
}
6870
export const JobsList = ({
69-
isLoading,
70-
hasFetchFailure,
71+
status,
7172
onAddEnvironments,
7273
anomalyDetectionJobsByEnv,
74+
hasLegacyJobs,
7375
}: Props) => {
76+
const isLoading =
77+
status === FETCH_STATUS.PENDING || status === FETCH_STATUS.LOADING;
78+
79+
const hasFetchFailure = status === FETCH_STATUS.FAILURE;
80+
7481
return (
7582
<EuiPanel>
7683
<EuiFlexGroup>
@@ -131,6 +138,8 @@ export const JobsList = ({
131138
items={isLoading || hasFetchFailure ? [] : anomalyDetectionJobsByEnv}
132139
/>
133140
<EuiSpacer size="l" />
141+
142+
{hasLegacyJobs && <LegacyJobsCallout />}
134143
</EuiPanel>
135144
);
136145
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { EuiCallOut, EuiButton } from '@elastic/eui';
8+
import React from 'react';
9+
import { i18n } from '@kbn/i18n';
10+
import { useApmPluginContext } from '../../../../hooks/useApmPluginContext';
11+
12+
export function LegacyJobsCallout() {
13+
const { core } = useApmPluginContext();
14+
return (
15+
<EuiCallOut
16+
title={i18n.translate(
17+
'xpack.apm.settings.anomaly_detection.legacy_jobs.title',
18+
{ defaultMessage: 'Legacy ML jobs are no longer used in APM app' }
19+
)}
20+
iconType="iInCircle"
21+
>
22+
<p>
23+
{i18n.translate(
24+
'xpack.apm.settings.anomaly_detection.legacy_jobs.body',
25+
{
26+
defaultMessage:
27+
'We have discovered legacy Machine Learning jobs from our previous integration which are no longer being used in the APM app',
28+
}
29+
)}
30+
</p>
31+
<EuiButton
32+
href={core.http.basePath.prepend(
33+
'/app/ml#/jobs?mlManagement=(jobId:high_mean_response_time)'
34+
)}
35+
>
36+
{i18n.translate(
37+
'xpack.apm.settings.anomaly_detection.legacy_jobs.button',
38+
{ defaultMessage: 'Review jobs' }
39+
)}
40+
</EuiButton>
41+
</EuiCallOut>
42+
);
43+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export const ML_MODULE_ID_APM_TRANSACTION = 'apm_transaction';
8+
export const APM_ML_JOB_GROUP = 'apm';

x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import {
1414
PROCESSOR_EVENT,
1515
} from '../../../common/elasticsearch_fieldnames';
1616
import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values';
17-
18-
const ML_MODULE_ID_APM_TRANSACTION = 'apm_transaction';
19-
export const ML_GROUP_NAME_APM = 'apm';
17+
import { APM_ML_JOB_GROUP, ML_MODULE_ID_APM_TRANSACTION } from './constants';
2018

2119
export type CreateAnomalyDetectionJobsAPIResponse = PromiseReturnType<
2220
typeof createAnomalyDetectionJobs
@@ -83,8 +81,8 @@ async function createAnomalyDetectionJob({
8381

8482
return ml.modules.setup({
8583
moduleId: ML_MODULE_ID_APM_TRANSACTION,
86-
prefix: `${ML_GROUP_NAME_APM}-${convertedEnvironmentName}-${randomToken}-`,
87-
groups: [ML_GROUP_NAME_APM, convertedEnvironmentName],
84+
prefix: `${APM_ML_JOB_GROUP}-${convertedEnvironmentName}-${randomToken}-`,
85+
groups: [APM_ML_JOB_GROUP, convertedEnvironmentName],
8886
indexPatternName,
8987
query: {
9088
bool: {

x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_detection_jobs.ts

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,34 @@
55
*/
66

77
import { Logger } from 'kibana/server';
8-
import { PromiseReturnType } from '../../../../observability/typings/common';
98
import { Setup } from '../helpers/setup_request';
10-
import { AnomalyDetectionJobByEnv } from '../../../typings/anomaly_detection';
11-
import { ML_GROUP_NAME_APM } from './create_anomaly_detection_jobs';
9+
import { getMlJobsWithAPMGroup } from './get_ml_jobs_by_group';
1210

13-
export type AnomalyDetectionJobsAPIResponse = PromiseReturnType<
14-
typeof getAnomalyDetectionJobs
15-
>;
16-
export async function getAnomalyDetectionJobs(
17-
setup: Setup,
18-
logger: Logger
19-
): Promise<AnomalyDetectionJobByEnv[]> {
11+
export async function getAnomalyDetectionJobs(setup: Setup, logger: Logger) {
2012
const { ml } = setup;
2113
if (!ml) {
2214
return [];
2315
}
24-
try {
25-
const mlCapabilities = await ml.mlSystem.mlCapabilities();
26-
if (
27-
!(
28-
mlCapabilities.mlFeatureEnabledInSpace &&
29-
mlCapabilities.isPlatinumOrTrialLicense
30-
)
31-
) {
32-
logger.warn(
33-
'Anomaly detection integration is not availble for this user.'
34-
);
35-
return [];
36-
}
37-
} catch (error) {
38-
logger.warn('Unable to get ML capabilities.');
39-
logger.error(error);
40-
return [];
41-
}
42-
try {
43-
const { jobs } = await ml.anomalyDetectors.jobs(ML_GROUP_NAME_APM);
44-
return jobs
45-
.map((job) => {
46-
const environment = job.custom_settings?.job_tags?.environment ?? '';
47-
return {
48-
job_id: job.job_id,
49-
environment,
50-
};
51-
})
52-
.filter((job) => job.environment);
53-
} catch (error) {
54-
if (error.statusCode !== 404) {
55-
logger.warn('Unable to get APM ML jobs.');
56-
logger.error(error);
57-
}
16+
17+
const mlCapabilities = await ml.mlSystem.mlCapabilities();
18+
if (
19+
!(
20+
mlCapabilities.mlFeatureEnabledInSpace &&
21+
mlCapabilities.isPlatinumOrTrialLicense
22+
)
23+
) {
24+
logger.warn('Anomaly detection integration is not availble for this user.');
5825
return [];
5926
}
27+
28+
const response = await getMlJobsWithAPMGroup(ml);
29+
return response.jobs
30+
.map((job) => {
31+
const environment = job.custom_settings?.job_tags?.environment ?? '';
32+
return {
33+
job_id: job.job_id,
34+
environment,
35+
};
36+
})
37+
.filter((job) => job.environment);
6038
}

0 commit comments

Comments
 (0)