mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Change alert intervals to be configured in seconds instead of milliseconds (#40148)
This commit is contained in:
parent
73bb21b771
commit
50f3bbeaa5
11 changed files with 34 additions and 34 deletions
|
@ -190,7 +190,7 @@ Payload:
|
|||
|Property|Description|Type|
|
||||
|---|---|---|
|
||||
|alertTypeId|The id value of the alert type you want to call when the alert is scheduled to execute.|string|
|
||||
|interval|The interval in milliseconds the alert should execute.|number|
|
||||
|interval|The interval in seconds the alert should execute.|number|
|
||||
|alertTypeParams|The parameters to pass in to the alert type executor `params` value. This will also validate against the alert type params validator if defined.|object|
|
||||
|actions|Array of the following:<br> - `group` (string): We support grouping actions in the scenario of escalations or different types of alert instances. If you don't need this, feel free to use `default` as a value.<br>- `id` (string): The id of the action saved object to fire.<br>- `params` (object): The map to the `params` the action type will receive. In order to help apply context to strings, we handle them as mustache templates and pass in a default set of context. (see templating actions).|array|
|
||||
|
||||
|
@ -232,7 +232,7 @@ Payload:
|
|||
|
||||
|Property|Description|Type|
|
||||
|---|---|---|
|
||||
|interval|The interval in milliseconds the alert should execute.|number|
|
||||
|interval|The interval in seconds the alert should execute.|number|
|
||||
|alertTypeParams|The parameters to pass in to the alert type executor `params` value. This will also validate against the alert type params validator if defined.|object|
|
||||
|actions|Array of the following:<br> - `group` (string): We support grouping actions in the scenario of escalations or different types of alert instances. If you don't need this, feel free to use `default` as a value.<br>- `id` (string): The id of the action saved object to fire.<br>- `params` (object): There map to the `params` the action type will receive. In order to help apply context to strings, we handle them as mustache templates and pass in a default set of context. (see templating actions).|array|
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"type": "keyword"
|
||||
},
|
||||
"interval": {
|
||||
"type": "long"
|
||||
"type": "integer"
|
||||
},
|
||||
"actions": {
|
||||
"type": "nested",
|
||||
|
|
|
@ -37,7 +37,7 @@ const mockedDate = new Date('2019-02-12T21:01:22.479Z');
|
|||
function getMockData() {
|
||||
return {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -67,7 +67,7 @@ describe('create()', () => {
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -132,7 +132,7 @@ Object {
|
|||
"bar": true,
|
||||
},
|
||||
"id": "1",
|
||||
"interval": 10000,
|
||||
"interval": 10,
|
||||
"scheduledTaskId": "task-123",
|
||||
}
|
||||
`);
|
||||
|
@ -154,7 +154,7 @@ Object {
|
|||
"alertTypeParams": Object {
|
||||
"bar": true,
|
||||
},
|
||||
"interval": 10000,
|
||||
"interval": 10,
|
||||
}
|
||||
`);
|
||||
expect(savedObjectsClient.create.mock.calls[0][2]).toMatchInlineSnapshot(`
|
||||
|
@ -259,7 +259,7 @@ Object {
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -308,7 +308,7 @@ Array [
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -367,7 +367,7 @@ describe('get()', () => {
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -406,7 +406,7 @@ Object {
|
|||
"bar": true,
|
||||
},
|
||||
"id": "1",
|
||||
"interval": 10000,
|
||||
"interval": 10,
|
||||
}
|
||||
`);
|
||||
expect(savedObjectsClient.get).toHaveBeenCalledTimes(1);
|
||||
|
@ -425,7 +425,7 @@ Array [
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -460,7 +460,7 @@ describe('find()', () => {
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -502,7 +502,7 @@ Array [
|
|||
"bar": true,
|
||||
},
|
||||
"id": "1",
|
||||
"interval": 10000,
|
||||
"interval": 10,
|
||||
},
|
||||
]
|
||||
`);
|
||||
|
@ -525,7 +525,7 @@ describe('delete()', () => {
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -600,7 +600,7 @@ describe('update()', () => {
|
|||
id: '1',
|
||||
type: 'alert',
|
||||
attributes: {
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -625,7 +625,7 @@ describe('update()', () => {
|
|||
const result = await alertsClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -658,7 +658,7 @@ Object {
|
|||
"bar": true,
|
||||
},
|
||||
"id": "1",
|
||||
"interval": 10000,
|
||||
"interval": 10,
|
||||
}
|
||||
`);
|
||||
expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
|
||||
|
@ -679,7 +679,7 @@ Object {
|
|||
"alertTypeParams": Object {
|
||||
"bar": true,
|
||||
},
|
||||
"interval": 10000,
|
||||
"interval": 10,
|
||||
}
|
||||
`);
|
||||
expect(savedObjectsClient.update.mock.calls[0][3]).toMatchInlineSnapshot(`
|
||||
|
@ -722,7 +722,7 @@ Object {
|
|||
alertsClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
|
|
@ -171,7 +171,7 @@ export class AlertsClient {
|
|||
state: {
|
||||
// This is here because we can't rely on the task manager's internal runAt.
|
||||
// It changes it for timeout, etc when a task is running.
|
||||
scheduledRunAt: new Date(Date.now() + alert.interval),
|
||||
scheduledRunAt: new Date(Date.now() + alert.interval * 1000),
|
||||
previousScheduledRunAt: null,
|
||||
alertTypeState: {},
|
||||
alertInstances: {},
|
||||
|
|
|
@ -14,7 +14,7 @@ const createFireHandlerParams = {
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -114,7 +114,7 @@ test('throws error if reference not found', async () => {
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
|
|
@ -52,7 +52,7 @@ const mockedAlertTypeSavedObject = {
|
|||
type: 'alert',
|
||||
attributes: {
|
||||
alertTypeId: '123',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
|
|
@ -15,12 +15,12 @@ const mockedNow = new Date('2019-06-03T18:55:25.982Z');
|
|||
|
||||
test('Adds interface to given date when result is > Date.now()', () => {
|
||||
const currentRunAt = new Date('2019-06-03T18:55:23.982Z');
|
||||
const result = getNextRunAt(currentRunAt, 10000);
|
||||
const result = getNextRunAt(currentRunAt, 10);
|
||||
expect(result).toEqual(new Date('2019-06-03T18:55:33.982Z'));
|
||||
});
|
||||
|
||||
test('Uses Date.now() when the result would of been a date in the past', () => {
|
||||
const currentRunAt = new Date('2019-06-03T18:55:13.982Z');
|
||||
const result = getNextRunAt(currentRunAt, 10000);
|
||||
const result = getNextRunAt(currentRunAt, 10);
|
||||
expect(result).toEqual(mockedNow);
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
export function getNextRunAt(currentRunAt: Date, interval: number) {
|
||||
let nextRunAt = currentRunAt.getTime() + interval;
|
||||
let nextRunAt = currentRunAt.getTime() + interval * 1000;
|
||||
if (nextRunAt < Date.now()) {
|
||||
// To prevent returning dates in the past, we'll return now instead
|
||||
nextRunAt = Date.now();
|
||||
|
|
|
@ -12,7 +12,7 @@ createAlertRoute(server);
|
|||
|
||||
const mockedAlert = {
|
||||
alertTypeId: '1',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
@ -59,7 +59,7 @@ Object {
|
|||
"bar": true,
|
||||
},
|
||||
"id": "123",
|
||||
"interval": 10000,
|
||||
"interval": 10,
|
||||
}
|
||||
`);
|
||||
expect(alertsClient.create).toHaveBeenCalledTimes(1);
|
||||
|
@ -80,7 +80,7 @@ Array [
|
|||
"alertTypeParams": Object {
|
||||
"bar": true,
|
||||
},
|
||||
"interval": 10000,
|
||||
"interval": 10,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
|
|
@ -13,7 +13,7 @@ getRoute(server);
|
|||
const mockedAlert = {
|
||||
id: '1',
|
||||
alertTypeId: '1',
|
||||
interval: 10000,
|
||||
interval: 10,
|
||||
alertTypeParams: {
|
||||
bar: true,
|
||||
},
|
||||
|
|
|
@ -15,7 +15,7 @@ beforeEach(() => jest.resetAllMocks());
|
|||
const mockedResponse = {
|
||||
id: '1',
|
||||
alertTypeId: '1',
|
||||
interval: 12000,
|
||||
interval: 12,
|
||||
alertTypeParams: {
|
||||
otherField: false,
|
||||
},
|
||||
|
@ -35,7 +35,7 @@ test('calls the update function with proper parameters', async () => {
|
|||
method: 'PUT',
|
||||
url: '/api/alert/1',
|
||||
payload: {
|
||||
interval: 12000,
|
||||
interval: 12,
|
||||
alertTypeParams: {
|
||||
otherField: false,
|
||||
},
|
||||
|
@ -73,7 +73,7 @@ Array [
|
|||
"alertTypeParams": Object {
|
||||
"otherField": false,
|
||||
},
|
||||
"interval": 12000,
|
||||
"interval": 12,
|
||||
},
|
||||
"id": "1",
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue