Documentation
¶
Index ¶
- Constants
- Variables
- func IDMutationTouchesManagedRoute(store Store, ids []string, allowedStates map[State]struct{}, ...) (bool, error)
- func SortRouteBacklogBuckets(buckets []RouteBacklogBucket)
- type AttemptListRequest
- type AttemptListResponse
- type AttemptOutcome
- type BacklogBucket
- type BacklogTrendListRequest
- type BacklogTrendListResponse
- type BacklogTrendOperatorAction
- type BacklogTrendSample
- type BacklogTrendSignalConfig
- type BacklogTrendSignalOptions
- type BacklogTrendSignals
- type BacklogTrendStore
- type BatchEnqueuer
- type ContextDequeuer
- type DeadDeleteRequest
- type DeadDeleteResponse
- type DeadListRequest
- type DeadListResponse
- type DeadRequeueRequest
- type DeadRequeueResponse
- type DeliveryAttempt
- type DequeueRequest
- type DequeueResponse
- type Envelope
- type HistogramBucket
- type HistogramSnapshot
- type LeaseBatchConflict
- type LeaseBatchResult
- type LeaseBatchStore
- type LeaseRouteResolver
- type MemoryOption
- func WithAttemptsRetention(maxAge time.Duration, maxRows int) MemoryOption
- func WithDLQRetention(maxAge time.Duration, maxDepth int) MemoryOption
- func WithDeliveredRetention(maxAge time.Duration) MemoryOption
- func WithMemoryPressureLimits(retainedItems int, retainedBytes int64) MemoryOption
- func WithNowFunc(now func() time.Time) MemoryOption
- func WithQueueLimits(maxDepth int, dropPolicy string) MemoryOption
- func WithQueueRetention(maxAge, pruneInterval time.Duration) MemoryOption
- type MemoryPressureRuntimeMetrics
- type MemoryRuntimeMetrics
- type MemoryStore
- func (s *MemoryStore) Ack(leaseID string) error
- func (s *MemoryStore) AckBatch(leaseIDs []string) (LeaseBatchResult, error)
- func (s *MemoryStore) CancelMessages(req MessageCancelRequest) (MessageCancelResponse, error)
- func (s *MemoryStore) CancelMessagesByFilter(req MessageManageFilterRequest) (MessageCancelResponse, error)
- func (s *MemoryStore) CaptureBacklogTrendSample(at time.Time) error
- func (s *MemoryStore) DeleteDead(req DeadDeleteRequest) (DeadDeleteResponse, error)
- func (s *MemoryStore) Dequeue(req DequeueRequest) (DequeueResponse, error)
- func (s *MemoryStore) DequeueContext(ctx context.Context, req DequeueRequest) (DequeueResponse, error)
- func (s *MemoryStore) Enqueue(env Envelope) error
- func (s *MemoryStore) EnqueueBatch(items []Envelope) (int, error)
- func (s *MemoryStore) Extend(leaseID string, extendBy time.Duration) error
- func (s *MemoryStore) LeaseRoutes(leaseIDs []string) (map[string]string, error)
- func (s *MemoryStore) ListAttempts(req AttemptListRequest) (AttemptListResponse, error)
- func (s *MemoryStore) ListBacklogTrend(req BacklogTrendListRequest) (BacklogTrendListResponse, error)
- func (s *MemoryStore) ListDead(req DeadListRequest) (DeadListResponse, error)
- func (s *MemoryStore) ListMessages(req MessageListRequest) (MessageListResponse, error)
- func (s *MemoryStore) LookupMessages(req MessageLookupRequest) (MessageLookupResponse, error)
- func (s *MemoryStore) MarkDead(leaseID string, reason string) error
- func (s *MemoryStore) MarkDeadBatch(leaseIDs []string, reason string) (LeaseBatchResult, error)
- func (s *MemoryStore) Nack(leaseID string, delay time.Duration) error
- func (s *MemoryStore) NackBatch(leaseIDs []string, delay time.Duration) (LeaseBatchResult, error)
- func (s *MemoryStore) NotifyCh() <-chan struct{}
- func (s *MemoryStore) RecordAttempt(attempt DeliveryAttempt) error
- func (s *MemoryStore) RequeueDead(req DeadRequeueRequest) (DeadRequeueResponse, error)
- func (s *MemoryStore) RequeueMessages(req MessageRequeueRequest) (MessageRequeueResponse, error)
- func (s *MemoryStore) RequeueMessagesByFilter(req MessageManageFilterRequest) (MessageRequeueResponse, error)
- func (s *MemoryStore) ResumeMessages(req MessageResumeRequest) (MessageResumeResponse, error)
- func (s *MemoryStore) ResumeMessagesByFilter(req MessageManageFilterRequest) (MessageResumeResponse, error)
- func (s *MemoryStore) RuntimeMetrics() StoreRuntimeMetrics
- func (s *MemoryStore) Stats() (Stats, error)
- type MessageCancelRequest
- type MessageCancelResponse
- type MessageListRequest
- type MessageListResponse
- type MessageLookupItem
- type MessageLookupRequest
- type MessageLookupResponse
- type MessageManageFilterRequest
- type MessageRequeueRequest
- type MessageRequeueResponse
- type MessageResumeRequest
- type MessageResumeResponse
- type RouteBacklogBucket
- type RuntimeMetricsProvider
- type SQLiteRuntimeMetrics
- type State
- type Stats
- type Store
- type StoreCommonRuntimeMetrics
- type StoreNotifier
- type StoreOperationCounterRuntimeMetric
- type StoreOperationDurationRuntimeMetric
- type StoreOperationErrorRuntimeMetric
- type StoreRuntimeMetrics
Constants ¶
const ( MessageOrderDesc = "desc" MessageOrderAsc = "asc" )
Variables ¶
Functions ¶
func IDMutationTouchesManagedRoute ¶
func IDMutationTouchesManagedRoute(store Store, ids []string, allowedStates map[State]struct{}, managedRoutes map[string]struct{}) (bool, error)
IDMutationTouchesManagedRoute reports whether the ID-scoped mutation request targets at least one managed route item in one of the allowed states.
func SortRouteBacklogBuckets ¶ added in v2.14.0
func SortRouteBacklogBuckets(buckets []RouteBacklogBucket)
SortRouteBacklogBuckets orders a backlog breakdown by route then target, the order Stats.Backlog is documented to carry.
Types ¶
type AttemptListRequest ¶
type AttemptListResponse ¶
type AttemptListResponse struct {
Items []DeliveryAttempt
}
type AttemptOutcome ¶
type AttemptOutcome string
const ( AttemptOutcomeAcked AttemptOutcome = "acked" AttemptOutcomeRetry AttemptOutcome = "retry" AttemptOutcomeDead AttemptOutcome = "dead" )
type BacklogBucket ¶
type BacklogBucket struct {
Route string
Target string
Queued int
OldestQueuedReceivedAt time.Time
EarliestQueuedNextRun time.Time
OldestQueuedAge time.Duration
ReadyLag time.Duration
}
func TopQueuedFromBacklog ¶ added in v2.14.0
func TopQueuedFromBacklog(buckets []RouteBacklogBucket, limit int) []BacklogBucket
TopQueuedFromBacklog reduces a complete backlog breakdown to the top-N buckets that hold queued items, ordered by queued count descending and then by route and target.
Deriving both views from one breakdown is also why the stores no longer run a separate top-N query: two queries can disagree about a route across a concurrent write, and Stats reports them side by side.
type BacklogTrendListRequest ¶
type BacklogTrendListResponse ¶
type BacklogTrendListResponse struct {
Items []BacklogTrendSample
Truncated bool
}
type BacklogTrendOperatorAction ¶
type BacklogTrendOperatorAction struct {
ID string
Severity string
AlertRoutingKey string
Summary string
Playbook string
Alerts []string
MCPTools []string
AdminEndpoints []string
}
func (BacklogTrendOperatorAction) Map ¶
func (a BacklogTrendOperatorAction) Map() map[string]any
type BacklogTrendSample ¶
type BacklogTrendSignalConfig ¶
type BacklogTrendSignalConfig struct {
Window time.Duration
ExpectedCaptureInterval time.Duration
StaleGraceFactor int
SustainedGrowthConsecutive int
SustainedGrowthMinSamples int
SustainedGrowthMinDelta int
RecentSurgeMinTotal int
RecentSurgeMinDelta int
RecentSurgePercent int
QueuedPressureMinTotal int
QueuedPressurePercent int
QueuedPressureLeasedMultiplier int
}
func DefaultBacklogTrendSignalConfig ¶
func DefaultBacklogTrendSignalConfig() BacklogTrendSignalConfig
type BacklogTrendSignals ¶
type BacklogTrendSignals struct {
Status string
Window time.Duration
ExpectedCaptureInterval time.Duration
Since time.Time
Until time.Time
SampleCount int
Truncated bool
LatestCapturedAt time.Time
LatestQueued int
LatestLeased int
LatestDead int
LatestTotal int
BaselineTotal int
DeltaTotal int
DeltaPercent int
GrowthRatePerMinute float64
ConsecutiveIncreases int
SustainedGrowth bool
RecentSurge bool
QueuedPressure bool
FreshnessSeconds int
SamplingStale bool
ActiveAlerts []string
}
func AnalyzeBacklogTrendSignals ¶
func AnalyzeBacklogTrendSignals(samples []BacklogTrendSample, truncated bool, opts BacklogTrendSignalOptions) BacklogTrendSignals
func (BacklogTrendSignals) Map ¶
func (s BacklogTrendSignals) Map() map[string]any
func (BacklogTrendSignals) OperatorActions ¶
func (s BacklogTrendSignals) OperatorActions() []BacklogTrendOperatorAction
type BacklogTrendStore ¶
type BacklogTrendStore interface {
CaptureBacklogTrendSample(at time.Time) error
ListBacklogTrend(req BacklogTrendListRequest) (BacklogTrendListResponse, error)
}
BacklogTrendStore is an optional extension implemented by stores that can persist and query backlog trend snapshots.
type BatchEnqueuer ¶
BatchEnqueuer is an optional extension for transactional batch enqueue. When supported, all items are committed atomically (all-or-nothing).
type ContextDequeuer ¶ added in v2.11.0
type ContextDequeuer interface {
DequeueContext(ctx context.Context, req DequeueRequest) (DequeueResponse, error)
}
ContextDequeuer is an optional extension for stores whose long-poll Dequeue can be abandoned when the caller's context is done.
Store.Dequeue takes no context, so a worker that gave up -- a gRPC client whose own deadline fired, an HTTP consumer that disconnected -- left the handler blocked inside the store for the rest of max_wait. Any items that arrived meanwhile were leased into a dead connection and stayed invisible for the whole lease TTL before the expiry sweep reclaimed them, turning each client timeout into a lease-TTL delivery delay.
type DeadDeleteRequest ¶
type DeadDeleteRequest struct {
IDs []string
}
type DeadDeleteResponse ¶
type DeadDeleteResponse struct {
Deleted int
}
type DeadListRequest ¶
type DeadListResponse ¶
type DeadListResponse struct {
Items []Envelope
}
type DeadRequeueRequest ¶
type DeadRequeueRequest struct {
IDs []string
}
type DeadRequeueResponse ¶
type DeadRequeueResponse struct {
Requeued int
}
type DeliveryAttempt ¶
type DequeueRequest ¶
type DequeueResponse ¶
type DequeueResponse struct {
Items []Envelope
}
type HistogramBucket ¶
type HistogramSnapshot ¶
type HistogramSnapshot struct {
Buckets []HistogramBucket
Count int64
Sum float64
}
type LeaseBatchConflict ¶
type LeaseBatchResult ¶
type LeaseBatchResult struct {
Succeeded int
Conflicts []LeaseBatchConflict
}
type LeaseBatchStore ¶
type LeaseBatchStore interface {
AckBatch(leaseIDs []string) (LeaseBatchResult, error)
NackBatch(leaseIDs []string, delay time.Duration) (LeaseBatchResult, error)
MarkDeadBatch(leaseIDs []string, reason string) (LeaseBatchResult, error)
}
LeaseBatchStore is an optional extension for batched lease operations. Implementations should process the whole batch in one store transaction where possible and return per-lease conflicts for not-found/expired leases.
type LeaseRouteResolver ¶ added in v2.11.0
type LeaseRouteResolver interface {
// LeaseRoutes maps each known lease ID to the route of the item it holds.
// Unknown leases are absent from the result rather than an error.
LeaseRoutes(leaseIDs []string) (map[string]string, error)
}
LeaseRouteResolver is an optional extension for stores that can report which route a lease belongs to.
It exists so route-scoped credentials can be enforced where the lease operations happen: Ack, Nack, MarkDead and Extend take only a lease ID, so a client authorized for one endpoint could settle another route's in-flight message if it learned that lease ID.
type MemoryOption ¶
type MemoryOption func(*MemoryStore)
func WithAttemptsRetention ¶ added in v2.11.0
func WithAttemptsRetention(maxAge time.Duration, maxRows int) MemoryOption
WithAttemptsRetention bounds the delivery-attempt history. Attempts were previously appended forever with no cap and no retention: a long-running instance delivering millions of webhooks accumulated millions of records -- hundreds of MB -- and the memory-pressure guard counts only envelope bytes, so the growth was invisible to the very mechanism meant to bound memory.
func WithDLQRetention ¶
func WithDLQRetention(maxAge time.Duration, maxDepth int) MemoryOption
func WithDeliveredRetention ¶
func WithDeliveredRetention(maxAge time.Duration) MemoryOption
func WithMemoryPressureLimits ¶
func WithMemoryPressureLimits(retainedItems int, retainedBytes int64) MemoryOption
WithMemoryPressureLimits overrides memory pressure limits for the in-memory backend. Positive values enable explicit thresholds.
func WithNowFunc ¶
func WithNowFunc(now func() time.Time) MemoryOption
func WithQueueLimits ¶
func WithQueueLimits(maxDepth int, dropPolicy string) MemoryOption
func WithQueueRetention ¶
func WithQueueRetention(maxAge, pruneInterval time.Duration) MemoryOption
type MemoryRuntimeMetrics ¶
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
func NewMemoryStore ¶
func NewMemoryStore(opts ...MemoryOption) *MemoryStore
func (*MemoryStore) Ack ¶
func (s *MemoryStore) Ack(leaseID string) error
func (*MemoryStore) AckBatch ¶
func (s *MemoryStore) AckBatch(leaseIDs []string) (LeaseBatchResult, error)
func (*MemoryStore) CancelMessages ¶
func (s *MemoryStore) CancelMessages(req MessageCancelRequest) (MessageCancelResponse, error)
func (*MemoryStore) CancelMessagesByFilter ¶
func (s *MemoryStore) CancelMessagesByFilter(req MessageManageFilterRequest) (MessageCancelResponse, error)
func (*MemoryStore) CaptureBacklogTrendSample ¶
func (s *MemoryStore) CaptureBacklogTrendSample(at time.Time) error
func (*MemoryStore) DeleteDead ¶
func (s *MemoryStore) DeleteDead(req DeadDeleteRequest) (DeadDeleteResponse, error)
func (*MemoryStore) Dequeue ¶
func (s *MemoryStore) Dequeue(req DequeueRequest) (DequeueResponse, error)
func (*MemoryStore) DequeueContext ¶ added in v2.11.0
func (s *MemoryStore) DequeueContext(ctx context.Context, req DequeueRequest) (DequeueResponse, error)
DequeueContext is Dequeue with the caller's context honoured: a consumer that has gone away neither keeps a goroutine parked for the rest of max_wait nor receives a lease it can never settle.
func (*MemoryStore) Enqueue ¶
func (s *MemoryStore) Enqueue(env Envelope) error
func (*MemoryStore) EnqueueBatch ¶
func (s *MemoryStore) EnqueueBatch(items []Envelope) (int, error)
EnqueueBatch atomically enqueues all items or none (all-or-nothing). Returns the number of items enqueued (0 or len(items)) and an error.
func (*MemoryStore) Extend ¶
func (s *MemoryStore) Extend(leaseID string, extendBy time.Duration) error
func (*MemoryStore) LeaseRoutes ¶ added in v2.11.0
func (s *MemoryStore) LeaseRoutes(leaseIDs []string) (map[string]string, error)
LeaseRoutes reports the route each known lease belongs to.
func (*MemoryStore) ListAttempts ¶
func (s *MemoryStore) ListAttempts(req AttemptListRequest) (AttemptListResponse, error)
func (*MemoryStore) ListBacklogTrend ¶
func (s *MemoryStore) ListBacklogTrend(req BacklogTrendListRequest) (BacklogTrendListResponse, error)
func (*MemoryStore) ListDead ¶
func (s *MemoryStore) ListDead(req DeadListRequest) (DeadListResponse, error)
func (*MemoryStore) ListMessages ¶
func (s *MemoryStore) ListMessages(req MessageListRequest) (MessageListResponse, error)
func (*MemoryStore) LookupMessages ¶
func (s *MemoryStore) LookupMessages(req MessageLookupRequest) (MessageLookupResponse, error)
func (*MemoryStore) MarkDeadBatch ¶
func (s *MemoryStore) MarkDeadBatch(leaseIDs []string, reason string) (LeaseBatchResult, error)
func (*MemoryStore) NackBatch ¶
func (s *MemoryStore) NackBatch(leaseIDs []string, delay time.Duration) (LeaseBatchResult, error)
func (*MemoryStore) NotifyCh ¶
func (s *MemoryStore) NotifyCh() <-chan struct{}
NotifyCh returns a channel that is closed when new items become available. After the channel fires, callers must call NotifyCh again to get the next signal.
func (*MemoryStore) RecordAttempt ¶
func (s *MemoryStore) RecordAttempt(attempt DeliveryAttempt) error
func (*MemoryStore) RequeueDead ¶
func (s *MemoryStore) RequeueDead(req DeadRequeueRequest) (DeadRequeueResponse, error)
func (*MemoryStore) RequeueMessages ¶
func (s *MemoryStore) RequeueMessages(req MessageRequeueRequest) (MessageRequeueResponse, error)
func (*MemoryStore) RequeueMessagesByFilter ¶
func (s *MemoryStore) RequeueMessagesByFilter(req MessageManageFilterRequest) (MessageRequeueResponse, error)
func (*MemoryStore) ResumeMessages ¶
func (s *MemoryStore) ResumeMessages(req MessageResumeRequest) (MessageResumeResponse, error)
func (*MemoryStore) ResumeMessagesByFilter ¶
func (s *MemoryStore) ResumeMessagesByFilter(req MessageManageFilterRequest) (MessageResumeResponse, error)
func (*MemoryStore) RuntimeMetrics ¶
func (s *MemoryStore) RuntimeMetrics() StoreRuntimeMetrics
func (*MemoryStore) Stats ¶
func (s *MemoryStore) Stats() (Stats, error)
type MessageCancelRequest ¶
type MessageCancelRequest struct {
IDs []string
}
type MessageCancelResponse ¶
type MessageListRequest ¶
type MessageListResponse ¶
type MessageListResponse struct {
Items []Envelope
}
type MessageLookupItem ¶
type MessageLookupRequest ¶
type MessageLookupRequest struct {
IDs []string
}
type MessageLookupResponse ¶
type MessageLookupResponse struct {
Items []MessageLookupItem
}
type MessageRequeueRequest ¶
type MessageRequeueRequest struct {
IDs []string
}
type MessageRequeueResponse ¶
type MessageResumeRequest ¶
type MessageResumeRequest struct {
IDs []string
}
type MessageResumeResponse ¶
type RouteBacklogBucket ¶ added in v2.14.0
type RouteBacklogBucket struct {
Route string
Target string
Queued int
Leased int
Dead int
OldestQueuedReceivedAt time.Time
EarliestQueuedNextRun time.Time
OldestQueuedAge time.Duration
ReadyLag time.Duration
}
RouteBacklogBucket is one (route, target) pair's backlog across the states a depth gauge reports.
It exists because TopQueued is a top-N cut: a low-volume route whose consumer went away sits below the cut behind any busy route, so its backlog had no series of its own, and its items were numerically invisible inside the instance-global aggregates. This breakdown is complete -- every pair holding at least one queued, leased or dead item -- so per-route depth and age can be reported without that blind spot. Cardinality stays bounded by the configured routes and their targets.
type RuntimeMetricsProvider ¶
type RuntimeMetricsProvider interface {
RuntimeMetrics() StoreRuntimeMetrics
}
type SQLiteRuntimeMetrics ¶
type SQLiteRuntimeMetrics struct {
WriteDurationSeconds HistogramSnapshot
DequeueDurationSeconds HistogramSnapshot
CheckpointDurationSeconds HistogramSnapshot
BusyTotal int64
RetryTotal int64
TxCommitTotal int64
TxRollbackTotal int64
CheckpointTotal int64
CheckpointErrorTotal int64
}
type Stats ¶
type Stats struct {
Total int
ByState map[State]int
OldestQueuedReceivedAt time.Time
EarliestQueuedNextRun time.Time
OldestQueuedAge time.Duration
ReadyLag time.Duration
TopQueued []BacklogBucket
// Backlog is the complete per-(route, target) breakdown, ordered by route
// then target. Unlike TopQueued it is never truncated.
Backlog []RouteBacklogBucket
}
type Store ¶
type Store interface {
Enqueue(env Envelope) error
Dequeue(req DequeueRequest) (DequeueResponse, error)
Ack(leaseID string) error
Nack(leaseID string, delay time.Duration) error
Extend(leaseID string, extendBy time.Duration) error
MarkDead(leaseID string, reason string) error
ListDead(req DeadListRequest) (DeadListResponse, error)
RequeueDead(req DeadRequeueRequest) (DeadRequeueResponse, error)
DeleteDead(req DeadDeleteRequest) (DeadDeleteResponse, error)
ListMessages(req MessageListRequest) (MessageListResponse, error)
LookupMessages(req MessageLookupRequest) (MessageLookupResponse, error)
CancelMessages(req MessageCancelRequest) (MessageCancelResponse, error)
RequeueMessages(req MessageRequeueRequest) (MessageRequeueResponse, error)
ResumeMessages(req MessageResumeRequest) (MessageResumeResponse, error)
CancelMessagesByFilter(req MessageManageFilterRequest) (MessageCancelResponse, error)
RequeueMessagesByFilter(req MessageManageFilterRequest) (MessageRequeueResponse, error)
ResumeMessagesByFilter(req MessageManageFilterRequest) (MessageResumeResponse, error)
Stats() (Stats, error)
RecordAttempt(attempt DeliveryAttempt) error
ListAttempts(req AttemptListRequest) (AttemptListResponse, error)
}
type StoreCommonRuntimeMetrics ¶
type StoreCommonRuntimeMetrics struct {
OperationDurationSeconds []StoreOperationDurationRuntimeMetric
OperationTotal []StoreOperationCounterRuntimeMetric
ErrorsTotal []StoreOperationErrorRuntimeMetric
}
type StoreNotifier ¶
type StoreNotifier interface {
NotifyCh() <-chan struct{}
}
StoreNotifier is an optional extension for stores that support event-driven notification when new items become available. The returned channel is closed when one or more items are enqueued, after which a fresh channel must be obtained by calling NotifyCh again.
type StoreOperationDurationRuntimeMetric ¶
type StoreOperationDurationRuntimeMetric struct {
Operation string
DurationSeconds HistogramSnapshot
}
type StoreRuntimeMetrics ¶
type StoreRuntimeMetrics struct {
Backend string
Common StoreCommonRuntimeMetrics
SQLite *SQLiteRuntimeMetrics
Memory *MemoryRuntimeMetrics
}