Skip to content

Commit

Permalink
[ML] API integration tests for job validation (#66265)
Browse files Browse the repository at this point in the history
* [ML] TS refactoring

* [ML] fix page overflow

* [ML] tests

* [ML] fix typing issues and unit tests

* [ML] remove string conversion

* [ML] indexOf checks

* [ML] fix tooltip overflow

* [ML] fix i18n

* [ML] fix unit tests

* [ML] use MlJobAggregation

* [ML] use enums

* Revert "[ML] fix tooltip overflow"

This reverts commit 103c36b

* Revert "[ML] fix page overflow"

This reverts commit 3c86922
  • Loading branch information
darnautov authored May 13, 2020
1 parent 69d4199 commit d0b9840
Show file tree
Hide file tree
Showing 23 changed files with 739 additions and 430 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x-pack/plugins/ml/common/types/data_recognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface JobStat {
id: string;
earliestTimestampMs: number;
latestTimestampMs: number;
latestResultsTimestampMs: number;
latestResultsTimestampMs: number | undefined;
}

export interface JobExistResult {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/common/util/anomaly_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export enum ENTITY_FIELD_TYPE {
export interface EntityField {
fieldName: string;
fieldValue: string | number | undefined;
fieldType: ENTITY_FIELD_TYPE;
fieldType?: ENTITY_FIELD_TYPE;
}

// List of function descriptions for which actual values from record level results should be displayed.
Expand Down
58 changes: 0 additions & 58 deletions x-pack/plugins/ml/common/util/job_utils.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
isJobVersionGte,
mlFunctionToESAggregation,
isJobIdValid,
ML_MEDIAN_PERCENTS,
prefixDatafeedId,
getSafeAggregationName,
getLatestDataOrBucketTimestamp,
} from './job_utils';
import { CombinedJob, Job } from '../types/anomaly_detection_jobs';

describe('ML - job utils', () => {
describe('calculateDatafeedFrequencyDefaultSeconds', () => {
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('ML - job utils', () => {

describe('isTimeSeriesViewJob', () => {
test('returns true when job has a single detector with a metric function', () => {
const job = {
const job = ({
analysis_config: {
detectors: [
{
Expand All @@ -61,13 +61,13 @@ describe('ML - job utils', () => {
},
],
},
};
} as unknown) as CombinedJob;

expect(isTimeSeriesViewJob(job)).toBe(true);
});

test('returns true when job has at least one detector with a metric function', () => {
const job = {
const job = ({
analysis_config: {
detectors: [
{
Expand All @@ -83,13 +83,13 @@ describe('ML - job utils', () => {
},
],
},
};
} as unknown) as CombinedJob;

expect(isTimeSeriesViewJob(job)).toBe(true);
});

test('returns false when job does not have at least one detector with a metric function', () => {
const job = {
const job = ({
analysis_config: {
detectors: [
{
Expand All @@ -105,13 +105,13 @@ describe('ML - job utils', () => {
},
],
},
};
} as unknown) as CombinedJob;

expect(isTimeSeriesViewJob(job)).toBe(false);
});

test('returns false when job has a single count by category detector', () => {
const job = {
const job = ({
analysis_config: {
detectors: [
{
Expand All @@ -121,14 +121,14 @@ describe('ML - job utils', () => {
},
],
},
};
} as unknown) as CombinedJob;

expect(isTimeSeriesViewJob(job)).toBe(false);
});
});

describe('isTimeSeriesViewDetector', () => {
const job = {
const job = ({
analysis_config: {
detectors: [
{
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('ML - job utils', () => {
},
},
},
};
} as unknown) as CombinedJob;

test('returns true for a detector with a metric function', () => {
expect(isTimeSeriesViewDetector(job, 0)).toBe(true);
Expand All @@ -192,7 +192,7 @@ describe('ML - job utils', () => {
});

describe('isSourceDataChartableForDetector', () => {
const job = {
const job = ({
analysis_config: {
detectors: [
{ function: 'count' }, // 0
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('ML - job utils', () => {
},
},
},
};
} as unknown) as CombinedJob;

test('returns true for expected detectors', () => {
expect(isSourceDataChartableForDetector(job, 0)).toBe(true);
Expand Down Expand Up @@ -299,13 +299,13 @@ describe('ML - job utils', () => {
});

describe('isModelPlotChartableForDetector', () => {
const job1 = {
const job1 = ({
analysis_config: {
detectors: [{ function: 'count' }],
},
};
} as unknown) as Job;

const job2 = {
const job2 = ({
analysis_config: {
detectors: [
{ function: 'count' },
Expand All @@ -319,7 +319,7 @@ describe('ML - job utils', () => {
model_plot_config: {
enabled: true,
},
};
} as unknown) as Job;

test('returns false when model plot is not enabled', () => {
expect(isModelPlotChartableForDetector(job1, 0)).toBe(false);
Expand All @@ -339,7 +339,7 @@ describe('ML - job utils', () => {
});

describe('getPartitioningFieldNames', () => {
const job = {
const job = ({
analysis_config: {
detectors: [
{
Expand Down Expand Up @@ -367,7 +367,7 @@ describe('ML - job utils', () => {
},
],
},
};
} as unknown) as CombinedJob;

test('returns empty array for a detector with no partitioning fields', () => {
const resp = getPartitioningFieldNames(job, 0);
Expand All @@ -392,7 +392,7 @@ describe('ML - job utils', () => {

describe('isModelPlotEnabled', () => {
test('returns true for a job in which model plot has been enabled', () => {
const job = {
const job = ({
analysis_config: {
detectors: [
{
Expand All @@ -405,13 +405,13 @@ describe('ML - job utils', () => {
model_plot_config: {
enabled: true,
},
};
} as unknown) as Job;

expect(isModelPlotEnabled(job, 0)).toBe(true);
});

test('returns expected values for a job in which model plot has been enabled with terms', () => {
const job = {
const job = ({
analysis_config: {
detectors: [
{
Expand All @@ -426,7 +426,7 @@ describe('ML - job utils', () => {
enabled: true,
terms: 'US,AAL',
},
};
} as unknown) as Job;

expect(
isModelPlotEnabled(job, 0, [
Expand All @@ -450,7 +450,7 @@ describe('ML - job utils', () => {
});

test('returns true for jobs in which model plot has not been enabled', () => {
const job1 = {
const job1 = ({
analysis_config: {
detectors: [
{
Expand All @@ -463,18 +463,18 @@ describe('ML - job utils', () => {
model_plot_config: {
enabled: false,
},
};
const job2 = {};
} as unknown) as CombinedJob;
const job2 = ({} as unknown) as CombinedJob;

expect(isModelPlotEnabled(job1, 0)).toBe(false);
expect(isModelPlotEnabled(job2, 0)).toBe(false);
});
});

describe('isJobVersionGte', () => {
const job = {
const job = ({
job_version: '6.1.1',
};
} as unknown) as CombinedJob;

test('returns true for later job version', () => {
expect(isJobVersionGte(job, '6.1.0')).toBe(true);
Expand Down Expand Up @@ -548,12 +548,6 @@ describe('ML - job utils', () => {
});
});

describe('ML_MEDIAN_PERCENTS', () => {
test("is '50.0'", () => {
expect(ML_MEDIAN_PERCENTS).toBe('50.0');
});
});

describe('prefixDatafeedId', () => {
test('returns datafeed-prefix-job from datafeed-job"', () => {
expect(prefixDatafeedId('datafeed-job', 'prefix-')).toBe('datafeed-prefix-job');
Expand Down
Loading

0 comments on commit d0b9840

Please sign in to comment.