Documentation
¶
Overview ¶
Package sinks holds the use cases of a project's sinks: the resource a maintainer creates, reads, edits and deletes, whose credentials are sealed and never read back.
Index ¶
- Constants
- Variables
- type AtRiskDeps
- type AtRiskStore
- type AuditLog
- type BatchToSend
- type Call
- type Claim
- type ClaimLimit
- type ClaimedSink
- type Create
- type CreateCommand
- type Created
- type DeadLetterCommand
- type DeadLetterStore
- type Delete
- type DeleteCommand
- type Deliver
- func (h *Deliver) Abandon(ctx context.Context, token LeaseToken, c ClaimedSink) error
- func (h *Deliver) AttemptSink(ctx context.Context, token LeaseToken, c ClaimedSink) (map[sinks.EventKind]Result, error)
- func (h *Deliver) Claim(ctx context.Context, busy []sinks.ID, limit ClaimLimit) (Claim, error)
- type DeliverDeps
- type DeliveryStore
- type Deps
- type DiscardDeadLetter
- type DismissGap
- type DismissGapCommand
- type Due
- type Enable
- type EnableCommand
- type EvaluateAtRisk
- type GapRows
- type GapStore
- type GapStream
- type GetSink
- type Inflight
- type Lease
- type LeaseToken
- type ListDeadLetters
- type ListGaps
- type ListSinks
- type NewDeadLetter
- type Observer
- type Opener
- type Probed
- type RedeliverDeadLetter
- type Renewal
- type Replay
- type ReplayCommand
- type Resolver
- type Result
- type ResumeCommand
- type ResumeSink
- type Retention
- type RetentionDeps
- type RotateCommand
- type RotateSecret
- type Rows
- type Sample
- type SampleCommand
- type Sampled
- type Sealer
- type SetAsideResult
- type Store
- type StreamRef
- type Target
- type Targets
- type Test
- type TestCommand
- type TestConfig
- type TestConfigCommand
- type Tested
- type Transactor
- type Update
- type UpdateCommand
Constants ¶
const ( ResultAck = "ack" ResultTransient = "transient" ResultRejected = "rejected" // ResultDeadLettered counts the batch a rejection set aside, beside the // rejection itself. ResultDeadLettered = "dead_lettered" // ResultRedelivered and ResultRedeliveryFailed count a dead letter sent // again, acknowledged or not. ResultRedelivered = "redelivered" ResultRedeliveryFailed = "redelivery_failed" )
The results of a batch, as the metric counts them.
const AtRiskEvery = time.Minute
AtRiskEvery is how seldom a sink is judged for being at risk: it takes a query per stream, and a sink falls behind retention over days.
const LeaseDuration = 5 * time.Minute
LeaseDuration is how long a claimed stream stays claimed. It is renewed immediately before each attempt, so it only has to outlast the longest attempt: a replica that dies mid-attempt leaves its stream to the next claim once it runs out.
const SkipEnvironmentDeleted = "environment_deleted"
SkipEnvironmentDeleted is the reason a row is skipped when its environment was deleted: the key it would be exported under is gone with it.
Variables ¶
var ( // ErrDeadLetterNotFound answers a dead letter the sink does not have. ErrDeadLetterNotFound = apperrors.NotFound("not_found", "the sink has no dead letter with this identifier") )
var ErrGapNotFound = apperrors.NotFound("not_found", "the sink has no gap with this identifier")
ErrGapNotFound answers a gap the sink does not have.
var ErrHalted = errors.New("the sink was disabled or stopped")
ErrHalted answers a batch that may not begin because its sink was disabled or stopped since the stream was claimed.
var ErrNotFound = errors.New("sinks: not found")
ErrNotFound is what a store answers for a row it does not have.
var ( // ErrSinkNotFound answers a sink the project does not have. ErrSinkNotFound = apperrors.NotFound("not_found", "the project has no sink with this identifier") )
Functions ¶
This section is empty.
Types ¶
type AtRiskDeps ¶ added in v0.4.0
type AtRiskDeps struct {
Tx Transactor
Store AtRiskStore
Rows Rows
Audit AuditLog
Clock clock.Clock
IDs *id.Source
// Retention is how long raw events are kept, and LossWarning how long
// before a row is dropped a sink still undelivered is at risk.
Retention, LossWarning time.Duration
}
AtRiskDeps are what judging the sinks runs on.
type AtRiskStore ¶ added in v0.4.0
type AtRiskStore interface {
// LockProject locks project's row for the unit of work, or answers
// ErrNotFound when there is none; it comes before the sink's own rows.
LockProject(ctx context.Context, project workspace.ProjectID) error
// Tracked returns every sink that has a stream or is marked at risk,
// with its streams, whatever its state: a disabled or stopped sink loses
// rows to retention too.
Tracked(ctx context.Context) ([]sinks.Sink, error)
// EnterAtRisk marks sink at risk since now and reports whether it was
// not already, so that only one of the replicas judging it at once tells
// of the episode.
EnterAtRisk(ctx context.Context, sink sinks.ID, now time.Time) (entered bool, err error)
// LeaveAtRisk clears the mark.
LeaveAtRisk(ctx context.Context, sink sinks.ID) error
}
AtRiskStore keeps which sinks are at risk.
type AuditLog ¶
type AuditLog interface {
Record(ctx context.Context, e governance.Entry) error
}
AuditLog records the audit entry of a change, in the unit of work of the change.
type BatchToSend ¶ added in v0.7.0
type BatchToSend struct {
// ID is the delivery's identity to the target, the same on every resend.
ID string
Kind sinks.EventKind
Rows []sinks.Row
// Sample says the rows are a sample, not events.
Sample bool
// Test says there are no rows: the call only shows the target answers.
Test bool
Now time.Time
}
BatchToSend is one batch to send to a target: the rows of a batch in flight, a sample or a test call. Not a delivery, which is a webhook subscription's.
type Call ¶
type Call struct {
Sink sinks.Sink
// ProjectKey is the key of the sink's project.
ProjectKey string
// Secrets are the secrets that sign or authenticate the call, opened: the
// sink's, then the one a rotation replaced while its overlap lasts.
Secrets []string
}
Call is what a target is called with.
type Claim ¶
type Claim struct {
Token LeaseToken
Sinks []ClaimedSink
}
Claim is what one round of claiming leased.
type ClaimLimit ¶ added in v0.7.0
type ClaimLimit struct {
// Sinks is how many sinks the claim may take: the replica's free slots.
Sinks int
// PerProject is how many sinks of one project the replica holds at most,
// those it is attempting now included.
PerProject int
}
ClaimLimit bounds what one claim leases, in sinks, because a replica attempts sinks, not streams: whatever it leases and cannot start stays leased away from the other replicas until the lease runs out.
type ClaimedSink ¶
ClaimedSink is a sink with the leased streams of it that are due, which are attempted one after another.
type Create ¶
type Create struct {
// contains filtered or unexported fields
}
Create creates a sink.
type CreateCommand ¶
type CreateCommand struct {
Project workspace.ProjectID
Draft sinks.Draft
// CreatedBy is the member or project token asking, nil for neither.
CreatedBy *governance.Author
Request governance.Request
}
CreateCommand asks for a sink of Project.
type Created ¶
Created is a sink just made or just given a new secret. Secret is the webhook sink's secret, shown this once; it is zero for the other kinds, whose secret the member supplied.
type DeadLetterCommand ¶
type DeadLetterCommand struct {
Project workspace.ProjectID
Sink sinks.ID
DeadLetter sinks.DeadLetterID
Request governance.Request
}
DeadLetterCommand names a dead letter of the sink Sink of Project.
type DeadLetterStore ¶
type DeadLetterStore interface {
// DeadLetters returns sink's dead letters, the oldest first.
DeadLetters(ctx context.Context, sink sinks.ID) ([]sinks.DeadLetter, error)
// DeadLetter returns sink's dead letter with dl, or ErrNotFound.
DeadLetter(ctx context.Context, sink sinks.ID, dl sinks.DeadLetterID) (sinks.DeadLetter, error)
// RecordRedelivery records a redelivery of dl: one more attempt, and
// either the failure that ended it or, when the target acknowledged it,
// that it is redelivered at now. It returns the dead letter as it is.
RecordRedelivery(ctx context.Context, sink sinks.ID, dl sinks.DeadLetterID, failure *sinks.FailureAt, now time.Time) (sinks.DeadLetter, error)
// DiscardDeadLetter deletes sink's dead letter dl; one gone already is left
// gone.
DiscardDeadLetter(ctx context.Context, sink sinks.ID, dl sinks.DeadLetterID) error
// Resume clears sink's stop and each of its streams' run of dead letters
// and makes the streams due at now at the latest; it reports when the sink
// had been stopped, nil when it had not and nothing was done.
Resume(ctx context.Context, sink sinks.ID, now time.Time) (stoppedAt *time.Time, err error)
}
DeadLetterStore keeps a sink's dead letters. Setting a batch aside is the delivery store's, since it is one step with moving the stream on.
type Delete ¶
type Delete struct {
// contains filtered or unexported fields
}
Delete deletes a sink.
type DeleteCommand ¶
type DeleteCommand struct {
Project workspace.ProjectID
Sink sinks.ID
Expected precondition.Version
Request governance.Request
}
DeleteCommand asks for the sink Sink of Project to go, based on its version Expected.
type Deliver ¶
type Deliver struct {
// contains filtered or unexported fields
}
Deliver attempts the streams that are due.
func (*Deliver) Abandon ¶ added in v0.7.0
func (h *Deliver) Abandon(ctx context.Context, token LeaseToken, c ClaimedSink) error
Abandon gives back the leases of the streams of c, a claimed sink that never started, so that another replica attempts them at once instead of after the lease runs out. It runs on its own context: it is called when the one of the claim is cancelled. A stream whose lease is gone is left alone.
func (*Deliver) AttemptSink ¶
func (h *Deliver) AttemptSink(ctx context.Context, token LeaseToken, c ClaimedSink) (map[sinks.EventKind]Result, error)
AttemptSink attempts the streams of c one after another, so that a stop one of them brings about holds back the others, and returns the result of each, with every error met. A stream that fails to attempt does not stop the rest: its lease runs out and it is attempted again.
type DeliverDeps ¶
type DeliverDeps struct {
Tx Transactor
Store DeliveryStore
Rows Rows
Targets Targets
Opener Opener
Audit AuditLog
Clock clock.Clock
IDs *id.Source
Observer Observer
// Random returns a number in [0, 1), the spread of the backoff.
Random func() float64
// RejectionAttempts is how many times the target must reject a batch for
// it to be set aside as a dead letter, and StopAfterDeadLetters how many
// dead letters in a row on one stream stop the sink.
RejectionAttempts, StopAfterDeadLetters int
}
DeliverDeps are what the delivery worker runs on.
type DeliveryStore ¶
type DeliveryStore interface {
// LockProject locks project's row for the unit of work, or answers
// ErrNotFound when there is none. Every write of a project's sinks takes
// it before the sink's own rows, so recording a failure takes it first
// too.
LockProject(ctx context.Context, project workspace.ProjectID) error
// Claim leases to token, until until, the streams due by now of sinks
// that are enabled or still have a batch in flight and are not stopped,
// leaving out those of the sinks busy and of sinks another replica holds a
// stream of, the longest due first, at most limit sinks and all the due
// streams of each. A replay a stream has waiting is applied as it is
// leased: its cursor is the position the replay set.
Claim(ctx context.Context, token LeaseToken, now, until time.Time, limit ClaimLimit, busy []sinks.ID) ([]ClaimedSink, error)
// Renew pushes the lease token holds on stream out to until and reports
// the state of its sink.
Renew(ctx context.Context, stream StreamRef, token LeaseToken, until time.Time) (Renewal, error)
// Begin commits the batch to deliver next of stream, as in flight, while
// its sink is enabled and not stopped; ErrHalted otherwise. held is false
// when the lease is gone.
Begin(ctx context.Context, stream StreamRef, token LeaseToken, in Inflight) (held bool, err error)
// Ack moves stream's cursor to to, clears its batch in flight and its
// failures, ends its run of dead letters when it delivered rows (passing
// rows of other projects is no delivery), counts delivered rows and
// schedules its next attempt for next, releasing the lease. A bounded
// replay that to reaches the end of is over: the cursor goes to where
// the replay returns to instead.
Ack(ctx context.Context, stream StreamRef, token LeaseToken, to events.Cursor, delivered int, next, now time.Time) (held bool, err error)
// Fail records a failed attempt of stream: one more consecutive failure,
// the failure, a rejection counted when rejected, the next attempt at
// next, the lease released. entered is true when this is the sink's first
// failing stream, which begins an episode.
Fail(ctx context.Context, stream StreamRef, token LeaseToken, f sinks.Failure, rejected bool, next, now time.Time) (held, entered bool, err error)
// SetAside sets the batch in flight of stream aside as the dead letter dl,
// in the same unit of work: the cursor moves to the batch's end, the batch
// and the stream's failures are cleared, its run of dead letters grows by
// one and the stream is due at now. When that run reaches stopAfter the
// sink is stopped, if it is not already. The lease is released.
SetAside(ctx context.Context, stream StreamRef, token LeaseToken, dl NewDeadLetter, stopAfter int, now time.Time) (SetAsideResult, error)
// Idle releases stream's lease with nothing to send, to be attempted
// again at next.
Idle(ctx context.Context, stream StreamRef, token LeaseToken, next time.Time) (held bool, err error)
// Release gives up stream's lease without an attempt, leaving everything
// else as it was.
Release(ctx context.Context, stream StreamRef, token LeaseToken) (held bool, err error)
}
DeliveryStore is what the delivery worker reads and writes of streams. Every write names the token of the lease and applies only while it holds, and reports whether it did: a replica whose lease was taken records nothing.
type Deps ¶
type Deps struct {
Tx Transactor
Store Store
Audit AuditLog
Clock clock.Clock
IDs *id.Source
Random io.Reader
Sealer Sealer
Resolver Resolver
// TargetPolicy is what the operator allows a webhook sink's target to be.
TargetPolicy governance.TargetPolicy
// SecretOverlap is how long a rotated webhook secret signs beside the
// new one.
SecretOverlap time.Duration
// Rows, Targets and Opener serve enabling and testing a sink: the
// positions its streams start at, the target it is checked against, and
// its secrets.
Rows Rows
Targets Targets
Opener Opener
// DeadLetters keeps the sinks' dead letters, Gaps the rows retention
// dropped before they were delivered, and Observer is told what became of
// a redelivery.
DeadLetters DeadLetterStore
Gaps GapStore
Observer Observer
// LagWarning is how old the oldest undelivered row may be before a sink
// is lagging.
LagWarning time.Duration
// Retention is how long raw events are kept, which a sink cannot start
// further back than.
Retention time.Duration
}
Deps are what the sink use cases run on.
type DiscardDeadLetter ¶
type DiscardDeadLetter struct {
// contains filtered or unexported fields
}
DiscardDeadLetter gives a dead letter up.
func NewDiscardDeadLetter ¶
func NewDiscardDeadLetter(d Deps) *DiscardDeadLetter
NewDiscardDeadLetter returns the handler.
func (*DiscardDeadLetter) Handle ¶
func (h *DiscardDeadLetter) Handle(ctx context.Context, cmd DeadLetterCommand) error
Handle deletes the dead letter, whatever its status, and records sink.dead_letter_discarded.
type DismissGap ¶ added in v0.4.0
type DismissGap struct {
// contains filtered or unexported fields
}
DismissGap marks a gap as seen.
func NewDismissGap ¶ added in v0.4.0
func NewDismissGap(d Deps) *DismissGap
NewDismissGap returns the handler.
func (*DismissGap) Handle ¶ added in v0.4.0
func (h *DismissGap) Handle(ctx context.Context, cmd DismissGapCommand) (sinks.Gap, error)
Handle dismisses the gap and records sink.gap_dismissed. A gap dismissed already is answered as it is, with its first time, and nothing is recorded.
type DismissGapCommand ¶ added in v0.4.0
type DismissGapCommand struct {
Project workspace.ProjectID
Sink sinks.ID
Gap sinks.GapID
Request governance.Request
}
DismissGapCommand asks for the gap Gap of the sink Sink of Project to be dismissed.
type Due ¶
type Due struct {
Stream sinks.Stream
// Inflight is the batch committed before the last send; nil when the
// stream has none.
Inflight *Inflight
// Rejections is how many times the target rejected the batch in flight.
Rejections int
}
Due is a stream a replica leased, as an attempt needs it.
type Enable ¶
type Enable struct {
// contains filtered or unexported fields
}
Enable enables a sink.
func (*Enable) Handle ¶
Handle probes the sink's target, refusing with sink_not_ready and the failure when it cannot take a batch, creates the streams the sink lacks at the position its start asks for, and records sink.enabled. A sink that is already enabled is answered as it is: nothing is probed or recorded. Only the streams this creates start at StartFrom; one the sink already has keeps its cursor, so enabling a sink again continues where it stopped.
type EnableCommand ¶
type EnableCommand struct {
Project workspace.ProjectID
Sink sinks.ID
// StartFrom is when the streams this enable creates start reading, a
// time still within retention; nil to start from now.
StartFrom *time.Time
Request governance.Request
}
EnableCommand asks for the sink Sink of Project to start delivering.
type EvaluateAtRisk ¶ added in v0.4.0
type EvaluateAtRisk struct {
// contains filtered or unexported fields
}
EvaluateAtRisk judges whether sinks are about to lose events to retention.
func NewEvaluateAtRisk ¶ added in v0.4.0
func NewEvaluateAtRisk(d AtRiskDeps) *EvaluateAtRisk
NewEvaluateAtRisk returns the use case.
func (*EvaluateAtRisk) Handle ¶ added in v0.4.0
func (h *EvaluateAtRisk) Handle(ctx context.Context) error
Handle judges every sink not judged in the last AtRiskEvery: one whose oldest undelivered row is within the loss warning of retention's edge enters being at risk, once, with the audit entry the event is derived from; one that is no longer leaves. A sink that cannot be judged does not hold back the others; the errors are returned together.
type GapRows ¶ added in v0.4.0
type GapRows interface {
// Scope resolves the environments a sink names, as Rows does.
Scope(ctx context.Context, project workspace.ProjectID, keys []string) (scope sinks.Scope, ok bool, err error)
// Lost returns what the partitions of days of kind's rows hold past from
// in scope.
Lost(ctx context.Context, kind sinks.EventKind, scope sinks.Scope, days []time.Time, from events.Cursor) (events.Lost, error)
// FirstStored returns the first row of kind in scope past from outside
// the partitions of days, nil when there is none.
FirstStored(ctx context.Context, kind sinks.EventKind, scope sinks.Scope, days []time.Time, from events.Cursor) (*events.Cursor, error)
}
GapRows reads the rows a drop takes from a stream.
type GapStore ¶ added in v0.4.0
type GapStore interface {
// LockStreams holds every stream of kind until the unit of work ends,
// the streams of disabled and stopped sinks included.
LockStreams(ctx context.Context, kind sinks.EventKind) error
// GapStreams returns every stream of kind with its sink.
GapStreams(ctx context.Context, kind sinks.EventKind) ([]GapStream, error)
// RecordGap saves gap as the gap of sink's stream of kind and moves the
// stream's live position, the position a replay returns to when
// replaying is set and the cursor when not, to gap.Moved, dropping its
// batch in flight and its lease.
RecordGap(ctx context.Context, sink sinks.ID, kind sinks.EventKind, replaying bool, gap events.Gap) error
// ExpireDeadLetters expires the pending dead letters of kind none of
// whose rows is stored at or after before.
ExpireDeadLetters(ctx context.Context, kind sinks.EventKind, before time.Time) error
// PurgeDeadLetters deletes the dead letters of kind that are settled:
// redelivered before redelivered, or expired and created before expired.
// A pending one is never deleted.
PurgeDeadLetters(ctx context.Context, kind sinks.EventKind, redelivered, expired time.Time) error
// Gaps returns sink's gaps, the oldest first.
Gaps(ctx context.Context, sink sinks.ID) ([]sinks.Gap, error)
// Dismiss marks sink's gap dismissed at now, keeping the first time of
// one dismissed already; first says whether this call dismissed it.
// ErrNotFound when the sink has no such gap.
Dismiss(ctx context.Context, sink sinks.ID, gap sinks.GapID, now time.Time) (gap2 sinks.Gap, first bool, err error)
}
GapStore keeps the gaps retention leaves in the sinks' streams.
type GapStream ¶ added in v0.4.0
GapStream is a stream a drop of rows concerns, with the sink it belongs to: its identity, project, name, kind and environments.
type GetSink ¶
type GetSink struct {
// contains filtered or unexported fields
}
GetSink answers one sink.
type Inflight ¶
type Inflight struct {
To events.Cursor
Environments []workspace.EnvironmentID
}
Inflight is the batch a stream is delivering: its upper bound and the environments it was filtered to, committed before the first send so that every retry, on any replica, re-reads exactly the same rows.
type LeaseToken ¶
LeaseToken names one claim of a replica on the streams it leased, so that a replica whose lease ran out finds out the stream is no longer its own.
type ListDeadLetters ¶
type ListDeadLetters struct {
// contains filtered or unexported fields
}
ListDeadLetters answers a sink's dead letters.
func NewListDeadLetters ¶
func NewListDeadLetters(d Deps) *ListDeadLetters
NewListDeadLetters returns the query.
type ListGaps ¶ added in v0.4.0
type ListGaps struct {
// contains filtered or unexported fields
}
ListGaps answers a sink's gaps.
func NewListGaps ¶ added in v0.4.0
NewListGaps returns the query.
type ListSinks ¶
type ListSinks struct {
// contains filtered or unexported fields
}
ListSinks answers a project's sinks.
type NewDeadLetter ¶
type NewDeadLetter struct {
ID sinks.DeadLetterID
// Failure is the rejection that set the batch aside.
Failure sinks.FailureAt
// Rows is how many rows the batch held, and First and Last when the first
// and the last of the rows sent were received.
Rows int
First, Last time.Time
// Floor is the floor the batch was read with, which a redelivery reads
// its rows with again; nil when there was none.
Floor *time.Time
}
NewDeadLetter is the batch in flight of a stream, rejected for the last time, as it is set aside.
type Observer ¶
type Observer interface {
Batch(sink sinks.ID, kind sinks.EventKind, result string)
Lag(sink sinks.ID, kind sinks.EventKind, lag time.Duration)
RowsSkipped(reason string, n int)
}
Observer is told what the delivery makes visible beside the streams: what became of each batch, how far behind each stream is, and rows passed over.
type Opener ¶
type Opener interface {
Open(purpose secret.Purpose, sealed string, binding secret.Binding) ([]byte, error)
}
Opener opens a value sealed under the instance's secret key.
type Probed ¶
type Probed struct {
// Failure is why the target cannot be delivered to; nil when it can.
Failure *sinks.Failure
// Warnings are what is wrong with it that does not stop delivery.
Warnings []string
}
Probed is what checking a target found.
type RedeliverDeadLetter ¶
type RedeliverDeadLetter struct {
// contains filtered or unexported fields
}
RedeliverDeadLetter sends a dead letter's rows again.
func NewRedeliverDeadLetter ¶
func NewRedeliverDeadLetter(d Deps) *RedeliverDeadLetter
NewRedeliverDeadLetter returns the handler.
func (*RedeliverDeadLetter) Handle ¶
func (h *RedeliverDeadLetter) Handle(ctx context.Context, cmd DeadLetterCommand) (sinks.DeadLetter, error)
Handle reads the rows of the dead letter that are still stored and sends them to the target now, under a delivery ID of this attempt, outside the stream: its cursor, failures and health are not touched. The target's acknowledgement makes the dead letter redelivered; its failure leaves it as it was, with one more attempt and the failure. Either is recorded as sink.dead_letter_redelivered. When no row is stored any more it is refused rows_expired and nothing is sent.
type Renewal ¶
type Renewal struct {
// Held is false when the lease ran out and another replica holds the
// stream, or the stream is gone; nothing else is then known.
Held bool
// Enabled and Stopped are the sink's state now.
Enabled, Stopped bool
}
Renewal is what a stream's state was when its lease was renewed.
type Replay ¶
type Replay struct {
// contains filtered or unexported fields
}
Replay sends a sink's history again.
func (*Replay) Handle ¶
Handle sets each stream asked for back to just before the first event received at or after From, to stop after the last one received at or before To and return to where it was, or to run on into the live stream. The delivery worker applies it before the stream's next batch; the batch in flight and the lease are dropped now, so that a send already under way records nothing over it. A stream with no event in the range is left as it is. It records sink.replayed and answers the sink.
The events are searched for before the project is locked: the search scans the raw tables for as far back as From goes and reads only committed rows, so it needs no lock, and holding the project's lock for it would hold up every write of the project, the kill switch included. The lock is taken to plan against the streams' positions as they are then; a sink edited between the search and the lock is searched for again.
type ReplayCommand ¶
type ReplayCommand struct {
Project workspace.ProjectID
Sink sinks.ID
From time.Time
To *time.Time
// Kinds are the event kinds to replay; none for every kind the sink
// exports.
Kinds []sinks.EventKind
Request governance.Request
}
ReplayCommand asks for the sink Sink of Project to send again the events received from From, until To when it is given, of the event kinds Kinds.
type Resolver ¶
type Resolver interface {
LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}
Resolver resolves a target's host name to its addresses.
type Result ¶
type Result string
Result is what became of one attempt on a stream.
const ( // Acked is a batch the target acknowledged. Acked Result = "acked" // Failed is a batch the target did not take, or a call that got no answer. Failed Result = "failed" // Idled is a stream with nothing to send. Idled Result = "idled" // Released is a stream not attempted because its sink was stopped or // disabled after the claim. Released Result = "released" // DeadLettered is a batch the target rejected for the last time and the // stream set aside. DeadLettered Result = "dead_lettered" // LeaseLost is an attempt whose lease another replica took, which // records nothing: the target may see the batch twice, under one delivery // ID. LeaseLost Result = "lease_lost" )
The results of an attempt.
type ResumeCommand ¶
ResumeCommand asks for the stopped sink Sink of Project to start again.
type ResumeSink ¶
type ResumeSink struct {
// contains filtered or unexported fields
}
ResumeSink starts a stopped sink again.
func (*ResumeSink) Handle ¶
func (h *ResumeSink) Handle(ctx context.Context, cmd ResumeCommand) (sinks.Sink, error)
Handle lifts the stop of the sink: each stream keeps its place and its batch in flight, its run of dead letters is cleared and it is due now. Dead letters are not redelivered. It records sink.resumed. A sink that is not stopped is answered as it is.
type Retention ¶ added in v0.4.0
type Retention struct {
// contains filtered or unexported fields
}
Retention is the sinks' side of retention dropping a partition: the events context calls it inside the drop's unit of work, so that the rows the drop takes can still be read and the gap is exact.
func NewRetention ¶ added in v0.4.0
func NewRetention(d RetentionDeps) *Retention
NewRetention returns the sinks' side of retention.
func (*Retention) LockStreams ¶ added in v0.4.0
LockStreams holds the streams of every sink reading typ until the drop's unit of work ends, the streams of disabled and stopped sinks included: a delivery cannot move a cursor under the drop, nor read a partition as it goes.
func (*Retention) RecordGaps ¶ added in v0.4.0
func (r *Retention) RecordGaps(ctx context.Context, typ events.EventType, days []time.Time, horizon uint64, now time.Time) ([]events.Gap, error)
RecordGaps records, for every stream of typ, the rows the drop of days takes that the stream had not delivered: a gap, the stream's live position moved to just before the first row still stored (never past the horizon), its batch in flight and lease dropped, and sink.data_lost. Measured from the position a replay returns to while one runs, since the replay's own cursor is behind rows already delivered. The pending dead letters with no row left are expired. It returns the gaps recorded.
type RetentionDeps ¶ added in v0.4.0
type RetentionDeps struct {
Store GapStore
Rows GapRows
Audit AuditLog
IDs *id.Source
// Retention is how long raw events are kept, which settled dead letters
// stay listed for as well.
Retention time.Duration
}
RetentionDeps are what the sinks' side of a partition drop runs on.
type RotateCommand ¶
RotateCommand asks for the webhook sink Sink of Project to be given a new secret.
type RotateSecret ¶
type RotateSecret struct {
// contains filtered or unexported fields
}
RotateSecret issues a webhook sink a new secret.
func NewRotateSecret ¶
func NewRotateSecret(d Deps) *RotateSecret
NewRotateSecret returns the handler.
func (*RotateSecret) Handle ¶
func (h *RotateSecret) Handle(ctx context.Context, cmd RotateCommand) (Created, error)
Handle draws the sink a new secret, stores it sealed with the one it replaces signing beside it for the overlap, and records sink.secret_rotated with both redacted. The new secret is returned this once. A sink of another kind has none to rotate (no_secret_to_rotate).
type Rows ¶
type Rows interface {
// Scope returns the scope of a stream of project's sinks naming the
// environments with keys, every environment when none; ok is false when
// the sink names some and none exists any more.
Scope(ctx context.Context, project workspace.ProjectID, keys []string) (scope sinks.Scope, ok bool, err error)
// NextBatch returns the next batch of at most limit rows past from, not
// reaching past until when it is not nil.
NextBatch(ctx context.Context, kind sinks.EventKind, scope sinks.Scope, from events.Cursor, limit int, until *events.Cursor) (sinks.Batch, error)
ReadBatch(ctx context.Context, kind sinks.EventKind, scope sinks.Scope, b sinks.Batch) (sinks.Page, error)
OldestUnread(ctx context.Context, kind sinks.EventKind, scope sinks.Scope, from events.Cursor) (at time.Time, ok bool, err error)
// Tail returns the position of the last row of kind below the snapshot
// horizon, where a stream that is to export what happens from now begins.
Tail(ctx context.Context, kind sinks.EventKind) (events.Cursor, error)
// Before returns the position just before the first row of kind in scope
// received at or after from; ok is false when there is none.
Before(ctx context.Context, kind sinks.EventKind, scope sinks.Scope, from time.Time) (at events.Cursor, ok bool, err error)
// Last returns the position of the last row of kind in scope received at
// or before to, below the horizon; ok is false when there is none.
Last(ctx context.Context, kind sinks.EventKind, scope sinks.Scope, to time.Time) (at events.Cursor, ok bool, err error)
}
Rows reads the rows the streams export.
type Sample ¶
type Sample struct {
// contains filtered or unexported fields
}
Sample sends sample rows to a sink's target.
func (*Sample) Handle ¶
Handle sends the ten sample rows of each event kind, one call per kind, under delivery IDs of their own. It reads and writes no stream, count or health, and a sink that is disabled or stopped is sampled all the same. A target that fails is a result, not an error. It records sink.sampled.
type SampleCommand ¶
type SampleCommand struct {
Project workspace.ProjectID
Sink sinks.ID
// Kinds are the event kinds to send samples of; none for every kind the
// sink exports.
Kinds []sinks.EventKind
Request governance.Request
}
SampleCommand asks for sample rows of the event kinds Kinds to be sent to the sink Sink of Project.
type Sampled ¶
type Sampled struct {
EventKind sinks.EventKind
// Failure is why the target did not acknowledge it; nil when it did.
Failure *sinks.Failure
}
Sampled is what sending the sample of one event kind found.
type Sealer ¶
type Sealer interface {
Seal(purpose secret.Purpose, plaintext []byte, binding secret.Binding) (string, error)
// Rebind returns sealed bound to binding, sealing again a value sealed
// before rows were bound.
Rebind(purpose secret.Purpose, sealed string, binding secret.Binding) (string, error)
}
Sealer seals a value under the instance's secret key.
type SetAsideResult ¶
type SetAsideResult struct {
// Held is false when the lease is gone, or the stream has no batch in
// flight, and nothing was done.
Held bool
// Attempts is how many times the batch was rejected.
Attempts int
// InARow is how many dead letters in a row the stream has now.
InARow int
// Stopped is true when this stopped the sink; false when it was already
// stopped or the run is short of the limit.
Stopped bool
}
SetAsideResult is what setting a batch aside found and did.
type Store ¶
type Store interface {
// LockProject locks project's row for the unit of work, which every
// write of the project's sinks takes first, or answers ErrNotFound when
// there is none.
LockProject(ctx context.Context, project workspace.ProjectID) error
// EnvironmentKeys returns the keys of project's environments.
EnvironmentKeys(ctx context.Context, project workspace.ProjectID) ([]string, error)
// ProjectKey returns the key of project.
ProjectKey(ctx context.Context, project workspace.ProjectID) (string, error)
// Sinks returns project's sinks, the oldest first.
Sinks(ctx context.Context, project workspace.ProjectID) ([]sinks.Sink, error)
// Sink returns project's sink with sink, or ErrNotFound.
Sink(ctx context.Context, project workspace.ProjectID, sink sinks.ID) (sinks.Sink, error)
Create(ctx context.Context, s sinks.Sink) error
// Update stores what an edit changes of s: its input, secret, update
// time and version, read under the project's lock.
Update(ctx context.Context, s sinks.Sink) error
// Delete deletes project's sink with sink, read under the project's
// lock.
Delete(ctx context.Context, project workspace.ProjectID, sink sinks.ID) error
// RotateSecret stores s's secrets and version, read under the project's
// lock.
RotateSecret(ctx context.Context, s sinks.Sink) error
// CreateStream starts the stream of kind of sink at the position at,
// sending no row received before floor when it is not nil.
CreateStream(ctx context.Context, sink sinks.ID, kind sinks.EventKind, at events.Cursor, floor *time.Time, now time.Time) error
// DeleteStream drops the stream of kind of sink with its position.
DeleteStream(ctx context.Context, sink sinks.ID, kind sinks.EventKind) error
// LockStream reads the stream of kind of sink for the unit of work, which
// holds it against the delivery worker's writes; ErrNotFound when the
// sink has none.
LockStream(ctx context.Context, sink sinks.ID, kind sinks.EventKind) (sinks.Stream, error)
// Replay puts the stream of kind of sink as plan has it: the position it
// reads on from, applied by the delivery worker before the stream's next
// batch, and where the replay stops and returns to. It drops the
// batch in flight and the lease and makes the stream due at now.
Replay(ctx context.Context, sink sinks.ID, kind sinks.EventKind, plan sinks.ReplayPlan, now time.Time) error
// SaveWarnings stores what the last check of sink's target found wrong.
SaveWarnings(ctx context.Context, sink sinks.ID, warnings []string) error
}
Store keeps a project's sinks.
type Target ¶
type Target interface {
// Probe shows whether the target answers and can take a batch, with a
// call made at now. A target that needs preparing, such as tables to
// create, is prepared when prepare is set.
Probe(ctx context.Context, c Call, now time.Time, prepare bool) Probed
// Deliver sends d and returns why it failed; nil when the target
// acknowledged it.
Deliver(ctx context.Context, c Call, d BatchToSend) *sinks.Failure
}
Target is the end of one kind of sink: the system a batch is delivered to.
type Test ¶
type Test struct {
// contains filtered or unexported fields
}
Test tests a saved sink.
func (*Test) Handle ¶
Handle calls the target of the stored sink, or of the stored sink with the configuration given, whose masked secret is the stored one. Testing the stored configuration also prepares the target when the sink may (ClickHouse tables) and stores what the check found as the sink's warnings. It records sink.tested.
type TestCommand ¶
type TestCommand struct {
Project workspace.ProjectID
Sink sinks.ID
// Config is the configuration to test in place of the stored one; nil to
// test the stored one.
Config *sinks.Config
// Secret is the secret the edit sent: empty or sinks.Masked takes the
// stored one.
Secret string
Request governance.Request
}
TestCommand asks for the stored sink Sink of Project to be tested, or an edit of it.
type TestConfig ¶
type TestConfig struct {
// contains filtered or unexported fields
}
TestConfig tests a configuration that is not saved.
func (*TestConfig) Handle ¶
func (h *TestConfig) Handle(ctx context.Context, cmd TestConfigCommand) (Tested, error)
Handle checks the configuration as saving one is checked, then calls its target. Nothing is stored or created at the target, but the test is audited as sink.config_tested: it makes a call, with headers the caller chose, from the instance's network, which whoever reads the audit log must be able to see. A webhook sink has no secret yet, so the call is signed with one drawn for it and thrown away.
type TestConfigCommand ¶
type TestConfigCommand struct {
Project workspace.ProjectID
Draft sinks.Draft
Request governance.Request
}
TestConfigCommand asks for an unsaved configuration to be tested.
type Tested ¶
type Tested struct {
// OK is whether the target answered and can take a batch.
OK bool
// Failure is why it cannot; nil when OK.
Failure *sinks.Failure
// Warnings are what is wrong with the target that does not stop delivery.
Warnings []string
}
Tested is what a test of a sink's target found.
type Transactor ¶
Transactor runs a use case's reads and writes as one unit of work.
type Update ¶
type Update struct {
// contains filtered or unexported fields
}
Update edits a sink.
type UpdateCommand ¶
type UpdateCommand struct {
Project workspace.ProjectID
Sink sinks.ID
Change sinks.Change
// Secret is the ClickHouse password or object storage secret access key
// the edit sent: empty or sinks.Masked keeps the stored one.
Secret string
Expected precondition.Version
Request governance.Request
}
UpdateCommand is an edit of the sink Sink of Project, based on its version Expected.