Documentation
¶
Index ¶
- Constants
- type ChannelInfo
- type ChannelInfoProvider
- type FifoQueueConsumer
- type FifoQueueProducer
- type PrometheusAlert
- type PrometheusWebhook
- type Server
- func (s *Server) Run(ctx context.Context) error
- func (s *Server) UpdateSettings(settings *config.APISettings) error
- func (s *Server) WithCacheStore(cacheStore cachestore.StoreInterface) *Server
- func (s *Server) WithMetrics(metrics types.Metrics) *Server
- func (s *Server) WithRawAlertConsumer(consumer FifoQueueConsumer) *Server
- func (s *Server) WithSettings(settings *config.APISettings) *Server
- type SlackClient
Constants ¶
const NA = "N/A"
const True = "true"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelInfo ¶
type ChannelInfo struct {
ChannelExists bool
ChannelIsArchived bool
ManagerIsInChannel bool
UserCount int
}
ChannelInfo contains information about a Slack channel. Returned by [ChannelInfoProvider.GetChannelInfo].
type ChannelInfoProvider ¶
type ChannelInfoProvider interface {
// GetChannelInfo returns [ChannelInfo] for the given Slack channel ID. The result
// is served from an internal cache and refreshed periodically in the background.
// A cache miss triggers a direct Slack API lookup.
GetChannelInfo(ctx context.Context, channel string) (*ChannelInfo, error)
// MapChannelNameToIDIfNeeded converts a human-readable channel name (e.g. "alerts")
// to its Slack channel ID. If the input is already a channel ID, it is returned
// unchanged. This allows alert clients to use either form interchangeably.
MapChannelNameToIDIfNeeded(channelName string) string
// ManagedChannels returns the current list of Slack channels the bot is a member of.
ManagedChannels() []*internal.ChannelSummary
}
ChannelInfoProvider supplies Slack channel metadata to the Server for request validation and channel listing.
type FifoQueueConsumer ¶
type FifoQueueConsumer interface {
Receive(ctx context.Context, sinkCh chan<- *types.FifoQueueItem) error
}
FifoQueueConsumer is the read side of a FIFO queue. It is used by the Server to consume raw alert items delivered outside of the HTTP API (e.g. via a secondary SQS or Redis Streams queue registered with Server.WithRawAlertConsumer).
type FifoQueueProducer ¶
type FifoQueueProducer interface {
Send(ctx context.Context, slackChannelID, dedupID, body string) error
}
FifoQueueProducer is the write side of a FIFO queue. The Server uses it to dispatch processed alerts to the Manager for issue lifecycle handling.
type PrometheusAlert ¶
type PrometheusAlert struct {
Status string `json:"status,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
StartsAt time.Time `json:"startsAt"`
EndsAt time.Time `json:"endsAt"`
GeneratorURL string `json:"generatorURL,omitempty"` //nolint:tagliatelle
Fingerprint string `json:"fingerprint,omitempty"`
}
PrometheusAlert is a single alert entry within a PrometheusWebhook payload.
type PrometheusWebhook ¶
type PrometheusWebhook struct {
Version string `json:"version,omitempty"`
GroupKey string `json:"groupKey,omitempty"`
TruncatedAlerts int `json:"truncatedAlerts,omitempty"`
Status string `json:"status,omitempty"`
Receiver string `json:"receiver,omitempty"`
GroupLabels map[string]string `json:"groupLabels,omitempty"`
CommonLabels map[string]string `json:"commonLabels,omitempty"`
CommonAnnotations map[string]string `json:"commonAnnotations,omitempty"`
ExternalURL string `json:"externalURL,omitempty"` //nolint:tagliatelle
Alerts []*PrometheusAlert `json:"alerts,omitempty"`
}
PrometheusWebhook is the JSON payload sent by Prometheus Alertmanager to the /prometheus-alert endpoint. It follows the Alertmanager webhook v4 format. Each payload contains one or more PrometheusAlert entries in the Alerts field.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the Slack Manager REST API server. It accepts alerts from external monitoring systems, applies per-channel token-bucket rate limiting, and enqueues them for the Manager to process into Slack issues.
Create a Server with New and start it with Server.Run. API settings can be updated at runtime via Server.UpdateSettings without restarting the service.
func New ¶
New creates a Server with the three required dependencies.
Optional dependencies can be configured via method chaining before calling Server.Run:
- Server.WithCacheStore — sets the cache store (defaults to in-process go-cache, unsuitable for multi-instance)
- Server.WithMetrics — sets the metrics implementation (defaults to no-op)
- Server.WithSettings — sets the initial API settings (defaults to zero-value)
func (*Server) Run ¶
Run starts the HTTP server and handles incoming requests. It also initializes the Slack API client and the channel info syncer. If raw alert consumers are set, it will start dedicated consumers for those queues.
This method blocks until the context is cancelled, or a server error occurs.
func (*Server) UpdateSettings ¶
func (s *Server) UpdateSettings(settings *config.APISettings) error
UpdateSettings hot-reloads API settings without restarting. The new settings are validated before being applied; if validation fails the existing settings remain active and an error is returned. Passing nil replaces the current settings with zero-value defaults.
func (*Server) WithCacheStore ¶ added in v0.5.0
func (s *Server) WithCacheStore(cacheStore cachestore.StoreInterface) *Server
WithCacheStore sets the cache store. If not called, Server.Run defaults to an in-process go-cache instance (unsuitable for multi-instance deployments that require shared channel-info caching). Passing nil is a no-op.
func (*Server) WithMetrics ¶ added in v0.5.0
WithMetrics sets the metrics implementation. If not called, a no-op implementation is used. Passing nil is a no-op.
func (*Server) WithRawAlertConsumer ¶
func (s *Server) WithRawAlertConsumer(consumer FifoQueueConsumer) *Server
WithRawAlertConsumer registers a FifoQueueConsumer that reads alerts outside of the HTTP API (e.g. from SQS or Redis Streams). The consumer is started by Server.Run in a dedicated goroutine.
Multiple raw alert consumers can be added.
The server can receive alerts from both the main rest API and the raw alert consumers simultaneously.
The queue item body must be a single JSON-serialized types.Alert. Prometheus webhooks are not supported here.
func (*Server) WithSettings ¶ added in v0.5.0
func (s *Server) WithSettings(settings *config.APISettings) *Server
WithSettings sets the initial API settings. If not called, zero-value settings are used. For runtime updates after Server.Run is started, use Server.UpdateSettings instead. Passing nil is a no-op.
type SlackClient ¶
type SlackClient interface {
GetChannelInfo(ctx context.Context, channelID string) (*slack.Channel, error)
GetUserIDsInChannel(ctx context.Context, channelID string) (map[string]struct{}, error)
BotIsInChannel(ctx context.Context, channelID string) (bool, error)
ListBotChannels(ctx context.Context) ([]*internal.ChannelSummary, error)
}
SlackClient is the Slack API subset required by the Server for channel validation (membership checks, user counts) and for listing managed channels.