Documentation
¶
Index ¶
- Constants
- type Alert
- func (a *Alert) Ack()
- func (a *Alert) ApplyLegacyFields()
- func (a *Alert) InsightsEvent(eventType types.InsightsEventType, reason, channelID string) types.InsightsEvent
- func (a *Alert) LogFields() map[string]any
- func (a *Alert) Nack()
- func (a *Alert) SetDefaultValues(settings *config.ManagerSettings)
- type Command
- type CommandAction
- type EscalationResult
- type InFlightMessage
- type InFlightMsgConstructor
- type Issue
- func (issue *Issue) AddAlert(alert *Alert, logger types.Logger) bool
- func (issue *Issue) AddAlertWithReason(alert *Alert, logger types.Logger) (bool, string)
- func (issue *Issue) ApplyEscalationRules() *EscalationResult
- func (issue *Issue) ArchivedInsightsEvent(archivedAt time.Time) types.InsightsEvent
- func (issue *Issue) ChannelID() string
- func (issue *Issue) CurrentPostID() string
- func (issue *Issue) FindWebhook(id string) *types.Webhook
- func (issue *Issue) FollowUpEnabled() bool
- func (issue *Issue) GetCorrelationID() string
- func (issue *Issue) GetSlackAction() SlackAction
- func (issue *Issue) HasSlackPost() bool
- func (issue *Issue) InsightsEvent(eventType types.InsightsEventType, reason string) types.InsightsEvent
- func (issue *Issue) IsInfoOrResolved() bool
- func (issue *Issue) IsLowerPriorityThan(other *Issue) bool
- func (issue *Issue) IsOpen() bool
- func (issue *Issue) IsReadyForArchiving() bool
- func (issue *Issue) IsResolved() bool
- func (issue *Issue) IsResolvedAsInconclusive() bool
- func (issue *Issue) IsResolvedAt(t time.Time) bool
- func (issue *Issue) LastAlertHasActiveMentions() bool
- func (issue *Issue) LogFields() map[string]any
- func (issue *Issue) MarshalJSON() ([]byte, error)
- func (issue *Issue) MarshalJSONAndCache() ([]byte, error)
- func (issue *Issue) RegisterArchiving()
- func (issue *Issue) RegisterHideOptionButtonsRequest()
- func (issue *Issue) RegisterInvestigateRequest(user string)
- func (issue *Issue) RegisterMoveRequest(reason MoveIssueReason, user, newChannelID, newChannelName string)
- func (issue *Issue) RegisterMuteRequest(user string)
- func (issue *Issue) RegisterResolveRequest(user string)
- func (issue *Issue) RegisterShowOptionButtonsRequest()
- func (issue *Issue) RegisterSlackPostCreatedOrUpdated(slackPostID string, action SlackAction)
- func (issue *Issue) RegisterSlackPostDeleted()
- func (issue *Issue) RegisterSlackPostInvalidBlocks()
- func (issue *Issue) RegisterTerminationRequest(user string)
- func (issue *Issue) RegisterUninvestigateRequest()
- func (issue *Issue) RegisterUnmuteRequest()
- func (issue *Issue) RegisterUnresolveRequest()
- func (issue *Issue) ResetCachedJSONBody()
- func (issue *Issue) Resolution() string
- func (issue *Issue) UniqueID() string
- type ManagerSettingsWrapper
- type MoveIssueReason
- type MoveMapping
- type SlackAction
- type WebhookCommandParams
Constants ¶
const ( CommandActionTerminateIssue = CommandAction("terminate_issue") CommandActionResolveIssue = CommandAction("resolve_issue") CommandActionUnresolveIssue = CommandAction("unresolve_issue") CommandActionInvestigateIssue = CommandAction("investigate_issue") CommandActionUninvestigateIssue = CommandAction("uninvestigate_issue") CommandActionMuteIssue = CommandAction("mute_issue") CommandActionUnmuteIssue = CommandAction("unmute_issue") CommandActionMoveIssue = CommandAction("move_issue") CommandActionCreateIssue = CommandAction("create_issue") CommandActionShowIssueOptionButtons = CommandAction("show_issue_option_buttons") CommandActionHideIssueOptionButtons = CommandAction("hide_issue_option_buttons") CommandActionWebhook = CommandAction("webhook") )
const ( // MoveIssueReasonEscalation indicates the issue was moved due to escalation rules. MoveIssueReasonEscalation = MoveIssueReason("ESCALATION") // MoveIssueReasonUserCommand indicates the issue was moved manually by a Slack user. MoveIssueReasonUserCommand = MoveIssueReason("USER_COMMAND") )
const ( ActionNone = SlackAction("NONE") ActionAlert = SlackAction("ALERT") ActionResolve = SlackAction("RESOLVE") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
types.Alert
SlackChannelName string `json:"slackChannelName"`
OriginalSlackChannelID string `json:"originalSlackChannelId"`
OriginalText string `json:"originalText"`
// contains filtered or unexported fields
}
Alert represents an alert message to be sent to a Slack channel. It extends the types.Alert struct with additional fields needed in this package.
func (*Alert) Ack ¶
func (a *Alert) Ack()
Ack acknowledges the alert message, indicating successful processing. Any subsequent calls to Ack or Nack will have no effect.
func (*Alert) ApplyLegacyFields ¶
func (a *Alert) ApplyLegacyFields()
ApplyLegacyFields maps deprecated legacy alert fields to their current equivalents. The deprecated DeletionDelaySeconds is used as the archiving delay when ArchivingDelaySeconds is not set. Must be called before SetDefaultValues, which sets a default archiving delay.
func (*Alert) InsightsEvent ¶
func (a *Alert) InsightsEvent(eventType types.InsightsEventType, reason, channelID string) types.InsightsEvent
InsightsEvent returns an insights event of the given type and reason, describing this alert as processed in channelID. RelatedChannelID is set to the original channel if the alert was redirected by a move mapping.
func (*Alert) LogFields ¶
LogFields returns a map of key-value pairs representing the Alert's important fields for logging purposes.
func (*Alert) Nack ¶
func (a *Alert) Nack()
Nack negatively acknowledges the alert message, indicating processing failure and requesting re-delivery. Any subsequent calls to Ack or Nack will have no effect.
func (*Alert) SetDefaultValues ¶
func (a *Alert) SetDefaultValues(settings *config.ManagerSettings)
SetDefaultValues sets default values for the Alert fields based on the provided ManagerSettings.
type Command ¶
type Command struct {
Timestamp time.Time `json:"timestamp"`
SlackChannelID string `json:"slackChannelId,omitempty"`
SlackPostID string `json:"ts,omitempty"`
Reaction string `json:"reaction,omitempty"`
UserID string `json:"userId,omitempty"`
UserRealName string `json:"userRealName,omitempty"`
Action CommandAction `json:"action,omitempty"`
Parameters map[string]any `json:"parameters,omitempty"`
WebhookParameters *WebhookCommandParams `json:"webhookParameters,omitempty"`
IncludeArchivedIssues bool `json:"includeArchivedIssues"`
ExecuteWhenNoIssueFound bool `json:"executeWhenNoIssueFound"`
// contains filtered or unexported fields
}
Command represents a user-initiated action within Slack that the system needs to process.
func NewCommand ¶
func NewCommand(slackChannelID, ts, reaction, userID, userRealName string, action CommandAction, parameters map[string]any) *Command
NewCommand creates a new Command instance with the provided parameters.
func (*Command) Ack ¶
func (c *Command) Ack()
Ack acknowledges the command message, indicating successful processing. Any subsequent calls to Ack or Nack will have no effect.
func (*Command) DedupID ¶
DedupID generates a deduplication ID for the command based on its key attributes.
func (*Command) LogFields ¶
LogFields returns a map of key-value pairs representing the Command's important fields for logging purposes.
func (*Command) Nack ¶
func (c *Command) Nack()
Nack negatively acknowledges the command message, indicating processing failure and requesting re-delivery. Any subsequent calls to Ack or Nack will have no effect.
func (*Command) ParamAsBool ¶
ParamAsBool retrieves a boolean parameter by key from the Command's Parameters map.
func (*Command) ParamAsInt ¶
ParamAsInt retrieves an integer parameter by key from the Command's Parameters map.
func (*Command) ParamAsString ¶
ParamAsString retrieves a string parameter by key from the Command's Parameters map.
type CommandAction ¶
type CommandAction string
CommandAction represents the type of action a user has initiated within Slack.
type EscalationResult ¶
type EscalationResult struct {
Issue *Issue
Escalated bool
MoveToChannel string
// Changed is true if the escalation became active for the first time, or raised the issue severity,
// in this attempt. Escalated stays true on every attempt while a rule is active; Changed does not.
Changed bool
// PrevSeverity is the issue severity before the escalation was applied (only set when Escalated is true).
PrevSeverity types.AlertSeverity
}
EscalationResult represents the outcome of an escalation attempt for an issue.
type InFlightMessage ¶
type InFlightMessage interface {
Ack()
Nack()
}
InFlightMessage represents a message that is currently being processed. It should be acknowledged (Ack) or negatively acknowledged (Nack) once processing is complete.
Ack and Nack do not accept a context parameter because acknowledgment is a commitment that must complete regardless of the caller's context state. Each queue implementation is responsible for managing its own timeouts and retry logic internally.
func NewAlertFromQueueItem ¶
func NewAlertFromQueueItem(queueItem *types.FifoQueueItem) (InFlightMessage, error)
NewAlertFromQueueItem creates a new Alert instance from a FifoQueueItem. It unmarshals the JSON body of the queue item into an Alert struct.
func NewCommandFromQueueItem ¶
func NewCommandFromQueueItem(queueItem *types.FifoQueueItem) (InFlightMessage, error)
NewCommandFromQueueItem creates a Command instance from a FIFO queue item. It unmarshals the JSON body of the queue item into a Command struct.
type InFlightMsgConstructor ¶
type InFlightMsgConstructor func(queueItem *types.FifoQueueItem) (InFlightMessage, error)
InFlightMsgConstructor is a function type that constructs an InFlightMessage from a FifoQueueItem. The actual implementation may vary based on the message type (e.g., Alert, Command).
type Issue ¶
type Issue struct {
ID string `json:"id"`
CorrelationID string `json:"correlationId"`
Created time.Time `json:"created"`
// FirstAlert is the first alert that created this issue. This field is retained for debugging
// purposes only and is not used in any business logic.
FirstAlert *Alert `json:"firstAlert"`
// LastAlert is the most recent alert for this issue. All issue state is derived from this alert.
// This field must never be nil after issue creation or deserialization.
LastAlert *Alert `json:"lastAlert"`
AlertCount int `json:"alertCount"`
LastAlertReceived time.Time `json:"lastAlertReceived"`
LastSlackMention string `json:"lastSlackMention"`
LastSlackMentionTime time.Time `json:"lastSlackMentionTime"`
AutoResolvePeriod time.Duration `json:"autoResolvePeriod"`
ArchiveDelay time.Duration `json:"archiveDelay"`
ArchiveTime time.Time `json:"archiveTime"`
Archived bool `json:"archived"`
ResolveTime time.Time `json:"resolveTime"`
SlackPostID string `json:"slackPostId"`
SlackPostCreated time.Time `json:"slackPostCreated"`
SlackPostUpdated time.Time `json:"slackPostUpdated"`
SlackPostHeader string `json:"slackPostHeader"`
SlackPostText string `json:"slackPostText"`
SlackPostLastAction SlackAction `json:"slackPostLastAction"`
SlackPostNeedsUpdate bool `json:"slackPostNeedsUpdate"`
SlackPostNeedsDelete bool `json:"slackPostNeedsDelete"`
SlackAlertSentAtLeastOnce bool `json:"slackAlertSentAtLeastOnce"`
SlackPostDelayedUntil time.Time `json:"slackPostDelayedUntil"`
// The following IsEmoji* fields use "slackPostEmoji*" JSON tags for backward compatibility
// with existing serialized data and external API consumers.
IsEmojiTerminated bool `json:"slackPostEmojiTerminated"`
IsEmojiResolved bool `json:"slackPostEmojiResolved"`
IsEmojiInvestigated bool `json:"slackPostEmojiInvestigated"`
IsEmojiMuted bool `json:"slackPostEmojiMuted"`
IsEmojiButtonsActivated bool `json:"slackPostEmojiButtonsActivated"`
IsMoved bool `json:"isMoved"`
TerminatedByUser string `json:"terminatedByUser"`
ResolvedByUser string `json:"resolvedByUser"`
InvestigatedByUser string `json:"investigatedByUser"`
InvestigatedSince time.Time `json:"investigatedSince"`
MutedByUser string `json:"mutedByUser"`
MutedSince time.Time `json:"mutedSince"`
MoveReason MoveIssueReason `json:"moveReason"`
MovedByUser string `json:"movedByUser"`
IsEscalated bool `json:"isEscalated"`
// FirstInvestigatedAt is when the issue was first marked as investigated. Unlike InvestigatedSince,
// it is never reset, so it can be used to compute the time to first investigation.
FirstInvestigatedAt time.Time `json:"firstInvestigatedAt"`
// ReopenCount is the number of times the issue went from resolved back to unresolved,
// by a new alert or an unresolve request.
ReopenCount int `json:"reopenCount"`
// contains filtered or unexported fields
}
Issue represents one or more alerts with the same correlation ID (in the same Slack channel). Issues are created when the first alert with a given correlation ID is received, and updated when new alerts arrive with the same correlation ID. Issues can be resolved, archived, and have a connected Slack post.
func NewIssue ¶
NewIssue creates a new Issue from an Alert. Returns nil if the provided alert is nil.
func (*Issue) AddAlert ¶
AddAlert adds a new alert to an existing issue. Alerts that are older than the previous alert are ignored. Alerts with status Resolved are ignored if the issue is already resolved. This method is only relevant for issues that have follow-up enabled. For issues without follow-up, all new alerts are ignored.
Note: This method may mutate the provided alert's Severity field when escalation is active and the current severity is higher than the incoming alert's severity.
The SlackPostDelayedUntil is calculated from issue.Created (not current time) by design, ensuring the issue doesn't appear until the original delay period has elapsed, regardless of how many alerts are added to the issue.
func (*Issue) AddAlertWithReason ¶
AddAlertWithReason works like Issue.AddAlert, and additionally returns the reason the alert was ignored (one of the types.InsightsReason* values for ignored alerts) when it returns false.
func (*Issue) ApplyEscalationRules ¶
func (issue *Issue) ApplyEscalationRules() *EscalationResult
func (*Issue) ArchivedInsightsEvent ¶
func (issue *Issue) ArchivedInsightsEvent(archivedAt time.Time) types.InsightsEvent
ArchivedInsightsEvent returns the types.InsightsEventIssueArchived event for this issue, archived at the given time. The event reason is the Issue.Resolution, and the values hold lifecycle durations and counts.
func (*Issue) CurrentPostID ¶
func (*Issue) FollowUpEnabled ¶
func (*Issue) GetCorrelationID ¶
func (*Issue) GetSlackAction ¶
func (issue *Issue) GetSlackAction() SlackAction
GetSlackAction returns the Slack action needed for this issue
func (*Issue) HasSlackPost ¶
HasSlackPost returns true if this issue has a connected Slack post at this moment
func (*Issue) InsightsEvent ¶
func (issue *Issue) InsightsEvent(eventType types.InsightsEventType, reason string) types.InsightsEvent
InsightsEvent returns an insights event of the given type and reason, describing this issue in its current channel. Count is set to the issue alert count.
func (*Issue) IsInfoOrResolved ¶
func (*Issue) IsLowerPriorityThan ¶
IsLowerPriorityThan returns true if this issue has lower priority than the other issue
func (*Issue) IsReadyForArchiving ¶
IsReadyForArchiving returns true if the issue is ready to be archived
func (*Issue) IsResolved ¶
func (*Issue) IsResolvedAsInconclusive ¶
func (*Issue) IsResolvedAt ¶
IsResolvedAt returns true if the issue is resolved at the given time. An issue with follow-up is resolved from its resolve time (inclusive), so an explicit resolve takes effect immediately.
func (*Issue) LastAlertHasActiveMentions ¶
LastAlertHasActiveMentions returns true if the last alert has active Slack mentions, that are not muted
func (*Issue) MarshalJSON ¶
func (*Issue) MarshalJSONAndCache ¶
func (*Issue) RegisterArchiving ¶
func (issue *Issue) RegisterArchiving()
RegisterArchiving registers that the issue has been archived
func (*Issue) RegisterHideOptionButtonsRequest ¶
func (issue *Issue) RegisterHideOptionButtonsRequest()
func (*Issue) RegisterInvestigateRequest ¶
func (*Issue) RegisterMoveRequest ¶
func (issue *Issue) RegisterMoveRequest(reason MoveIssueReason, user, newChannelID, newChannelName string)
func (*Issue) RegisterMuteRequest ¶
func (*Issue) RegisterResolveRequest ¶
func (*Issue) RegisterShowOptionButtonsRequest ¶
func (issue *Issue) RegisterShowOptionButtonsRequest()
func (*Issue) RegisterSlackPostCreatedOrUpdated ¶
func (issue *Issue) RegisterSlackPostCreatedOrUpdated(slackPostID string, action SlackAction)
RegisterSlackPostCreatedOrUpdated registers that a Slack post has been created or updated for this issue
func (*Issue) RegisterSlackPostDeleted ¶
func (issue *Issue) RegisterSlackPostDeleted()
RegisterSlackPostDeleted registers that the Slack post connected to this issue has been deleted
func (*Issue) RegisterSlackPostInvalidBlocks ¶
func (issue *Issue) RegisterSlackPostInvalidBlocks()
RegisterSlackPostInvalidBlocks registers that a Slack post could not be created due to invalid blocks (i.e. bad message formatting). It zeros out the Slack post information, but sets the SlackPostNeedsUpdate flag to false, to avoid trying again until the next alert.
func (*Issue) RegisterTerminationRequest ¶
RegisterTerminationRequest registers that the Slack post connected to this issue has been marked for termination via Slack reaction/emoji
func (*Issue) RegisterUninvestigateRequest ¶
func (issue *Issue) RegisterUninvestigateRequest()
func (*Issue) RegisterUnmuteRequest ¶
func (issue *Issue) RegisterUnmuteRequest()
func (*Issue) RegisterUnresolveRequest ¶
func (issue *Issue) RegisterUnresolveRequest()
func (*Issue) ResetCachedJSONBody ¶
func (issue *Issue) ResetCachedJSONBody()
func (*Issue) Resolution ¶
Resolution returns how the issue ended (or would end, if archived now), as one of the types.InsightsReason* values used by types.InsightsEventIssueArchived.
type ManagerSettingsWrapper ¶
type ManagerSettingsWrapper struct {
// contains filtered or unexported fields
}
ManagerSettingsWrapper wraps the ManagerSettings configuration with thread-safe access. The wrapper allows hot-reloading of settings without passing them around directly. All access to the settings should go through GetSettings() and SetSettings() methods to ensure thread safety during hot-reloading.
func NewManagerSettingsWrapper ¶
func NewManagerSettingsWrapper(settings *config.ManagerSettings) *ManagerSettingsWrapper
NewManagerSettingsWrapper creates a new ManagerSettingsWrapper with the given settings.
func (*ManagerSettingsWrapper) GetSettings ¶
func (w *ManagerSettingsWrapper) GetSettings() *config.ManagerSettings
GetSettings returns the current settings in a thread-safe manner.
func (*ManagerSettingsWrapper) SetSettings ¶
func (w *ManagerSettingsWrapper) SetSettings(settings *config.ManagerSettings)
SetSettings updates the settings in a thread-safe manner.
type MoveIssueReason ¶
type MoveIssueReason string
MoveIssueReason represents the reason for moving an issue between Slack channels.
type MoveMapping ¶
type MoveMapping struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
CorrelationID string `json:"correlationId"`
OriginalChannelID string `json:"originalChannelId"`
TargetChannelID string `json:"targetChannelId"`
Reason MoveIssueReason `json:"reason"`
}
MoveMapping represents information about an issue moved between Slack channels.
func NewMoveMapping ¶
func NewMoveMapping(correlationID, originalChannelID, targetChannelID string, reason MoveIssueReason) *MoveMapping
NewMoveMapping creates a new MoveMapping instance.
func (*MoveMapping) ChannelID ¶
func (m *MoveMapping) ChannelID() string
ChannelID returns the original channel ID of the move mapping, i.e., where the issue was moved from.
func (*MoveMapping) GetCorrelationID ¶
func (m *MoveMapping) GetCorrelationID() string
GetCorrelationID returns the issue correlation ID associated with the move mapping.
func (*MoveMapping) MarshalJSON ¶
func (m *MoveMapping) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface, which is required by the types.MoveMapping interface.
func (*MoveMapping) UniqueID ¶
func (m *MoveMapping) UniqueID() string
UniqueID returns the unique identifier of the move mapping.
type SlackAction ¶
type SlackAction string
type WebhookCommandParams ¶
type WebhookCommandParams struct {
WebhookID string `json:"webhookId"`
PlainTextInput map[string]string `json:"plainTextInput,omitempty"`
CheckboxInput map[string][]string `json:"checkboxInput,omitempty"`
}
WebhookCommandParams holds parameters specific to webhook commands.