Skip to content

Public alerts API #4667

Open
Open
@TarantoolBot

Description

@TarantoolBot

Dev. issue: tarantool/tarantool#10873

Product: Tarantool
Since: 3.3.0
Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/config/
SME: @ grafin

Details

Users can now raise their own alerts (similar to the alerts raised by
the config module).

New available methods:

  • config:new_alerts_namespace(alerts_namespace_name) - creates a new
    alerts namespaces and returns it. alerts_namespace_name must be a
    string and can not contain a colon (":").
  • alerts_namespace:add(alert) - raises new alert of type warning.
    alert must be a table. alert.message is logged and the alert will
    be shown in box.info.config.alerts.
  • alerts_namespace:set(key, alert) - raises new alert of type warning,
    or replaces an existing, raised with the same 'key' in the namespace.
    alert must be a table. alert.message is logged and the alert will
    be shown in box.info.config.alerts. key must be a string and can
    not contain a colon (":").
  • alerts_namespace:unset(key) - discards the alert with the
    corresponding 'key' in the namespace. key must be a
    string and can not contain a colon (":"). If an alert with the
    corresponding key does not exist in the namespace, does nothing.
  • alerts_namespace:clear() - discards all alerts from the namespace,
    removing them from box.info.config.alerts.

Alerts namespaces with the same name will point to the same alerts
namespace. During configuration update all alerts from namespaces are
removed from box.info.config.alerts.

The alert.type is forced to be "warn", anything except "warn" or
nil is considered an error.

Any keys in alert which start with an underscore will be ignored.

Example usage:

local config = require('config')

-- Create a new alerts namespace 'my_alerts'.
local alerts = config:new_alerts_namespace('my_alerts')

-- Raise a new alert.
alerts:add({
    message = 'Test alert',
    my_field = 'my_value',
})

-- Raise a new alert with a key.
alerts:set("my_alert", {
    message = 'Test alert',
    my_field = 'my_value',
})

-- Update an existing alert with a key.
alerts:set("my_alert", {
    message = 'Test alert',
    my_field = 'my_value',
})

-- Discard an existing alert with a key.
alerts:unset("my_alert")

-- Clear all alerts in the alerts namespace 'my_alerts'
alerts:clear()

Requested by @grafin in tarantool/tarantool@4691346.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.3server[area] Task relates to Tarantool's server (core) functionality

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions