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

[Infrastructure UI][Rules] Specify recovery context for Inventory Threshold rule type #126279

Closed
ymao1 opened this issue Feb 23, 2022 · 5 comments · Fixed by #131199
Closed

[Infrastructure UI][Rules] Specify recovery context for Inventory Threshold rule type #126279

ymao1 opened this issue Feb 23, 2022 · 5 comments · Fixed by #131199
Assignees
Labels
auto-backport Deprecated: Automatically backport this PR after it's merged Feature:Metrics UI Metrics UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v8.3.0

Comments

@ymao1
Copy link
Contributor

ymao1 commented Feb 23, 2022

The alerting framework has recently merged a PR to provide rule executors with the ability to specify context for recovered alerts. Details are available in the PR and in the alerting README but essentially,

  1. Rule types should set doesSetRecoveryContext to true on the rule type. This allows context variables to appear in the action variable list in the UI for the recovered action group.
  2. Inside the rule executor, when the executor has finished scheduling actions for active alerts, the following code should be added:
// Call done() to gain access to recovery utils
// If `doesSetRecoveryContext` is set to `false`, getRecoveredAlerts() returns an empty list
const { getRecoveredAlerts } = alertsFactory.done();

for (const alert of getRecoveredAlerts()) {
	const alertId = alert.getId();
	alert.setContext({
		CONTEXT HERE!
	})
}

Note that currently, we expect the recovered context to match the existing typing for context variables on the rule.

@botelastic botelastic bot added the needs-team Issues missing a team label label Feb 23, 2022
@ymao1 ymao1 added the Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services label Feb 23, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/infra-monitoring-ui (Team:Infra Monitoring UI)

@botelastic botelastic bot removed the needs-team Issues missing a team label label Feb 23, 2022
@weltenwort weltenwort changed the title Specify recovery context for Infra rule types [Infra UI] Specify recovery context for Infra rule types Feb 23, 2022
@simianhacker
Copy link
Member

@ymao1 Is there a way to get the previous alert action group. For example, with the Metric Threshold alerts, there are 2 action groups: metric.threshold.fired and metric.threshold.warning. Eventually, I would like to add a third for NO DATA. One of the variables for the context is reason which should probably be tailored to the why it's recovered. For example, if we previously trigger a metric.threshold.warn or metric.threshold.fired then we would want to construct a reason message like CPU Usage for host-01 has recovered. Current value is {{value}}. But if it was a "NO DATA" alert (which we are going to add metric.thresold.nodata) we would want to have Data for host-01 is now available.

@simianhacker simianhacker changed the title [Infra UI] Specify recovery context for Infra rule types [Infrastructure UI][Rules] Specify recovery context for Inventory Threshold rule type Mar 7, 2022
@simianhacker simianhacker added the Feature:Metrics UI Metrics UI feature label Mar 7, 2022
@ymao1
Copy link
Contributor Author

ymao1 commented Mar 8, 2022

@simianhacker Yes there is! We keep track of this in the lastScheduledActions on the alert

For recovered alerts you can do something like this:

const { getRecoveredAlerts } = services.alertFactory.done();
for (const alert of getRecoveredAlerts()) {
  const lastScheduledActionGroup = alert.getLastScheduledActions().group;
}

where lastScheduledActions looks like:

{
    group: <action group id>
    date: iso string representing the date the action was scheduled.
}

Does that work for your use case?

@simianhacker
Copy link
Member

@ymao1 Yes it does, thank you ❤️

@nugroho-exp
Copy link

HI @simianhacker, I have Kibana v8.3.2 but recovery context is still empty. Looking at the merge date it seems
it is merged just after 8.3.0 branch is created. Would it be possible to backport it to 8.3.x? Thank you.

@simianhacker simianhacker added the auto-backport Deprecated: Automatically backport this PR after it's merged label Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated: Automatically backport this PR after it's merged Feature:Metrics UI Metrics UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v8.3.0
Projects
None yet
5 participants