Skip to content

Commit

Permalink
- Use the anomalyDetectorsProvider jobs API rather than the search en…
Browse files Browse the repository at this point in the history
…dpoint directly

- Defines a specific return type for the ml jobs api
- Update the empty anomaly data message
  • Loading branch information
ogupte committed Jun 8, 2020
1 parent acc3db6 commit 08b94cf
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ const ANOMALY_DETECTION_DISABLED_TEXT = i18n.translate(
const ANOMALY_DETECTION_NO_DATA_TEXT = i18n.translate(
'xpack.apm.serviceMap.anomalyDetectionPopoverNoData',
{
defaultMessage:
'No anomaly score found with the current filters. See details in the anomaly explorer:',
defaultMessage: `We couldn't find an anomaly score within the selected time range. See details in the anomaly explorer.`,
}
);

Expand Down
14 changes: 2 additions & 12 deletions x-pack/plugins/apm/server/lib/helpers/setup_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { APMRequestHandlerContext } from '../../routes/typings';
import { getESClient } from './es_client';
import { ProcessorEvent } from '../../../common/processor_event';
import { getDynamicIndexPattern } from '../index_pattern/get_dynamic_index_pattern';
import { Job as AnomalyDetectionJob } from '../../../../ml/server';

function decodeUiFilters(
indexPattern: IIndexPattern | undefined,
Expand Down Expand Up @@ -115,17 +114,8 @@ function getMlSetup(context: APMRequestHandlerContext, request: KibanaRequest) {
const ml = context.plugins.ml;
const mlClient = ml.mlClient.asScoped(request).callAsCurrentUser;
return {
...ml.mlSystemProvider(mlClient, request),
mlSystem: ml.mlSystemProvider(mlClient, request),
anomalyDetectors: ml.anomalyDetectorsProvider(mlClient),
mlClient,
/**
* https://www.elastic.co/guide/en/elasticsearch/reference/7.x/ml-get-job.html#ml-get-job-desc
* @param {string | string[]} [jobId] - job id, group name, or a wildcard, returns all jobs if nothing passed in
*/
mlJobs: async (
jobId?: string | string[]
): Promise<AnomalyDetectionJob[]> => {
const mlJobsResponse = await mlClient('ml.jobs', { jobId });
return mlJobsResponse.jobs;
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function getServiceAnomalies(
return [];
}

const apmMlJobs = await ml.mlJobs('apm');
const { jobs: apmMlJobs } = await ml.anomalyDetectors.jobs('apm');
const apmMlJobCategories = apmMlJobs
.map((job) => getApmMlJobCategory(job, serviceNames))
.filter(
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function getServiceAnomalies(
},
};

const response = await ml.mlAnomalySearch(params);
const response = await ml.mlSystem.mlAnomalySearch(params);
const anomalyScores: Array<{
jobId: string;
anomalyScore: number;
Expand All @@ -109,7 +109,7 @@ export async function getServiceAnomalies(
({ jobId, timestamp }) => {
return (async () => {
try {
const modelPlotResponse = await ml.mlAnomalySearch({
const modelPlotResponse = await ml.mlSystem.mlAnomalySearch({
body: {
size: 1,
query: {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*/

export * from '../common/types/anomalies';
export { Job } from '../common/types/anomaly_detection_jobs';
export * from '../common/types/anomaly_detection_jobs';
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

import { APICaller } from 'kibana/server';
import { LicenseCheck } from '../license_checks';
import { Job } from '../../../common/types/anomaly_detection_jobs';

export interface AnomalyDetectorsProvider {
anomalyDetectorsProvider(
callAsCurrentUser: APICaller
): {
jobs(jobId?: string): Promise<any>;
jobs(jobId?: string): Promise<{ count: number; jobs: Job[] }>;
};
}

Expand Down

0 comments on commit 08b94cf

Please sign in to comment.