Skip to main content

manager.go

manager.go - Overview

  1. Overview The manager.go file defines the Manager struct and related functionalities for managing alerting rules. It includes methods for rule creation, editing, deletion, execution, state management, and notification. The manager is responsible for coordinating the interaction between the rule definitions, the data source, and the notification channels.

  2. Detailed Documentation

Type: PrepareTaskOptions

  • Purpose: Bundles the options required to prepare a Task.
  • Fields:
    • Rule: *PostableRule - The alerting rule.
    • TaskName: string - The name of the task.
    • RuleDB: RuleDB - The database interface for rules.
    • Logger: *zap.Logger - The logger for logging messages.
    • Reader: interfaces.Reader - Interface for reading data.
    • Cache: cache.Cache - Cache for storing data.
    • FF: interfaces.FeatureLookup - Feature flag lookup interface.
    • ManagerOpts: *ManagerOptions - The options for the manager.
    • NotifyFunc: NotifyFunc - The notification function.
    • SQLStore: sqlstore.SQLStore - SQLStore interface.
    • UseLogsNewSchema: bool - Use new logs schema.
    • UseTraceNewSchema: bool - Use new trace schema.

Type: PrepareTestRuleOptions

  • Purpose: Bundles the options required to prepare a Test Rule.
  • Fields:
    • Rule: *PostableRule - The alerting rule.
    • RuleDB: RuleDB - The database interface for rules.
    • Logger: *zap.Logger - The logger for logging messages.
    • Reader: interfaces.Reader - Interface for reading data.
    • Cache: cache.Cache - Cache for storing data.
    • FF: interfaces.FeatureLookup - Feature flag lookup interface.
    • ManagerOpts: *ManagerOptions - The options for the manager.
    • NotifyFunc: NotifyFunc - The notification function.
    • SQLStore: sqlstore.SQLStore - SQLStore interface.
    • UseLogsNewSchema: bool - Use new logs schema.
    • UseTraceNewSchema: bool - Use new trace schema.

Constants:

  • taskNamesuffix: string - Suffix appended to task names ("webAppEditor").

Function: RuleIdFromTaskName

  • Purpose: Extracts the rule ID from the task name.
  • Parameters:
    • n: string - The task name.
  • Returns: string - The extracted rule ID.

Function: prepareTaskName

  • Purpose: Prepares the task name from rule ID.
  • Parameters:
    • ruleId: interface{} - The rule ID which can be an integer or a string.
  • Returns: string - The generated task name.

Type: ManagerOptions

  • Purpose: Bundles options for the Manager.
  • Fields:
    • TelemetryStore: telemetrystore.TelemetryStore - Telemetry store interface.
    • Prometheus: prometheus.Prometheus - Prometheus interface.
    • RepoURL: string - URL for linking back to the repository in alert messages.
    • DBConn: *sqlx.DB - Database connection for rules.
    • Context: context.Context - Context for cancellation and deadlines.
    • Logger: *zap.Logger - Logger for logging messages.
    • ResendDelay: time.Duration - Delay before resending alerts.
    • DisableRules: bool - Disable execution of rules.
    • FeatureFlags: interfaces.FeatureLookup - Feature flag lookup interface.
    • Reader: interfaces.Reader - Interface for reading data.
    • Cache: cache.Cache - Cache for storing data.
    • EvalDelay: time.Duration - Evaluation delay.
    • PrepareTaskFunc: func(opts PrepareTaskOptions) (Task, error) - Function to prepare a task.
    • UseLogsNewSchema: bool - Use new logs schema.
    • UseTraceNewSchema: bool - Use new trace schema.
    • PrepareTestRuleFunc: func(opts PrepareTestRuleOptions) (int, *model.ApiError) - Function to prepare a test rule.
    • Alertmanager: alertmanager.Alertmanager - Alertmanager interface.
    • SQLStore: sqlstore.SQLStore - SQLStore interface.

Type: Manager

  • Purpose: Manages recording and alerting rules.
  • Fields:
    • opts: *ManagerOptions - The manager options.
    • tasks: map[string]Task - Map of tasks.
    • rules: map[string]Rule - Map of rules.
    • mtx: sync.RWMutex - Mutex for concurrent access.
    • block: chan struct{} - Channel to block execution until the manager is ready.
    • ruleDB: RuleDB - Datastore for alert definitions.
    • logger: *zap.Logger - Logger for logging messages.
    • featureFlags: `interfaces.