Skip to content

Commit

Permalink
ensure latLong jobs not viewable in single metric viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Jan 28, 2021
1 parent c7b782b commit 4b8124d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
15 changes: 13 additions & 2 deletions x-pack/plugins/ml/common/util/job_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ export function isTimeSeriesViewDetector(job: CombinedJob, detectorIndex: number
);
}

// Returns a flag to indicate whether the specified job is suitable for embedded map viewing.
export function isMappableJob(job: CombinedJob, detectorIndex: number): boolean {
let isMappable = false;
const { detectors } = job.analysis_config;
if (detectorIndex >= 0 && detectorIndex < detectors.length) {
const dtr = detectors[detectorIndex];
const functionName = dtr.function;
isMappable = functionName === ML_JOB_AGGREGATION.LAT_LONG;
}
return isMappable;
}

// Returns a flag to indicate whether the source data can be plotted in a time
// series chart for the specified detector.
export function isSourceDataChartableForDetector(job: CombinedJob, detectorIndex: number): boolean {
Expand All @@ -93,8 +105,7 @@ export function isSourceDataChartableForDetector(job: CombinedJob, detectorIndex
// Note that the 'function' field in a record contains what the user entered e.g. 'high_count',
// whereas the 'function_description' field holds an ML-built display hint for function e.g. 'count'.
isSourceDataChartable =
(mlFunctionToESAggregation(functionName) !== null ||
functionName === ML_JOB_AGGREGATION.LAT_LONG) &&
mlFunctionToESAggregation(functionName) !== null &&
dtr.by_field_name !== MLCATEGORY &&
dtr.partition_field_name !== MLCATEGORY &&
dtr.over_field_name !== MLCATEGORY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
isSourceDataChartableForDetector,
isModelPlotChartableForDetector,
isModelPlotEnabled,
isMappableJob,
} from '../../../../common/util/job_utils';
import { mlResultsService } from '../../services/results_service';
import { mlJobService } from '../../services/job_service';
Expand Down Expand Up @@ -498,7 +499,10 @@ function processRecordsForDisplay(anomalyRecords) {
return;
}

let isChartable = isSourceDataChartableForDetector(job, record.detector_index);
let isChartable =
isSourceDataChartableForDetector(job, record.detector_index) ||
isMappableJob(job, record.detector_index);

if (isChartable === false) {
if (isModelPlotChartableForDetector(job, record.detector_index)) {
// Check if model plot is enabled for this job.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
*/

import { FIELD_ORIGIN, STYLE_TYPE } from '../../../../../maps/common/constants';
import { ANOMALY_THRESHOLD, SEVERITY_COLORS } from '../../../../common';

const FEATURE = 'Feature';
const POINT = 'Point';
const SEVERITY_COLOR_RAMP = [
{
stop: 0,
color: '#8BC8FB',
stop: ANOMALY_THRESHOLD.LOW,
color: SEVERITY_COLORS.WARNING,
},
{
stop: 25,
color: '#FDEC25',
stop: ANOMALY_THRESHOLD.MINOR,
color: SEVERITY_COLORS.MINOR,
},
{
stop: 50,
color: '#FBA740',
stop: ANOMALY_THRESHOLD.MAJOR,
color: SEVERITY_COLORS.MAJOR,
},
{
stop: 75,
color: '#FE5050',
stop: ANOMALY_THRESHOLD.CRITICAL,
color: SEVERITY_COLORS.CRITICAL,
},
];

Expand Down Expand Up @@ -102,7 +103,6 @@ export const getMLAnomaliesTypicalLayer = (anomalies: any) => {
};
};

// GEOJSON_FILE type layer does not support source-type to inject custom data for styling
export const getMLAnomaliesActualLayer = (anomalies: any) => {
return {
id: 'anomalies_actual_layer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '../../../common/constants/search';
import { getEntityFieldList } from '../../../common/util/anomaly_utils';
import { extractErrorMessage } from '../../../common/util/errors';
import { ML_JOB_AGGREGATION } from '../../../common/constants/aggregation_types';
import {
isSourceDataChartableForDetector,
isModelPlotChartableForDetector,
Expand Down Expand Up @@ -513,8 +512,7 @@ export async function loadAnomaliesTableData(
isChartable = isModelPlotEnabled(job, anomaly.detectorIndex, entityFields);
}

anomaly.isTimeSeriesViewRecord =
isChartable && anomaly.source?.function !== ML_JOB_AGGREGATION.LAT_LONG;
anomaly.isTimeSeriesViewRecord = isChartable;

if (mlJobService.customUrlsByJob[jobId] !== undefined) {
anomaly.customUrls = mlJobService.customUrlsByJob[jobId];
Expand Down

0 comments on commit 4b8124d

Please sign in to comment.