kibana/x-pack/plugins/notifications
Alexi Doak 03f0cdc327
[ResponseOps][Alerting] Create xpack.actions.queued.max circuit breaker (#164632)
Resolves https://github.com/elastic/kibana/issues/162264


## Summary

Adds a limit on the maximum number of actions that can be queued with a
circuit breaker. The limit in serverless is set to 10,000, and 1,000,000
in the other environments.

- If a rule execution exceeds the limit, the circuit breaker kicks in
and stops triggering actions.
- Alerting rule's status updated to warning when circuit breaker is hit

Did not update the `enqueueExecution` bc it's going to be removed in
https://github.com/elastic/kibana/pull/165120.


### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios


### To Verify

- Create a 2 rules that have actions
- Set `xpack.actions.queued.max` in kibana.yml to a low number like 2 or
3
- Use the run soon button to queue up actions and hit the circuit
breaker.
- The actions will not be scheduled and the rule status will be set to
warning

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-09-07 06:59:01 -07:00
..
common
server [ResponseOps][Alerting] Create xpack.actions.queued.max circuit breaker (#164632) 2023-09-07 06:59:01 -07:00
jest.config.js
kibana.jsonc [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
README.md
tsconfig.json Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00

Kibana Notifications Plugin

The Notifications plugin provides a set of services to help Solutions and plugins send notifications to users.

Notifications Plugin public API

Start

The start function exposes the following interface:

  • isEmailServiceAvailable(): boolean: A function to check whether the deployment is properly configured and the EmailService can be correctly retrieved.
  • getEmailService(): EmailService:
  • A function to get the basic EmailService, which can be used to send plain text emails. If the EmailService is not available, trying to retrieve it will result in an Exception.

Usage

To use the exposed plugin start contract:

  1. Make sure notifications is in your optionalPlugins in the kibana.json file:
// <plugin>/kibana.json
{
"id": "...",
"requiredPlugins": ["notifications"]
}
  1. Use the exposed contract:
// <plugin>/server/plugin.ts
import { NotificationsPluginStart } from '../notifications/server`;

interface MyPluginStartDeps {
  notifications?: NotificationsPluginStart;
}

class MyPlugin {
  public start(
    core: CoreStart,
    { notifications }: MyPluginStartDeps
  ) {
    if (notifications.isEmailServiceAvailable()) {
      const emailService = notifications.getEmailService();
      emailService.sendPlainTextEmail({
          to: 'foo@bar.com',
          subject: 'Some subject',
          message: 'Hello world!',
      });
    }
    ...
  }
}

Requirements

  • This plugin currently depends on the 'actions' plugin, as it uses Connectors under the hood.

  • Note also that for each notification channel the corresponding connector must be preconfigured. E.g. to enable email notifications, an Email connector must exist in the system.

  • Once the appropriate connectors are preconfigured in kibana.yaml, you can configure the 'notifications' plugin by adding:

    notifications:
      connectors:
        default:
          email: elastic-cloud-email  # The identifier of the configured connector