Skip to content

Commit

Permalink
expanded test on thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Oct 20, 2020
1 parent 508a726 commit 14faf60
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
54 changes: 52 additions & 2 deletions x-pack/plugins/task_manager/server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,37 @@ describe('config validation', () => {
`);
});

test('the monitored_task_execution_thresholds warn_threshold must be lte error_threshold', () => {
test('the monitored_task_execution_thresholds ensures that the default warn_threshold is lt the default error_threshold', () => {
const config: Record<string, unknown> = {
monitored_task_execution_thresholds: {
default: {
warn_threshold: 80,
error_threshold: 70,
},
},
};
expect(() => {
configSchema.validate(config);
}).toThrowErrorMatchingInlineSnapshot(
`"[monitored_task_execution_thresholds.default]: warn_threshold (80) must be less than, or equal to, error_threshold (70)"`
);
});

test('the monitored_task_execution_thresholds allows the default warn_threshold to equal the default error_threshold', () => {
const config: Record<string, unknown> = {
monitored_task_execution_thresholds: {
default: {
warn_threshold: 70,
error_threshold: 70,
},
},
};
expect(() => {
configSchema.validate(config);
}).not.toThrowError();
});

test('the monitored_task_execution_thresholds ensures that the warn_threshold is lte error_threshold on custom thresholds', () => {
const config: Record<string, unknown> = {
monitored_task_execution_thresholds: {
custom: {
Expand All @@ -131,7 +161,27 @@ describe('config validation', () => {
expect(() => {
configSchema.validate(config);
}).toThrowErrorMatchingInlineSnapshot(
`"[monitored_task_execution_thresholds.custom.alerting:always-fires]: warn_threshold must be less than, or equal to, error_threshold"`
`"[monitored_task_execution_thresholds.custom.alerting:always-fires]: warn_threshold (90) must be less than, or equal to, error_threshold (80)"`
);
});

test('the monitored_task_execution_thresholds allows a custom error_threshold which is lower than the default warn_threshold', () => {
const config: Record<string, unknown> = {
monitored_task_execution_thresholds: {
default: {
warn_threshold: 80,
error_threshold: 90,
},
custom: {
'alerting:always-fires': {
error_threshold: 60,
warn_threshold: 50,
},
},
},
};
expect(() => {
configSchema.validate(config);
}).not.toThrowError();
});
});
10 changes: 3 additions & 7 deletions x-pack/plugins/task_manager/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ export const taskExecutionFailureThresholdSchema = schema.object(
}),
},
{
validate: (config) => {
if (
config.error_threshold &&
config.warn_threshold &&
config.warn_threshold > config.error_threshold
) {
return `warn_threshold must be less than, or equal to, error_threshold`;
validate(config) {
if (config.error_threshold < config.warn_threshold) {
return `warn_threshold (${config.warn_threshold}) must be less than, or equal to, error_threshold (${config.error_threshold})`;
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { of, Subject } from 'rxjs';
import { take, bufferCount } from 'rxjs/operators';
import { createMonitoringStatsStream, AggregatedStat } from './monitoring_stats_stream';
import { JsonValue } from 'src/plugins/kibana_utils/common';
import { ManagedConfiguration } from '../lib/create_managed_configuration';

beforeEach(() => {
jest.resetAllMocks();
Expand Down

0 comments on commit 14faf60

Please sign in to comment.