mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* Closes #69238 by handling 404 thrown error from the query for APM ML jobs. * Improved coded readability * moved anomaly job fetch to new function getApmAnomalyDetectionJobs for improved readability and only handle a 404 status code response else throw
This commit is contained in:
parent
4bf7341385
commit
37ae060f02
1 changed files with 25 additions and 1 deletions
|
@ -8,12 +8,33 @@ import { leftJoin } from '../../../common/utils/left_join';
|
|||
import { Job as AnomalyDetectionJob } from '../../../../ml/server';
|
||||
import { PromiseReturnType } from '../../../typings/common';
|
||||
import { IEnvOptions } from './get_service_map';
|
||||
import { Setup } from '../helpers/setup_request';
|
||||
import {
|
||||
APM_ML_JOB_GROUP_NAME,
|
||||
encodeForMlApi,
|
||||
} from '../../../common/ml_job_constants';
|
||||
|
||||
async function getApmAnomalyDetectionJobs(
|
||||
setup: Setup
|
||||
): Promise<AnomalyDetectionJob[]> {
|
||||
const { ml } = setup;
|
||||
|
||||
if (!ml) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
const { jobs } = await ml.anomalyDetectors.jobs(APM_ML_JOB_GROUP_NAME);
|
||||
return jobs;
|
||||
} catch (error) {
|
||||
if (error.statusCode === 404) {
|
||||
return [];
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
type ApmMlJobCategory = NonNullable<ReturnType<typeof getApmMlJobCategory>>;
|
||||
|
||||
export const getApmMlJobCategory = (
|
||||
mlJob: AnomalyDetectionJob,
|
||||
serviceNames: string[]
|
||||
|
@ -62,7 +83,10 @@ export async function getServiceAnomalies(
|
|||
return [];
|
||||
}
|
||||
|
||||
const { jobs: apmMlJobs } = await ml.anomalyDetectors.jobs('apm');
|
||||
const apmMlJobs = await getApmAnomalyDetectionJobs(options.setup);
|
||||
if (apmMlJobs.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const apmMlJobCategories = apmMlJobs
|
||||
.map((job) => getApmMlJobCategory(job, serviceNames))
|
||||
.filter(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue