Skip to content

Commit

Permalink
Make rule execute events @timestamp represent the end of the event …
Browse files Browse the repository at this point in the history
…rather than the start (#119761)

* Fix event log timestamp for execute events

* commit using @elastic.co

* Fix failing jest tests

* Fix typo

* Fix failing jest tests

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
mikecote and kibanamachine authored Dec 7, 2021
1 parent 80dc3b6 commit d955835
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 63 deletions.
36 changes: 0 additions & 36 deletions x-pack/plugins/alerting/server/task_runner/task_runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ describe('Task Runner', () => {
expect(eventLogger.startTiming).toHaveBeenCalledTimes(1);
expect(eventLogger.logEvent.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -450,7 +449,6 @@ describe('Task Runner', () => {
const eventLogger = customTaskRunnerFactoryInitializerParams.eventLogger;
expect(eventLogger.logEvent).toHaveBeenCalledTimes(5);
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(1, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute-start',
category: ['alerts'],
Expand Down Expand Up @@ -582,7 +580,6 @@ describe('Task Runner', () => {
},
});
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(5, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: { action: 'execute', category: ['alerts'], kind: 'alert', outcome: 'success' },
kibana: {
alerting: {
Expand Down Expand Up @@ -671,7 +668,6 @@ describe('Task Runner', () => {
expect(eventLogger.startTiming).toHaveBeenCalledTimes(1);
expect(eventLogger.logEvent).toHaveBeenCalledTimes(4);
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(1, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute-start',
category: ['alerts'],
Expand Down Expand Up @@ -767,7 +763,6 @@ describe('Task Runner', () => {
},
});
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(4, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute',
category: ['alerts'],
Expand Down Expand Up @@ -931,7 +926,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -1001,7 +995,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute",
"category": Array [
Expand Down Expand Up @@ -1272,7 +1265,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -1418,7 +1410,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute",
"category": Array [
Expand Down Expand Up @@ -1569,7 +1560,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -1755,7 +1745,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute",
"category": Array [
Expand Down Expand Up @@ -2139,7 +2128,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -2246,7 +2234,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute",
"category": Array [
Expand Down Expand Up @@ -2481,7 +2468,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -2515,7 +2501,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"error": Object {
"message": "OMG",
},
Expand Down Expand Up @@ -2590,7 +2575,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -2624,7 +2608,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"error": Object {
"message": "OMG",
},
Expand Down Expand Up @@ -2708,7 +2691,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -2742,7 +2724,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"error": Object {
"message": "OMG",
},
Expand Down Expand Up @@ -2826,7 +2807,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -2860,7 +2840,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"error": Object {
"message": "OMG",
},
Expand Down Expand Up @@ -2943,7 +2922,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -2977,7 +2955,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"error": Object {
"message": "OMG",
},
Expand Down Expand Up @@ -3238,7 +3215,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -3416,7 +3392,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute",
"category": Array [
Expand Down Expand Up @@ -3525,7 +3500,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -3631,7 +3605,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute",
"category": Array [
Expand Down Expand Up @@ -3732,7 +3705,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -3834,7 +3806,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute",
"category": Array [
Expand Down Expand Up @@ -3930,7 +3901,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -4036,7 +4006,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute",
"category": Array [
Expand Down Expand Up @@ -4134,7 +4103,6 @@ describe('Task Runner', () => {
Array [
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -4234,7 +4202,6 @@ describe('Task Runner', () => {
],
Array [
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute",
"category": Array [
Expand Down Expand Up @@ -4383,7 +4350,6 @@ describe('Task Runner', () => {
expect(eventLogger.startTiming).toHaveBeenCalledTimes(1);
expect(eventLogger.logEvent.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"@timestamp": "1970-01-01T00:00:00.000Z",
"event": Object {
"action": "execute-start",
"category": Array [
Expand Down Expand Up @@ -4463,7 +4429,6 @@ describe('Task Runner', () => {
const eventLogger = taskRunnerFactoryInitializerParams.eventLogger;
expect(eventLogger.logEvent).toHaveBeenCalledTimes(2);
expect(eventLogger.logEvent.mock.calls[0][0]).toStrictEqual({
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute-start',
kind: 'alert',
Expand All @@ -4484,7 +4449,6 @@ describe('Task Runner', () => {
message: 'alert execution start: "1"',
});
expect(eventLogger.logEvent.mock.calls[1][0]).toStrictEqual({
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute',
kind: 'alert',
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,6 @@ export class TaskRunner<
const scheduleDelay = runDate.getTime() - this.taskInstance.runAt.getTime();

const event = createAlertEventLogRecordObject({
timestamp: runDateString,
ruleId: alertId,
ruleType: this.alertType as UntypedNormalizedAlertType,
action: EVENT_LOG_ACTIONS.execute,
Expand Down Expand Up @@ -747,7 +746,6 @@ export class TaskRunner<

const eventLogger = this.context.eventLogger;
const event: IEvent = {
'@timestamp': new Date().toISOString(),
event: {
action: EVENT_LOG_ACTIONS.executeTimeout,
kind: 'alert',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ describe('Task Runner Cancel', () => {
expect(eventLogger.logEvent).toHaveBeenCalledTimes(3);
expect(eventLogger.startTiming).toHaveBeenCalledTimes(1);
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(1, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute-start',
category: ['alerts'],
Expand Down Expand Up @@ -225,7 +224,6 @@ describe('Task Runner Cancel', () => {
},
});
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(2, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute-timeout',
category: ['alerts'],
Expand All @@ -250,7 +248,6 @@ describe('Task Runner Cancel', () => {
},
});
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(3, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute',
category: ['alerts'],
Expand Down Expand Up @@ -424,7 +421,6 @@ describe('Task Runner Cancel', () => {
expect(eventLogger.startTiming).toHaveBeenCalledTimes(1);
expect(eventLogger.logEvent).toHaveBeenCalledTimes(3);
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(1, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute-start',
category: ['alerts'],
Expand Down Expand Up @@ -453,7 +449,6 @@ describe('Task Runner Cancel', () => {
},
});
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(2, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute-timeout',
category: ['alerts'],
Expand All @@ -479,7 +474,6 @@ describe('Task Runner Cancel', () => {
},
});
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(3, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute',
category: ['alerts'],
Expand Down Expand Up @@ -539,7 +533,6 @@ describe('Task Runner Cancel', () => {
const eventLogger = taskRunnerFactoryInitializerParams.eventLogger;
expect(eventLogger.logEvent).toHaveBeenCalledTimes(6);
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(1, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute-start',
category: ['alerts'],
Expand Down Expand Up @@ -569,7 +562,6 @@ describe('Task Runner Cancel', () => {
},
});
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(2, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: {
action: 'execute-timeout',
category: ['alerts'],
Expand Down Expand Up @@ -689,7 +681,6 @@ describe('Task Runner Cancel', () => {
},
});
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(6, {
'@timestamp': '1970-01-01T00:00:00.000Z',
event: { action: 'execute', category: ['alerts'], kind: 'alert', outcome: 'success' },
kibana: {
alerting: {
Expand Down
Loading

0 comments on commit d955835

Please sign in to comment.