config.go
config.go - Overview
-
Overview This file defines the data structures and functions for managing Alertmanager configurations within the Signoz platform. It handles loading, storing, and manipulating Alertmanager configurations, including global settings, routes, and receivers. It also defines the interface for interacting with the configuration store.
-
Detailed Documentation
Constants
DefaultReceiverName
- Purpose: Defines the default receiver name.
- Type:
string
- Value:
"default-receiver"
Variables
ErrCodeAlertmanagerConfigInvalid
- Purpose: Defines an error code for invalid Alertmanager configurations.
- Type:
errors.Code
ErrCodeAlertmanagerConfigNotFound
- Purpose: Defines an error code for when an Alertmanager configuration is not found.
- Type:
errors.Code
ErrCodeAlertmanagerConfigConflict
- Purpose: Defines an error code for Alertmanager configuration conflicts (e.g., duplicate receiver names).
- Type:
errors.Code
Type Aliases
GlobalConfig
- Purpose: Alias for
config.GlobalConfig
from the Prometheus Alertmanager config package. - Type:
config.GlobalConfig
- Purpose: Alias for
Type Definitions
RouteConfig
- Purpose: Represents the routing configuration for Alertmanager.
- Fields:
GroupByStr
: Slice of strings for grouping alerts.- Type:
[]string
GroupInterval
: Duration for grouping alerts.- Type:
time.Duration
GroupWait
: Duration to wait before sending grouped alerts.- Type:
time.Duration
RepeatInterval
: Duration for repeating alerts.- Type:
time.Duration
StoreableConfig
- Purpose: Represents the Alertmanager configuration stored in the database.
- Fields:
bun.BaseModel
: Base model for bun ORM.- Type:
bun.BaseModel
types.Identifiable
: Embedded struct for identifiable entities (includes an ID).- Type:
types.Identifiable
types.TimeAuditable
: Embedded struct for time-auditable entities (includes CreatedAt, UpdatedAt).- Type:
types.TimeAuditable
Config
: The Alertmanager configuration in string format (JSON).- Type:
string
Hash
: Hash of the configuration for change detection.- Type:
string
OrgID
: Organization ID associated with the configuration.- Type:
string
Config
- Purpose: Represents the Alertmanager configuration. It holds both the Alertmanager's native config and the storeable config.
- Fields:
alertmanagerConfig
: The actual Alertmanager configuration.- Type:
*config.Config
storeableConfig
: The storeable representation of the configuration.- Type:
*StoreableConfig
Functions
NewConfig(c *config.Config, orgID string) *Config
- Purpose: Creates a new
Config
instance from an Alertmanager configuration and an organization ID. - Parameters:
c
: The Alertmanager configuration.- Type:
*config.Config
orgID
: The organization ID.- Type:
string
- Returns:
- Type:
*Config
- Represents: A pointer to a new
Config
instance.
- Type:
NewConfigFromStoreableConfig(sc *StoreableConfig) (*Config, error)
- Purpose: Creates a new
Config
instance from a storeable configuration. - Parameters:
sc
: The storeable configuration.- Type:
*StoreableConfig
- Returns:
- Type:
*Config, error
- Represents: A pointer to a new
Config
instance and an error, if any.
- Type:
NewDefaultConfig(globalConfig GlobalConfig, routeConfig RouteConfig, orgID string) (*Config, error)
- Purpose: Creates a new
Config
with default values, merged with provided configurations. - Parameters:
globalConfig
: The global configuration.- Type:
GlobalConfig
routeConfig
: The route configuration.- Type:
RouteConfig
orgID
: The organization ID.- Type:
string
- Returns:
- Type:
*Config, error
- Represents: A pointer to a new
Config
instance and an error, if any.
- Type:
newConfigFromString(s string) (*config.Config, error)
- Purpose: Creates a
config.Config
from a JSON string. - Parameters:
s
: The JSON string representing the configuration.- Type:
string
- Returns:
- Type:
*config.Config, error
- Represents: A pointer to a new
config.Config
instance and an error, if any.
- Type:
newRawFromConfig(c *config.Config) []byte
- Purpose: Serializes an Alertmanager config to a JSON byte array.
- Parameters:
c
: The Alertmanager config.- Type:
*config.Config
- Returns:
- Type:
[]byte
- Represents: The JSON byte array representing the config.
- Type:
newConfigHash(s string) [16]byte
- Purpose: Creates an MD5 hash of a string.
- Parameters:
s
: The string to hash.- Type:
string
- Returns:
- Type:
[16]byte
- Represents: The MD5 hash of the string.
- Type:
(c *Config) CopyWithReset() (*Config, error)
- Purpose: Creates a copy of the config with reset values.
- Parameters:
c
: The config to copy.- Type:
*Config
- Returns:
- Type:
*Config, error
- Represents: A pointer to a new
Config
instance and an error, if any.
- Type:
(c *Config) SetGlobalConfig(globalConfig GlobalConfig) error
- Purpose: Sets the global configuration for the
Config
instance. - Parameters:
globalConfig
: The global configuration to set.- Type:
GlobalConfig
- Returns:
- Type:
error
- Represents: An error, if any.
- Type:
(c *Config) SetRouteConfig(routeConfig RouteConfig) error
- Purpose: Sets the route configuration for the
Config
instance. - Parameters:
routeConfig
: The route configuration to set.- Type:
RouteConfig
- Returns:
- Type:
error
- Represents: An error, if any.
- Type:
(c *Config) AlertmanagerConfig() *config.Config
- Purpose: Returns the underlying Alertmanager configuration.
- Parameters: None
- Returns:
- Type:
*config.Config
- Represents: A pointer to the Alertmanager configuration.
- Type:
(c *Config) StoreableConfig() *StoreableConfig
- Purpose: Returns the storeable configuration.
- Parameters: None
- Returns:
- Type:
*StoreableConfig
- Represents: A pointer to the storeable configuration.
- Type:
(c *Config) CreateReceiver(receiver config.Receiver) error
- Purpose: Creates a new receiver in the Alertmanager configuration.
- Parameters:
receiver
: The receiver to create.- Type:
config.Receiver
- Returns:
- Type:
error
- Represents: An error, if any.
- Type:
(c *Config) GetReceiver(name string) (Receiver, error)
- Purpose: Retrieves a receiver by its name.
- Parameters:
name
: The name of the receiver to retrieve.- Type:
string
- Returns:
- Type:
Receiver, error
- Represents: The receiver and an error, if any.
- Type:
(c *Config) UpdateReceiver(receiver config.Receiver) error
- Purpose: Updates an existing receiver in the Alertmanager configuration.
- Parameters:
receiver
: The receiver to update.- Type:
config.Receiver
- Returns:
- Type:
error
- Represents: An error, if any.
- Type:
(c *Config) DeleteReceiver(name string) error
- Purpose: Deletes a receiver from the Alertmanager configuration.
- Parameters:
name
: The name of the receiver to delete.- Type:
string
- Returns:
- Type:
error
- Represents: An error, if any.
- Type:
(c *Config) CreateRuleIDMatcher(ruleID string, receiverNames []string) error
- Purpose: Creates a matcher for a rule ID and associates it with the given receiver names.
- Parameters:
ruleID
: The ID of the rule.- Type:
string
receiverNames
: A slice of receiver names to associate with the rule ID.- Type:
[]string
- Returns:
- Type:
error
- Represents: An error, if any.
- Type:
(c *Config) UpdateRuleIDMatcher(ruleID string, receiverNames []string) error
- Purpose: Updates a matcher for a rule ID.
- Parameters:
ruleID
: The ID of the rule.- Type:
string
receiverNames
: A slice of receiver names to associate with the rule ID.- Type:
[]string
- Returns:
- Type:
error
- Represents: An error, if any.
- Type:
(c *Config) DeleteRuleIDMatcher(ruleID string) error
- Purpose: Deletes a matcher for a rule ID.
- Parameters:
ruleID
: The ID of the rule.- Type:
string
- Returns:
- Type:
error
- Represents: An error, if any.
- Type:
(c *Config) ReceiverNamesFromRuleID(ruleID string) []string
- Purpose: Returns a list of receiver names associated with a given rule ID.
- Parameters:
ruleID
: The ID of the rule.- Type:
string
- Returns:
- Type:
[]string
- Represents: A slice of receiver names.
- Type:
storeOptions
- Purpose: Options for store operations.
- Fields:
Cb
: Callback function to be executed.- Type:
func(context.Context) error
StoreOption
- Purpose: Type for store options.
- Type:
func(*storeOptions)
WithCb(cb func(context.Context) error) StoreOption
- Purpose: Creates a StoreOption with a callback function.
- Parameters:
cb
: Callback function to be executed.- Type:
func(context.Context) error
- Returns:
- Type:
StoreOption
- Represents: A StoreOption with the provided callback.
- Type:
NewStoreOptions(opts ...StoreOption) *storeOptions
- Purpose: Creates a new StoreOptions instance from a list of StoreOption.
- Parameters:
opts
: A list of StoreOption.- Type:
...StoreOption
- Returns:
- Type:
*storeOptions
- Represents: A pointer to a new
StoreOptions
instance.
- Type:
ConfigStore
- Purpose: Interface for storing and retrieving Alertmanager configurations and channels.
- Methods:
Set(context.Context, *Config, ...StoreOption) error
: Creates or updates a config.Get(context.Context, string) (*Config, error)
: Returns the config for the given orgID.ListOrgs(context.Context) ([]string, error)
: Returns the list of orgs.CreateChannel(context.Context, *Channel, ...StoreOption) error
: Creates a new channel.GetChannelByID(context.Context, string, valuer.UUID) (*Channel, error)
: Returns the channel for the given id.UpdateChannel(context.Context, string, *Channel, ...StoreOption) error
: Updates a channel.DeleteChannelByID(context.Context, string, valuer.UUID, ...StoreOption) error
: Deletes a channel.ListChannels(context.Context, string) ([]*Channel, error)
: Returns the list of channels.ListAllChannels(context.Context) ([]*Channel, error)
: Returns the list of channels for all organizations.GetMatchers(context.Context, string) (map[string][]string, error)
: Gets a list of matchers per organization.
init()
- Purpose: Initializes the package by setting global configurations related to secret value marshalling and name validation scheme.
- Parameters: None
- Returns: None
-
Code Examples N/A
-
Clarity and Accuracy The documentation is based on the code provided and aims to be accurate.
Include in Getting Started: NO