Skip to main content

manager.go

manager.go - Overview

  1. Overview

This file defines functions for preparing rule tasks and testing notifications based on different rule types (Threshold, PromQL, Anomaly). It also includes a helper function for creating tasks.

  1. Detailed Documentation

PrepareTaskFunc

  • Purpose: Creates a task based on the provided options, including the rule type (Threshold, PromQL, or Anomaly). It initializes the appropriate rule and task type based on the configuration.
  • Parameters:
    • opts (baserules.PrepareTaskOptions): Contains all the necessary options to create a task, including the rule, feature flags, reader, manager options, SQL store, notification function, and rule database.
  • Returns:
    • baserules.Task: The created task.
    • error: An error if the task creation fails.

TestNotification

  • Purpose: Prepares a dummy rule based on provided parameters and sends a test notification.
  • Parameters:
    • opts (baserules.PrepareTestRuleOptions): Contains options needed for creating the test rule, including the rule itself, feature flags, reader, manager options, SQL store, logger and notification function.
  • Returns:
    • int: The number of alerts found during evaluation.
    • *basemodel.ApiError: An API error if something goes wrong.

newTask

  • Purpose: Returns a new task object based on the specified task type.
  • Parameters:
    • taskType (baserules.TaskType): The type of task to create (e.g., baserules.TaskTypeCh, baserules.TaskTypeProm).
    • name (string): The name of the task.
    • frequency (time.Duration): The frequency at which the task should run.
    • rules ([]baserules.Rule): A slice of rules to be executed by the task.
    • opts (*baserules.ManagerOptions): Manager options for task execution.
    • notify (baserules.NotifyFunc): The notification function to be called when alerts are triggered.
    • ruleDB (baserules.RuleDB): The rule database.
  • Returns:
    • baserules.Task: A new task instance of the appropriate type.
  1. Code Examples

None

  1. Clarity and Accuracy

The documentation accurately reflects the code's functionality.

  1. Markdown & MDX Perfection

The documentation is formatted correctly using Markdown.

  1. Edge Cases To Avoid Breaking MDX:

N/A

  1. Getting Started Relevance

Include in Getting Started: NO