File tree Expand file tree Collapse file tree
x-pack/plugins/apm/server/lib/service_map Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,12 +8,33 @@ import { leftJoin } from '../../../common/utils/left_join';
88import { Job as AnomalyDetectionJob } from '../../../../ml/server' ;
99import { PromiseReturnType } from '../../../typings/common' ;
1010import { IEnvOptions } from './get_service_map' ;
11+ import { Setup } from '../helpers/setup_request' ;
1112import {
1213 APM_ML_JOB_GROUP_NAME ,
1314 encodeForMlApi ,
1415} from '../../../common/ml_job_constants' ;
1516
17+ async function getApmAnomalyDetectionJobs (
18+ setup : Setup
19+ ) : Promise < AnomalyDetectionJob [ ] > {
20+ const { ml } = setup ;
21+
22+ if ( ! ml ) {
23+ return [ ] ;
24+ }
25+ try {
26+ const { jobs } = await ml . anomalyDetectors . jobs ( APM_ML_JOB_GROUP_NAME ) ;
27+ return jobs ;
28+ } catch ( error ) {
29+ if ( error . statusCode === 404 ) {
30+ return [ ] ;
31+ }
32+ throw error ;
33+ }
34+ }
35+
1636type ApmMlJobCategory = NonNullable < ReturnType < typeof getApmMlJobCategory > > ;
37+
1738export const getApmMlJobCategory = (
1839 mlJob : AnomalyDetectionJob ,
1940 serviceNames : string [ ]
@@ -62,13 +83,7 @@ export async function getServiceAnomalies(
6283 return [ ] ;
6384 }
6485
65- let apmMlJobs : AnomalyDetectionJob [ ] = [ ] ;
66- try {
67- const { jobs } = await ml . anomalyDetectors . jobs ( APM_ML_JOB_GROUP_NAME ) ;
68- apmMlJobs = jobs ;
69- } catch ( error ) {
70- // did not find any apm jobs
71- }
86+ const apmMlJobs = await getApmAnomalyDetectionJobs ( options . setup ) ;
7287 if ( apmMlJobs . length === 0 ) {
7388 return [ ] ;
7489 }
You can’t perform that action at this time.
0 commit comments