provider.go
provider.go - Overview
-
Overview The
provider.go
file defines theprovider
struct and its associated methods, which implement thealertmanager.Alertmanager
interface. This provider acts as an intermediary between the application and the underlying Alertmanager service, handling configuration, state management, and alert operations specific to the SigNoz implementation. It also manages the synchronization of Alertmanager servers. -
Detailed Documentation
type provider
- Purpose: The
provider
struct encapsulates the Alertmanager service, configuration, settings, data stores, and a stop channel for managing the Alertmanager lifecycle. - Members:
service
: An instance ofalertmanager.Service
that manages the Alertmanager lifecycle.config
: Analertmanager.Config
instance that contains configuration parameters.settings
:factory.ScopedProviderSettings
providing scoped settings for the provider.configStore
: Analertmanagertypes.ConfigStore
for storing and retrieving Alertmanager configurations.stateStore
: Analertmanagertypes.StateStore
for storing and retrieving Alertmanager state.stopC
: A channel used to signal theStart
method to stop its execution.
func NewFactory
- Purpose: Creates a new
factory.ProviderFactory
for the SigNoz Alertmanager provider. This factory is responsible for instantiating theprovider
based on the provided settings and configuration. - Parameters:
sqlstore
(sqlstore.SQLStore
): The SQL store instance to be used by the config and state stores.
- Returns:
factory.ProviderFactory[alertmanager.Alertmanager, alertmanager.Config]
: A new provider factory for creatingprovider
instances.
func New
- Purpose: Creates a new
provider
instance. It initializes the service, config store, and state store. - Parameters:
ctx
(context.Context
): The context for the operation.providerSettings
(factory.ProviderSettings
): Provider-specific settings.config
(alertmanager.Config
): The Alertmanager configuration.sqlstore
(sqlstore.SQLStore
): The SQL store for persistence.
- Returns:
*provider
: A newprovider
instance.error
: An error if any of the initialization steps fail.
func (provider *provider) Start
- Purpose: Starts the Alertmanager service and begins synchronizing Alertmanager servers at a defined interval.
- Parameters:
ctx
(context.Context
): The context for the operation.
- Returns:
error
: An error if the initial sync fails.
func (provider *provider) Stop
- Purpose: Stops the Alertmanager service.
- Parameters:
ctx
(context.Context
): The context for the operation.
- Returns:
error
: An error if stopping the service fails.
func (provider *provider) GetAlerts
- Purpose: Retrieves alerts from the Alertmanager service.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.params
(alertmanagertypes.GettableAlertsParams
): Parameters for filtering alerts.
- Returns:
alertmanagertypes.DeprecatedGettableAlerts
: A list of alerts.error
: An error if retrieving the alerts fails.
func (provider *provider) PutAlerts
- Purpose: Puts (creates/updates) alerts into the Alertmanager service.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.alerts
(alertmanagertypes.PostableAlerts
): The alerts to be put.
- Returns:
error
: An error if putting the alerts fails.
func (provider *provider) TestReceiver
- Purpose: Tests a receiver configuration.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.receiver
(alertmanagertypes.Receiver
): The receiver to test.
- Returns:
error
: An error if testing the receiver fails.
func (provider *provider) TestAlert
- Purpose: Tests an alert configuration.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.alert
(*alertmanagertypes.PostableAlert
): The alert to test.receivers
([]string
): A list of receivers to send the test alert to.
- Returns:
error
: An error if testing the alert fails.
func (provider *provider) ListChannels
- Purpose: Lists all channels for a given organization.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.
- Returns:
[]*alertmanagertypes.Channel
: A list of channels.error
: An error if listing the channels fails.
func (provider *provider) ListAllChannels
- Purpose: Lists all channels (across all organizations).
- Parameters:
ctx
(context.Context
): The context for the operation.
- Returns:
[]*alertmanagertypes.Channel
: A list of channels.error
: An error if listing the channels fails.
func (provider *provider) GetChannelByID
- Purpose: Retrieves a channel by its ID.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.channelID
(valuer.UUID
): The ID of the channel.
- Returns:
*alertmanagertypes.Channel
: The channel, or nil if not found.error
: An error if retrieving the channel fails.
func (provider *provider) UpdateChannelByReceiverAndID
- Purpose: Updates a channel with the provided receiver.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.receiver
(alertmanagertypes.Receiver
): The receiver to update the channel with.id
(valuer.UUID
): The ID of the channel to update.
- Returns:
error
: An error if updating the channel fails.
func (provider *provider) DeleteChannelByID
- Purpose: Deletes a channel by its ID.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.channelID
(valuer.UUID
): The ID of the channel to delete.
- Returns:
error
: An error if deleting the channel fails.
func (provider *provider) CreateChannel
- Purpose: Creates a new channel.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.receiver
(alertmanagertypes.Receiver
): The receiver to create the channel from.
- Returns:
error
: An error if creating the channel fails.
func (provider *provider) SetConfig
- Purpose: Sets the Alertmanager configuration.
- Parameters:
ctx
(context.Context
): The context for the operation.config
(*alertmanagertypes.Config
): The configuration to set.
- Returns:
error
: An error if setting the configuration fails.
func (provider *provider) GetConfig
- Purpose: Retrieves the Alertmanager configuration for a given organization.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.
- Returns:
*alertmanagertypes.Config
: The Alertmanager configuration.error
: An error if retrieving the configuration fails.
func (provider *provider) SetDefaultConfig
- Purpose: Sets the default Alertmanager configuration for a given organization.
- Parameters:
ctx
(context.Context
): The context for the operation.orgID
(string
): The organization ID.
- Returns:
error
: An error if setting the default configuration fails.
-
Code Examples N/A
-
Clarity and Accuracy The documentation accurately reflects the code's functionality.
Include in Getting Started: YES