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 9 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
9 changes: 9 additions & 0 deletions x-pack/plugins/actions/server/lib/action_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ test('successfully executes', async () => {
},
},
},
"alerting": Object {
"outcome": "success",
},
"saved_objects": Array [
Object {
"id": "1",
Expand Down Expand Up @@ -648,6 +651,9 @@ test('writes to event log for execute and execute start', async () => {
},
},
},
alerting: {
outcome: 'success',
},
saved_objects: [
{
rel: 'primary',
Expand Down Expand Up @@ -731,6 +737,9 @@ test('writes to event log for execute and execute start when consumer and relate
rule_type_id: '.rule-type',
},
},
alerting: {
outcome: 'success',
},
saved_objects: [
{
rel: 'primary',
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,18 @@ export class ActionExecutor {
};

event.event = event.event || {};
event.kibana = event.kibana || {};
event.kibana.alerting = event.kibana.alerting || {};
doakalexi marked this conversation as resolved.
Show resolved Hide resolved

if (result.status === 'ok') {
span?.setOutcome('success');
event.event.outcome = 'success';
event.kibana.alerting.outcome = 'success';
event.message = `action executed: ${actionLabel}`;
} else if (result.status === 'error') {
span?.setOutcome('failure');
event.event.outcome = 'failure';
event.kibana.alerting.outcome = 'failure';
event.message = `action execution failure: ${actionLabel}`;
event.error = event.error || {};
event.error.message = actionErrorToMessage(result);
Expand All @@ -274,6 +278,7 @@ export class ActionExecutor {
} else {
span?.setOutcome('failure');
event.event.outcome = 'failure';
event.kibana.alerting.outcome = 'failure';
event.message = `action execution returned unexpected result: ${actionLabel}: "${result.status}"`;
event.error = event.error || {};
event.error.message = 'action execution returned unexpected result';
Expand Down
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
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
Loading