Documentation
¶
Index ¶
- Constants
- Variables
- func NewDeliveryError(kind DeliveryErrorKind, code string, cause error) error
- func Observe(state State, outcome Outcome, options Options) (State, Decision, error)
- func ValidateEventFacts(event EventFacts) error
- func ValidateNotification(notification Notification) error
- func ValidateOutcome(outcome Outcome) error
- func ValidateState(state State) error
- type BuzzConfig
- type Config
- type CoolingIncidentStatus
- type Decision
- type DeliveryError
- type DeliveryErrorKind
- type DeliveryRecord
- type DeliveryStatus
- type DeliverySummary
- type Envelope
- type EventFacts
- type EventKind
- type Factory
- type FailureDefinition
- type FailureType
- type Incident
- type IncidentPhase
- type IncidentSnapshot
- type Manager
- type ManagerOption
- type Notification
- func BuildFailureMessage(incident Incident, repeatAfter time.Duration) (Notification, error)
- func BuildRecoveryMessage(incidents []Incident, createdAt time.Time, repeatAfter time.Duration) (Notification, error)
- func BuildReminderMessage(incident Incident, repeatAfter time.Duration) (Notification, error)
- func DeriveNotification(event EventFacts) (Notification, error)
- type OpenIncidentStatus
- type Operation
- type Options
- type Outcome
- type OutcomeStatus
- type Provider
- type ProviderStatus
- type Reader
- type Receipt
- type Registry
- type SlackConfig
- type State
- type StateStore
- type Status
- type Store
Constants ¶
const ( StateSchemaV1 = "dbrain.notifications.state.v1" StateSchemaV2 = "dbrain.notifications.state.v2" )
Variables ¶
var ErrStatusInvalid = errors.New("notification_status_invalid")
Functions ¶
func NewDeliveryError ¶
func NewDeliveryError(kind DeliveryErrorKind, code string, cause error) error
func ValidateEventFacts ¶
func ValidateEventFacts(event EventFacts) error
func ValidateNotification ¶
func ValidateNotification(notification Notification) error
func ValidateOutcome ¶
func ValidateState ¶
Types ¶
type BuzzConfig ¶
type BuzzConfig struct {
Enabled bool
RelayURL string
ChannelID string
PrivateKeyRef string
AllowPrivateOrigin bool
}
func LoadBuzzConfig ¶
func LoadBuzzConfig(rootDir string) (BuzzConfig, error)
LoadBuzzConfig loads and validates the Buzz provider independently from the global notification kill switch. It is intended for read-only inspection and explicit provider tests; automatic delivery must continue to use LoadConfig.
type Config ¶
type Config struct {
Enabled bool
RepeatAfter time.Duration
Buzz BuzzConfig
Slack SlackConfig
}
func LoadConfig ¶
func LoadInspectionConfig ¶
LoadInspectionConfig loads the redacted operator view independently from the automatic-delivery kill switch. Unlike LoadConfig, it validates the repeat interval and any explicitly enabled provider even when delivery is disabled.
type CoolingIncidentStatus ¶
type CoolingIncidentStatus struct {
FailureType FailureType `json:"failure_type"`
Occurrences int `json:"occurrences"`
RearmsAt time.Time `json:"rearms_at"`
}
type Decision ¶
type Decision struct {
Notifications []Notification
}
type DeliveryError ¶
type DeliveryError struct {
Kind DeliveryErrorKind
Code string
// contains filtered or unexported fields
}
func (*DeliveryError) Error ¶
func (e *DeliveryError) Error() string
func (*DeliveryError) Unwrap ¶
func (e *DeliveryError) Unwrap() error
type DeliveryErrorKind ¶
type DeliveryErrorKind string
const ( DeliveryErrorTemporary DeliveryErrorKind = "temporary" DeliveryErrorPermanent DeliveryErrorKind = "permanent" DeliveryErrorAmbiguous DeliveryErrorKind = "ambiguous" )
type DeliveryRecord ¶
type DeliveryStatus ¶
type DeliveryStatus string
const ( DeliveryPending DeliveryStatus = "pending" DeliveryAccepted DeliveryStatus = "accepted" DeliveryPermanentError DeliveryStatus = "permanent_error" DeliveryAmbiguous DeliveryStatus = "ambiguous" DeliveryRetired DeliveryStatus = "retired" )
type DeliverySummary ¶
type DeliverySummary struct {
NotificationID string `json:"notification_id,omitempty"`
Provider string `json:"provider,omitempty"`
Kind EventKind `json:"kind,omitempty"`
Status DeliveryStatus `json:"status,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
At time.Time `json:"at,omitempty"`
}
type Envelope ¶
type Envelope struct {
Event EventFacts `json:"event"`
Deliveries map[string]DeliveryRecord `json:"deliveries"`
}
type EventFacts ¶
type FailureDefinition ¶
type FailureDefinition struct {
Type FailureType
ErrorCode string
Title string
Action string
}
func LookupFailure ¶
func LookupFailure(failureType FailureType) (FailureDefinition, bool)
type FailureType ¶
type FailureType string
const ( FailureConfigResolution FailureType = "sync.config_resolution.failed" FailureMetricsOpen FailureType = "sync.metrics.open.failed" FailureMetricsClose FailureType = "sync.metrics.close.failed" FailureStoreOpen FailureType = "sync.store.open.failed" FailureStoreClose FailureType = "sync.store.close.failed" FailureOptions FailureType = "sync.options.failed" FailureOutput FailureType = "sync.output.failed" FailureAppleNotesPermission FailureType = "sync.apple_notes.permission_denied" FailureUnknown FailureType = "sync.unknown" )
func KnownFailureTypes ¶
func KnownFailureTypes() []FailureType
func LookupSemanticFailure ¶
func LookupSemanticFailure(code string) (FailureType, bool)
func LookupStageFailure ¶
func LookupStageFailure(stage string) (FailureType, bool)
type Incident ¶
type Incident struct {
ID string `json:"id"`
Operation Operation `json:"operation"`
FailureType FailureType `json:"failure_type"`
Phase IncidentPhase `json:"phase"`
FirstSeenAt time.Time `json:"first_seen_at"`
LastSeenAt time.Time `json:"last_seen_at"`
Occurrences int `json:"occurrences"`
LastFailureEnqueuedAt time.Time `json:"last_failure_enqueued_at"`
NeedsRecovery bool `json:"needs_recovery"`
RecoveryNotifiedAt time.Time `json:"recovery_notified_at,omitempty"`
}
type IncidentPhase ¶
type IncidentPhase string
const ( IncidentOpen IncidentPhase = "open" IncidentCooling IncidentPhase = "cooling" )
type IncidentSnapshot ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func NewManager(options Options, store StateStore, providers []Provider, managerOptions ...ManagerOption) *Manager
type ManagerOption ¶
type ManagerOption func(*Manager)
func WithClock ¶
func WithClock(now func() time.Time) ManagerOption
func WithDeliveryTimeout ¶
func WithDeliveryTimeout(timeout time.Duration) ManagerOption
func WithManagerLogger ¶
func WithManagerLogger(log func(string)) ManagerOption
func WithMetricsEmitter ¶
func WithMetricsEmitter(emit func(metrics.Event) error) ManagerOption
type Notification ¶
type Notification struct {
ID string `json:"id"`
IncidentIDs []string `json:"incident_ids"`
Kind EventKind `json:"kind"`
Operation Operation `json:"operation"`
FailureTypes []FailureType `json:"failure_types"`
Title string `json:"title"`
Body string `json:"body"`
Occurrences int `json:"occurrences"`
FirstSeenAt time.Time `json:"first_seen_at"`
LastSeenAt time.Time `json:"last_seen_at"`
CreatedAt time.Time `json:"created_at"`
SuppressionAfter time.Duration `json:"suppression_after"`
}
func BuildFailureMessage ¶
func BuildFailureMessage(incident Incident, repeatAfter time.Duration) (Notification, error)
func BuildRecoveryMessage ¶
func BuildReminderMessage ¶
func BuildReminderMessage(incident Incident, repeatAfter time.Duration) (Notification, error)
func DeriveNotification ¶
func DeriveNotification(event EventFacts) (Notification, error)
type OpenIncidentStatus ¶
type Operation ¶
type Operation string
const OperationScheduledSyncAll Operation = "scheduled_sync_all"
type Outcome ¶
type Outcome struct {
Operation Operation `json:"operation"`
Status OutcomeStatus `json:"status"`
FailureType FailureType `json:"failure_type,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
StartedAt time.Time `json:"started_at"`
FinishedAt time.Time `json:"finished_at"`
}
type OutcomeStatus ¶
type OutcomeStatus string
const ( OutcomeSuccess OutcomeStatus = "success" OutcomeFailure OutcomeStatus = "failure" OutcomeCancelled OutcomeStatus = "cancelled" )
type ProviderStatus ¶
type ProviderStatus struct {
Name string `json:"name"`
Configured bool `json:"configured"`
LastStatus string `json:"last_status,omitempty"`
LastErrorCode string `json:"last_error_code,omitempty"`
LastAttemptAt *time.Time `json:"last_attempt_at,omitempty"`
LastAcceptedAt *time.Time `json:"last_accepted_at,omitempty"`
}
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func BuiltinRegistry ¶
func BuiltinRegistry() Registry
func NewRegistry ¶
func NewRegistry() Registry
type SlackConfig ¶
func LoadSlackConfig ¶
func LoadSlackConfig(rootDir string) (SlackConfig, error)
LoadSlackConfig loads and validates the Slack provider independently from the global notification kill switch. Webhook credentials remain typed references until a delivery attempt resolves them.
type State ¶
type State struct {
Schema string `json:"schema"`
Incidents map[string]Incident `json:"incidents"`
Outbox []Envelope `json:"outbox"`
// LastDelivery is retained only to decode v1 state. Canonical v2 state must
// leave it empty and use LastDeliveries instead.
LastDelivery DeliverySummary `json:"last_delivery,omitempty"`
LastDeliveries map[string]DeliverySummary `json:"last_deliveries"`
}
func EmptyState ¶
func EmptyState() State
type Status ¶
type Status struct {
Enabled bool `json:"enabled"`
RepeatAfter string `json:"repeat_after"`
Providers []ProviderStatus `json:"providers"`
OpenIncidents []OpenIncidentStatus `json:"open_incidents"`
CoolingIncidents []CoolingIncidentStatus `json:"cooling_incidents"`
PendingDeliveries int `json:"pending_deliveries"`
}