Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps][Alerting] Rule run history displays success with a message when the rule status is warning #142645

Merged
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
30ccfd1
Adding new field to the event log
doakalexi Oct 4, 2022
7bf3e81
Fixing tests
doakalexi Oct 4, 2022
31b175b
Merge branch 'main' into alerting/rule-run-history-matches-status
doakalexi Oct 4, 2022
faa8e84
Fixing additional tests
doakalexi Oct 4, 2022
3b289c1
Merge branch 'alerting/rule-run-history-matches-status' of github.com…
doakalexi Oct 4, 2022
33c7d30
Fixing types
doakalexi Oct 5, 2022
42534af
Adding runtime fields
doakalexi Oct 5, 2022
502eaa7
Fixing tests and global event log
doakalexi Oct 5, 2022
1723e06
Fixing jest tests
doakalexi Oct 5, 2022
508690e
Update x-pack/plugins/alerting/server/lib/get_execution_log_aggregati…
doakalexi Oct 6, 2022
81e23cd
Removing action executor
doakalexi Oct 6, 2022
b2e2346
Merge branch 'alerting/rule-run-history-matches-status' of github.com…
doakalexi Oct 6, 2022
b4766c0
Removing runtime fields
doakalexi Oct 10, 2022
885d0c9
Cleaning up some of the changes
doakalexi Oct 10, 2022
756a5b8
Using variable instead of string
doakalexi Oct 10, 2022
591108b
Merge branch 'main' into alerting/rule-run-history-matches-status
doakalexi Oct 10, 2022
d48c414
Adding back unknown
doakalexi Oct 11, 2022
a06ccf1
Merge branch 'alerting/rule-run-history-matches-status' of github.com…
doakalexi Oct 11, 2022
459eea7
Adding back status color
doakalexi Oct 11, 2022
4b14ec1
Fixing failing test
doakalexi Oct 11, 2022
7c0cd8a
Merge branch 'main' of github.com:elastic/kibana into alerting/rule-r…
doakalexi Oct 12, 2022
2e3408c
Adding new test
doakalexi Oct 12, 2022
e2a78ae
Fixing jest tests
doakalexi Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/common/execution_log_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const EMPTY_EXECUTION_KPI_RESULT = {
success: 0,
unknown: 0,
failure: 0,
warning: 0,
activeAlerts: 0,
newAlerts: 0,
recoveredAlerts: 0,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/common/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export enum RuleExecutionStatusWarningReasons {
MAX_ALERTS = 'maxAlerts',
}

export type RuleAlertingOutcome = 'failure' | 'success' | 'warning';

export interface RuleExecutionStatus {
status: RuleExecutionStatuses;
lastExecutionDate: Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ describe('AlertingEventLogger', () => {
...event.rule,
name: 'my-super-cool-rule',
},
kibana: {
...event.kibana,
alerting: {
outcome: 'success',
},
},
message: 'success!',
});
});
Expand Down Expand Up @@ -260,6 +266,12 @@ describe('AlertingEventLogger', () => {
error: {
message: 'something went wrong!',
},
kibana: {
...event.kibana,
alerting: {
outcome: 'failure',
},
},
message: 'rule failed!',
});
});
Expand Down Expand Up @@ -446,6 +458,7 @@ describe('AlertingEventLogger', () => {
...event?.kibana,
alerting: {
status: 'error',
outcome: 'failure',
},
},
message: 'test:123: execution failed',
Expand Down Expand Up @@ -484,6 +497,7 @@ describe('AlertingEventLogger', () => {
...event?.kibana,
alerting: {
status: 'error',
outcome: 'failure',
},
},
message: 'test:123: execution failed',
Expand Down Expand Up @@ -526,6 +540,7 @@ describe('AlertingEventLogger', () => {
...event?.kibana,
alerting: {
status: 'error',
outcome: 'failure',
},
},
message: 'i am an existing error message',
Expand Down Expand Up @@ -560,6 +575,7 @@ describe('AlertingEventLogger', () => {
...event?.kibana,
alerting: {
status: 'warning',
outcome: 'warning',
},
},
message: 'something funky happened',
Expand Down Expand Up @@ -594,6 +610,7 @@ describe('AlertingEventLogger', () => {
...event?.kibana,
alerting: {
status: 'warning',
outcome: 'warning',
},
},
message: 'something funky happened',
Expand Down Expand Up @@ -630,6 +647,7 @@ describe('AlertingEventLogger', () => {
...event?.kibana,
alerting: {
status: 'warning',
outcome: 'success',
},
},
message: 'success!',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,20 @@ export class AlertingEventLogger {
throw new Error('AlertingEventLogger not initialized');
}

updateEvent(this.event, { message, outcome: 'success' });
updateEvent(this.event, { message, outcome: 'success', alertingOutcome: 'success' });
}

public setExecutionFailed(message: string, errorMessage: string) {
if (!this.isInitialized || !this.event) {
throw new Error('AlertingEventLogger not initialized');
}

updateEvent(this.event, { message, outcome: 'failure', error: errorMessage });
updateEvent(this.event, {
message,
outcome: 'failure',
alertingOutcome: 'failure',
error: errorMessage,
});
}

public logTimeout() {
Expand Down Expand Up @@ -175,6 +180,7 @@ export class AlertingEventLogger {
if (status.error) {
updateEvent(this.event, {
outcome: 'failure',
alertingOutcome: 'failure',
reason: status.error?.reason || 'unknown',
error: this.event?.error?.message || status.error.message,
...(this.event.message
Expand All @@ -186,6 +192,7 @@ export class AlertingEventLogger {
} else {
if (status.warning) {
updateEvent(this.event, {
alertingOutcome: 'warning',
reason: status.warning?.reason || 'unknown',
message: status.warning?.message || this.event?.message,
});
Expand Down Expand Up @@ -325,15 +332,18 @@ export function initializeExecuteRecord(context: RuleContext) {
interface UpdateEventOpts {
message?: string;
outcome?: string;
alertingOutcome?: string;
error?: string;
ruleName?: string;
status?: string;
reason?: string;
metrics?: RuleRunMetrics;
timings?: TaskRunnerTimings;
}

export function updateEvent(event: IEvent, opts: UpdateEventOpts) {
const { message, outcome, error, ruleName, status, reason, metrics, timings } = opts;
const { message, outcome, error, ruleName, status, reason, metrics, timings, alertingOutcome } =
opts;
if (!event) {
throw new Error('Cannot update event because it is not initialized.');
}
Expand All @@ -346,6 +356,12 @@ export function updateEvent(event: IEvent, opts: UpdateEventOpts) {
event.event.outcome = outcome;
}

if (alertingOutcome) {
event.kibana = event.kibana || {};
event.kibana.alerting = event.kibana.alerting || {};
event.kibana.alerting.outcome = alertingOutcome;
}

if (error) {
event.error = event.error || {};
event.error.message = error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ describe('getExecutionLogAggregation', () => {
'kibana.version',
'rule.id',
'rule.name',
'kibana.alerting.outcome',
],
},
},
Expand Down Expand Up @@ -486,6 +487,7 @@ describe('getExecutionLogAggregation', () => {
'kibana.version',
'rule.id',
'rule.name',
'kibana.alerting.outcome',
],
},
},
Expand Down Expand Up @@ -691,6 +693,7 @@ describe('getExecutionLogAggregation', () => {
'kibana.version',
'rule.id',
'rule.name',
'kibana.alerting.outcome',
],
},
},
Expand Down Expand Up @@ -787,6 +790,9 @@ describe('formatExecutionLogResult', () => {
},
kibana: {
version: '8.2.0',
alerting: {
outcome: 'success',
},
},
message:
"rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'",
Expand Down Expand Up @@ -866,12 +872,14 @@ describe('formatExecutionLogResult', () => {
_score: 1.0,
_source: {
rule: { id: 'a348a740-9e2c-11ec-bd64-774ed95c43ef', name: 'rule_name' },

event: {
outcome: 'success',
},
kibana: {
version: '8.2.0',
alerting: {
outcome: 'success',
},
},
message:
"rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'",
Expand Down Expand Up @@ -1028,6 +1036,9 @@ describe('formatExecutionLogResult', () => {
},
kibana: {
version: '8.2.0',
alerting: {
outcome: 'failure',
},
},
message:
"rule execution failure: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'",
Expand Down Expand Up @@ -1115,6 +1126,9 @@ describe('formatExecutionLogResult', () => {
},
kibana: {
version: '8.2.0',
alerting: {
outcome: 'success',
},
},
message:
"rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'",
Expand Down Expand Up @@ -1271,6 +1285,9 @@ describe('formatExecutionLogResult', () => {
},
kibana: {
version: '8.2.0',
alerting: {
outcome: 'success',
},
},
message:
"rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'",
Expand Down Expand Up @@ -1350,6 +1367,9 @@ describe('formatExecutionLogResult', () => {
},
kibana: {
version: '8.2.0',
alerting: {
outcome: 'success',
},
},
message:
"rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'",
Expand Down Expand Up @@ -1506,6 +1526,9 @@ describe('formatExecutionLogResult', () => {
},
kibana: {
version: '8.2.0',
alerting: {
outcome: 'success',
},
},
message:
"rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'",
Expand Down Expand Up @@ -1590,6 +1613,9 @@ describe('formatExecutionLogResult', () => {
},
kibana: {
version: '8.2.0',
alerting: {
outcome: 'success',
},
},
message:
"rule executed: example.always-firing:a348a740-9e2c-11ec-bd64-774ed95c43ef: 'test rule'",
Expand Down Expand Up @@ -1808,9 +1834,17 @@ describe('getExecutionKPIAggregation', () => {
},
},
ruleExecutionOutcomes: {
terms: {
field: 'event.outcome',
size: 2,
multi_terms: {
size: 3,
terms: [
{
field: 'kibana.alerting.outcome',
missing: '',
},
{
field: 'event.outcome',
},
],
},
},
},
Expand Down Expand Up @@ -1959,9 +1993,17 @@ describe('getExecutionKPIAggregation', () => {
},
},
ruleExecutionOutcomes: {
terms: {
field: 'event.outcome',
size: 2,
multi_terms: {
size: 3,
terms: [
{
field: 'kibana.alerting.outcome',
missing: '',
},
{
field: 'event.outcome',
},
],
},
},
},
Expand Down Expand Up @@ -2110,9 +2152,17 @@ describe('getExecutionKPIAggregation', () => {
},
},
ruleExecutionOutcomes: {
terms: {
field: 'event.outcome',
size: 2,
multi_terms: {
size: 3,
terms: [
{
field: 'kibana.alerting.outcome',
missing: '',
},
{
field: 'event.outcome',
},
],
},
},
},
Expand Down Expand Up @@ -2150,6 +2200,7 @@ describe('formatExecutionKPIAggBuckets', () => {
success: 0,
triggeredActions: 0,
unknown: 0,
warning: 0,
});
});

Expand Down Expand Up @@ -2188,7 +2239,8 @@ describe('formatExecutionKPIAggBuckets', () => {
sum_other_doc_count: 0,
buckets: [
{
key: 'success',
key: ['success', 'success'],
key_as_string: 'success|success',
doc_count: 3,
},
],
Expand Down Expand Up @@ -2233,7 +2285,8 @@ describe('formatExecutionKPIAggBuckets', () => {
sum_other_doc_count: 0,
buckets: [
{
key: 'success',
key: ['success', 'success'],
key_as_string: 'success|success',
doakalexi marked this conversation as resolved.
Show resolved Hide resolved
doc_count: 2,
},
],
Expand Down Expand Up @@ -2264,6 +2317,7 @@ describe('formatExecutionKPIAggBuckets', () => {
success: 5,
unknown: 0,
failure: 0,
warning: 0,
activeAlerts: 10,
newAlerts: 10,
recoveredAlerts: 0,
Expand Down
Loading