Documentation
¶
Overview ¶
Package events holds the runtime-level exporters, the event channel and the notifiers of the relay proxy.
Exporters and notifiers are resources of the whole runtime, not of a flag set: M exporters shared by N flag sets are M running pipelines, and the number of goroutines and the memory do not depend on N. An evaluation hands its event to Dispatcher.Collect, which does one non-blocking send into one bounded channel. A small fixed pool of workers moves the events from the channel to the exporter managers. When the channel is full the event is dropped and counted, never waited for.
The Notifications worker consumes the changes of the reconcile engine and hands each of them to every notifier through a bounded queue per notifier, so a slow notifier delays only itself.
Builder turns the exporters and notifiers sections of the bootstrap file (config v2) into engine exporters and notifiers. AWS backed kinds take their client or configuration from the connection factory by connection name. Runtime ties the dispatcher and the notification worker together under one lifecycle (start, reload in place, shutdown with a drain deadline), and Collector exposes Status to Prometheus.
Index ¶
- Constants
- Variables
- type Builder
- type Collector
- type Dispatcher
- func (d *Dispatcher) Apply(ctx context.Context, defs []ExporterDef) (ReloadSet, error)
- func (d *Dispatcher) Collect(event Event) bool
- func (d *Dispatcher) Done() <-chan struct{}
- func (d *Dispatcher) DropNotPublic(count int)
- func (d *Dispatcher) Reload(ctx context.Context, specs Specs) (ReloadSet, error)
- func (d *Dispatcher) Shutdown(ctx context.Context) (ShutdownReport, error)
- func (d *Dispatcher) Start(ctx context.Context) error
- func (d *Dispatcher) Status() Status
- func (d *Dispatcher) WaitDrains(ctx context.Context) error
- type DispatcherConfig
- type DrainResult
- type Drops
- type EntryError
- type ErrorClass
- type Event
- type EventManager
- type ExporterDef
- type ExporterStatus
- type NewManagerFunc
- type Notifications
- func (n *Notifications) Apply(ctx context.Context, defs []NotifierDef) (ReloadSet, error)
- func (n *Notifications) Done() <-chan struct{}
- func (n *Notifications) Reload(ctx context.Context, specs Specs) (ReloadSet, error)
- func (n *Notifications) Shutdown(ctx context.Context) error
- func (n *Notifications) Start(ctx context.Context, changes <-chan flagruntime.Change) error
- func (n *Notifications) Status() Status
- func (n *Notifications) WaitDrains(ctx context.Context) error
- type NotificationsConfig
- type NotifierDef
- type NotifierStatus
- type Pipeline
- type QueueStatus
- type ReloadReport
- type ReloadSet
- type RetryPolicy
- type Runtime
- func (r *Runtime) Collect(event Event) bool
- func (r *Runtime) DropNotPublic(count int)
- func (r *Runtime) Reload(ctx context.Context, specs Specs) (ReloadReport, error)
- func (r *Runtime) Shutdown(ctx context.Context) (ShutdownReport, error)
- func (r *Runtime) Start(ctx context.Context, changes <-chan flagruntime.Change) error
- func (r *Runtime) Status() Status
- type RuntimeConfig
- type Sealed
- type ShutdownReport
- type Specs
- type Status
- type StatusReader
Constants ¶
const ( // EventTypeFeature is the type of the events of the evaluations, the default. EventTypeFeature = "feature" // EventTypeTracking is the type of the events a provider tracks (OpenFeature Tracking API). EventTypeTracking = "tracking" )
The types of events an exporter takes (the eventType of its entry).
const ( // DefaultQueueSize is the capacity of the shared event channel. DefaultQueueSize = 65536 // DefaultWorkers is the number of workers that move the events from the channel to the exporters. DefaultWorkers = 2 // DefaultBatchSize is the largest batch a worker or an exporter hands over at once. DefaultBatchSize = 256 // DefaultHandoffSize is the capacity of the hand-off of each exporter, in events. DefaultHandoffSize = 16384 // DefaultDrainTimeout is the deadline of the drain of a replaced or removed exporter. DefaultDrainTimeout = 10 * time.Second )
Defaults of the dispatcher.
const ( // ReasonQueueFull: the event channel (or the queue of a notifier) was full. ReasonQueueFull = "queue_full" // ReasonShutdown: the component was shutting down or shut down. ReasonShutdown = "shutdown" // ReasonNoExporter: a worker took the event while the set of exporters was empty (a reload to no exporter). ReasonNoExporter = "no_exporter" // ReasonOverflow: the queue of an exporter overflowed (its manager dropped the event). ReasonOverflow = "overflow" // ReasonBlockTimeout: the exporter has the block policy and its queue stayed full until the block deadline. ReasonBlockTimeout = "block_timeout" // ReasonRetryExhausted: the export of the batch failed through every attempt of the retry. ReasonRetryExhausted = "retry_exhausted" // ReasonNotPublic: the event came from a caller without an API key and its flag is not one of the public flags. ReasonNotPublic = "not_public" // ReasonDrain: the event was not delivered when its exporter closed: the drain deadline passed or the final // flush failed. ReasonDrain = "drain" )
Reasons for which an event or a change is dropped. The set is closed: it is the label set of the metrics.
const ( // StateRunning: the exporter or notifier takes events. StateRunning = "running" // StateDraining: it was replaced or removed and is delivering what it holds. StateDraining = "draining" // StateStopped: it drained and closed. StateStopped = "stopped" // StateCut: its drain passed the deadline and was cut. StateCut = "cut" )
Component states.
const DefaultNotifierQueueSize = 64
DefaultNotifierQueueSize is the number of changes that wait for one notifier.
Variables ¶
var ( // ErrUnknownKind is matched when an exporter or notifier has a kind the package does not build. ErrUnknownKind = errors.New("events: unknown kind") // ErrInvalidSettings is matched when the settings of an entry do not fit its kind. ErrInvalidSettings = errors.New("events: invalid settings") // ErrUnsupportedEventType is matched by an exporter of an event type the relay does not know. ErrUnsupportedEventType = errors.New("events: unsupported event type") // ErrUnknownConnection is matched when an entry names a connection that is not defined. ErrUnknownConnection = errors.New("events: unknown connection") // ErrWrongConnectionKind is matched when the connection of an entry has the wrong type for its kind. ErrWrongConnectionKind = errors.New("events: wrong connection type") // ErrUnresolvedSecret is matched when a secret of an entry cannot be read. ErrUnresolvedSecret = errors.New("events: secret cannot be resolved") // ErrConnectionClient is matched when the connection factory cannot give the client of a connection. ErrConnectionClient = errors.New("events: connection client") // ErrClosed is matched by an operation on a component that was shut down. ErrClosed = errors.New("events: closed") // ErrAlreadyStarted is matched by a second Start. ErrAlreadyStarted = errors.New("events: already started") )
var ErrExporterPanicked = errors.New("events: the exporter panicked")
ErrExporterPanicked is matched by the error that stands for the panic of an exporter. The engine manager treats it like any failed flush.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// Factory gives the AWS clients and configurations of the connections. It is required for the AWS kinds.
Factory *connection.Factory
// Secrets reads the secrets of the entries (environment and files).
Secrets bootstrap.LoadOptions
}
Builder builds exporters and notifiers from Specs.
func (Builder) Exporters ¶
Exporters builds the exporters of the specs, sorted by name. It returns every failing entry, each as an EntryError, and no exporter when one failed.
func (Builder) Notifiers ¶
Notifiers builds the notifiers of the specs, sorted by name. It returns every failing entry, each as an EntryError, and no notifier when one failed.
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector exposes a Status to Prometheus. Register it in the registry of the relay when the relay switches to config v2; it is not part of the metrics of version 1.
func NewCollector ¶
func NewCollector(source StatusReader) *Collector
NewCollector returns the collector of the status of source.
func (*Collector) Collect ¶
func (c *Collector) Collect(out chan<- prometheus.Metric)
Collect implements prometheus.Collector.
func (*Collector) Describe ¶
func (c *Collector) Describe(out chan<- *prometheus.Desc)
Describe implements prometheus.Collector.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher owns the one bounded event channel, the fixed pool of workers that hands every event to every exporter, and the exporters. It is safe for concurrent use.
The goroutines of a dispatcher are its workers and one goroutine per exporter: their number does not depend on the number of flag sets. The workers read a batch from the channel and offer it, without blocking, to the hand-off of every exporter of the current set under a read lock; a reload swaps the set under the write lock, so a batch goes entirely to the old set or entirely to the new one.
func NewDispatcher ¶
func NewDispatcher(config *DispatcherConfig) *Dispatcher
NewDispatcher returns a dispatcher with no exporter. It takes events as soon as it has one, and delivers them once Dispatcher.Start ran.
func (*Dispatcher) Apply ¶
func (d *Dispatcher) Apply(ctx context.Context, defs []ExporterDef) (ReloadSet, error)
Apply replaces the set of exporters by defs, in place. An exporter whose name and identity did not change keeps its manager and the events it holds. A new or changed one gets a new manager; the old one of a changed or removed exporter is no longer given events and is closed in the background: its hand-off is delivered, then its manager is stopped, which flushes it. Apply waits for the closing of the exporters that left, in parallel, for the drain timeout of the configuration, which does not depend on ctx: a request that is cancelled does not cut the drains. An exporter still closing at the deadline is reported as cut and keeps closing; its events are delivered or counted when it finishes. The lifecycle lock is not held while waiting, so a shutdown does not wait for a reload.
Events handed over before the swap went to the old exporters and are flushed by their drain; events after it go to the new ones; a batch goes to one set only.
func (*Dispatcher) Collect ¶
func (d *Dispatcher) Collect(event Event) bool
Collect hands the event to the exporters. It never blocks, takes no lock and does not allocate. It returns true when the event was queued, and false when it was not: there is no exporter (nothing is counted), the channel is full or the dispatcher is shut down (both are counted as drops). The event must not be changed after the call.
func (*Dispatcher) Done ¶
func (d *Dispatcher) Done() <-chan struct{}
Done is closed when Dispatcher.Shutdown finished.
func (*Dispatcher) DropNotPublic ¶
func (d *Dispatcher) DropNotPublic(count int)
DropNotPublic counts events that were refused before the queue: they came from a caller without an API key and their flag is not a public one.
func (*Dispatcher) Reload ¶
Reload builds the exporters of the specs and applies them in place, see Dispatcher.Apply. A build error changes nothing.
func (*Dispatcher) Shutdown ¶
func (d *Dispatcher) Shutdown(ctx context.Context) (ShutdownReport, error)
Shutdown stops taking events, delivers what the channel holds to the exporters, closes every exporter (which flushes it once) and reports what was drained and dropped. The deadline of ctx bounds the whole: past it the events still in the channel are dropped and counted, and an exporter that is still closing is cut and keeps closing in the background (see Dispatcher.WaitDrains). After it, Collect drops and counts. A second call does nothing and returns the first report. Apart from an exporter that was cut, no goroutine of the dispatcher is left.
func (*Dispatcher) Start ¶
func (d *Dispatcher) Start(ctx context.Context) error
Start starts the workers. The end of the context shuts the dispatcher down like Dispatcher.Shutdown with the drain timeout of the configuration as its deadline.
func (*Dispatcher) Status ¶
func (d *Dispatcher) Status() Status
Status returns a snapshot of the queue and of the exporters, without blocking on anything slower than a counter. The exporters are listed by name, with their cumulative counters.
func (*Dispatcher) WaitDrains ¶
func (d *Dispatcher) WaitDrains(ctx context.Context) error
WaitDrains waits until every exporter that left the set has finished closing, including the ones whose drain was cut, and the ones a shutdown is closing. The exporters that are still in the set are not waited for. It returns the error of ctx when that comes first.
type DispatcherConfig ¶
type DispatcherConfig struct {
Logger *slog.Logger
NewManager NewManagerFunc
// After is the timer of the block deadline and of the retry waits, Now the clock of the time budget of a retry
// and Rand the source of the jitter of the waits (a value in [0, 1)). The defaults are [time.After],
// [clock.Now] and [rand.Float64]; a test injects them.
After func(time.Duration) <-chan time.Time
Now func() time.Time
Rand func() float64
Builder Builder
QueueSize int
Workers int
BatchSize int
HandoffSize int
DrainTimeout time.Duration
// contains filtered or unexported fields
}
DispatcherConfig configures a Dispatcher. Zero values take the defaults.
type DrainResult ¶
type DrainResult struct {
Name string
Kind string
// Undelivered is the number of events that were not delivered when the drain ended: for a drain that was
// cut, the events that are still pending (they are delivered, or counted as dropped, when the exporter
// finishes).
Undelivered int64
// Cut says that the drain passed the deadline and was abandoned.
Cut bool
}
DrainResult is the outcome of the drain of one exporter.
type Drops ¶
type Drops struct {
QueueFull uint64 `json:"queueFull"`
Shutdown uint64 `json:"shutdown"`
NoExporter uint64 `json:"noExporter"`
Overflow uint64 `json:"overflow"`
Drain uint64 `json:"drain"`
NotPublic uint64 `json:"notPublic"`
// BlockTimeout and RetryExhausted are the drops of an exporter, see [ReasonBlockTimeout] and
// [ReasonRetryExhausted].
BlockTimeout uint64 `json:"blockTimeout"`
RetryExhausted uint64 `json:"retryExhausted"`
}
Drops counts dropped events by reason.
type EntryError ¶
EntryError names the exporter or notifier that could not be built: its section, its index in the sorted names of the section and its name. It never holds the value of a secret.
type ErrorClass ¶
type ErrorClass string
ErrorClass is the closed class of the last error of an exporter or notifier. It never holds a message: a message could carry a secret.
const ( ErrorNone ErrorClass = "none" ErrorTimeout ErrorClass = "timeout" ErrorCanceled ErrorClass = "canceled" ErrorPanic ErrorClass = "panic" ErrorOther ErrorClass = "other" )
Error classes.
type Event ¶
type Event = exporter.ExportableEvent
Event is what the evaluation path hands to the dispatcher: a feature event (*exporter.FeatureEvent) or a tracking event (*exporter.TrackingEvent). The event belongs to the dispatcher from the call of Dispatcher.Collect: the caller must not change it afterwards, the exporters read it concurrently. An exporter gets the events of its own type only (see EventTypeFeature and EventTypeTracking).
type EventManager ¶
EventManager is the engine manager of the events of one exporter.
type ExporterDef ¶
type ExporterDef struct {
// Inner is the engine exporter, without the wrapper that counts what it exports. It is sealed: it holds the
// secrets of the entry in clear.
Inner Sealed[exporter.Exporter]
// Name is the name of the entry in the exporters section.
Name string
// Kind is the kind of the exporter.
Kind string
// EventType is the type of the events the exporter takes: [EventTypeFeature] (also when empty) or
// [EventTypeTracking].
EventType string
// Identity changes when anything that affects the exporter changes: its settings, its secrets and the
// connection it uses. An exporter whose identity did not change is kept by a reload.
Identity string
// Config is what [exporter.NewManager] takes. Its Exporter counts what is exported.
Config exporter.Config
// Pipeline is the behaviour of the queue of the exporter. The zero value keeps the behaviour of a definition
// that has none.
Pipeline Pipeline
}
ExporterDef is an exporter built from its spec, not started yet.
func NewExporterDef ¶
func NewExporterDef(name, kind, identity string, exp exporter.Exporter, cfg exporter.Config) ExporterDef
NewExporterDef wraps an engine exporter in a definition the dispatcher can run: the exporter of cfg is replaced by a wrapper that counts what it exports. The builder uses it; so does a caller with an exporter of its own. Two definitions of one name with the same identity are the same exporter to a reload.
func (*ExporterDef) Format ¶
func (d *ExporterDef) Format(f fmt.State, _ rune)
Format implements fmt.Formatter so that no verb prints the exporter or its configuration.
func (*ExporterDef) GoString ¶
func (d *ExporterDef) GoString() string
GoString implements fmt.GoStringer.
func (*ExporterDef) LogValue ¶
func (d *ExporterDef) LogValue() slog.Value
LogValue implements slog.LogValuer.
func (*ExporterDef) String ¶
func (d *ExporterDef) String() string
String implements fmt.Stringer: the name, the kind and the identity, never the exporter. A definition that is printed by value shows no secret either: the exporter it holds is Sealed.
type ExporterStatus ¶
type ExporterStatus struct {
Name string `json:"name"`
Kind string `json:"kind"`
State string `json:"state"`
// OverflowPolicy is what a full queue of the exporter does: dropNewest, dropOldest or block.
OverflowPolicy string `json:"overflowPolicy"`
// LastError is the class of the error of the last flush.
LastError ErrorClass `json:"lastError"`
Dropped Drops `json:"dropped"`
// Queued is the number of events handed to the exporter that are neither exported nor dropped.
Queued int64 `json:"queued"`
// Handed is the number of events handed to the exporter.
Handed uint64 `json:"handed"`
// Exported is the number of events the exporter wrote.
Exported uint64 `json:"exported"`
// FlushFailures is the number of failed flushes.
FlushFailures uint64 `json:"flushFailures"`
// Flushes and FlushSeconds are the count and the total duration of the flushes.
Flushes uint64 `json:"flushes"`
FlushSeconds float64 `json:"flushSeconds"`
}
ExporterStatus is the state of one exporter. It holds no secret.
type NewManagerFunc ¶
NewManagerFunc builds the manager of the exporter name. The default is exporter.NewManager with that single exporter, so M exporters are M managers whatever the number of flag sets.
type Notifications ¶
type Notifications struct {
// contains filtered or unexported fields
}
Notifications is the change worker: one goroutine consumes the changes of the reconcile engine and offers each of them to the bounded queue of every notifier. Each notifier has one goroutine that calls it, one change at a time and in the order of the queue, so the changes of a flag set reach a notifier in order. A slow or failing notifier fills its own queue and loses its own changes; it never delays the consumer or the other notifiers.
There is no per-call timeout: the notifiers bound their own HTTP calls (the Teams notifier 5 seconds, the others the timeout of the HTTP client of the engine), and a call that never returns holds only the goroutine of its notifier.
A reload that replaces a notifier keeps the order: the new instance accepts changes at once, but calls its notifier only after the old instance delivered what its queue held (or the drain deadline passed).
func NewNotifications ¶
func NewNotifications(config *NotificationsConfig) *Notifications
NewNotifications returns a worker with no notifier.
func (*Notifications) Apply ¶
func (n *Notifications) Apply(ctx context.Context, defs []NotifierDef) (ReloadSet, error)
Apply replaces the set of notifiers in place. A notifier whose identity did not change keeps its goroutine and its queue. A new or changed one gets its own; the old one of a changed or removed notifier gets no more changes, delivers what its queue holds within the drain timeout (which does not depend on ctx) and stops. The lifecycle lock is not held while waiting.
func (*Notifications) Done ¶
func (n *Notifications) Done() <-chan struct{}
Done is closed when Notifications.Shutdown finished.
func (*Notifications) Reload ¶
Reload builds the notifiers of the specs and applies them, see Notifications.Apply.
func (*Notifications) Shutdown ¶
func (n *Notifications) Shutdown(ctx context.Context) error
Shutdown stops consuming changes, lets every notifier deliver what its queue holds until the deadline of ctx, and stops them. What is still queued at the deadline is dropped and counted. A second call does nothing.
func (*Notifications) Start ¶
func (n *Notifications) Start(ctx context.Context, changes <-chan flagruntime.Change) error
Start starts the consumer of changes (a nil channel is allowed: nothing is consumed). The consumer stops when the channel is closed or at Shutdown. The end of the context shuts the notifications down like Notifications.Shutdown, with the drain timeout of the configuration as its deadline.
func (*Notifications) Status ¶
func (n *Notifications) Status() Status
Status returns a snapshot of the notifiers by name, with their cumulative counters, without blocking.
func (*Notifications) WaitDrains ¶
func (n *Notifications) WaitDrains(ctx context.Context) error
WaitDrains waits until every notifier instance that left the set has finished, including the ones whose drain was cut. The instances that are still in the set are not waited for. It returns the error of ctx when that comes first.
type NotificationsConfig ¶
type NotificationsConfig struct {
Logger *slog.Logger
Broadcast func(flagruntime.Change)
Builder Builder
QueueSize int
DrainTimeout time.Duration
// contains filtered or unexported fields
}
NotificationsConfig configures Notifications. Zero values take the defaults.
type NotifierDef ¶
type NotifierDef struct {
// Notifier is the engine notifier. It is sealed: it holds the secrets of the entry in clear.
Notifier Sealed[notifier.Notifier]
// Name is the name of the entry in the notifiers section.
Name string
// Kind is the kind of the notifier.
Kind string
// Identity changes when anything that affects the notifier changes, secrets included.
Identity string
}
NotifierDef is a notifier built from its spec, not started yet.
func NewNotifierDef ¶
func NewNotifierDef(name, kind, identity string, notif notifier.Notifier) NotifierDef
NewNotifierDef wraps an engine notifier in a definition Notifications can run.
func (NotifierDef) Format ¶
func (d NotifierDef) Format(f fmt.State, _ rune)
Format implements fmt.Formatter so that no verb prints the notifier.
func (NotifierDef) GoString ¶
func (d NotifierDef) GoString() string
GoString implements fmt.GoStringer.
func (NotifierDef) LogValue ¶
func (d NotifierDef) LogValue() slog.Value
LogValue implements slog.LogValuer.
func (NotifierDef) String ¶
func (d NotifierDef) String() string
String implements fmt.Stringer: the name, the kind and the identity, never the notifier.
type NotifierStatus ¶
type NotifierStatus struct {
Name string `json:"name"`
Kind string `json:"kind"`
State string `json:"state"`
LastError ErrorClass `json:"lastError"`
// Queued is the number of changes waiting in the queue of the notifier.
Queued int `json:"queued"`
Delivered uint64 `json:"delivered"`
Errors uint64 `json:"errors"`
Panics uint64 `json:"panics"`
// Dropped counts the changes that did not fit in the queue or were cut at shutdown.
Dropped uint64 `json:"dropped"`
}
NotifierStatus is the state of one notifier. It holds no secret.
type Pipeline ¶
type Pipeline struct {
// Overflow is one of the bootstrap.Overflow* policies; empty is dropNewest.
Overflow string
// Retry is the retry of a failed export; its zero value turns the retry of the pipeline off.
Retry RetryPolicy
// BlockTimeout is the longest wait of the block policy for room in the queue.
BlockTimeout time.Duration
// DrainTimeout is the deadline of the drain of the exporter; zero is the one of the dispatcher.
DrainTimeout time.Duration
// MaxBytes cuts a batch at that size (see [exporter.EventSize]); zero is no limit.
MaxBytes int64
}
Pipeline is the behaviour of the queue of one exporter: what a full queue does, the limit of a batch in bytes, the retry of a failed export and the drain deadline. The zero value is the behaviour before these settings existed: a full queue drops the new event, no byte limit, a failed batch stays for the next flush, the drain deadline of the dispatcher.
func PipelineOf ¶
PipelineOf reads the pipeline settings of an exporter entry. The bootstrap loader has applied the defaults.
type QueueStatus ¶
type QueueStatus struct {
Dropped Drops `json:"dropped"`
Accepted uint64 `json:"accepted"`
Length int `json:"length"`
Capacity int `json:"capacity"`
}
QueueStatus is the state of the event channel.
type ReloadReport ¶
ReloadReport says what a reload did with the exporters and the notifiers.
type ReloadSet ¶
type ReloadSet struct {
// Kept are the entries whose identity did not change: their manager (and its queued events) stayed.
Kept []string
// Added are the new entries.
Added []string
// Replaced are the entries whose identity changed: a new one runs, the old one was drained.
Replaced []string
// Removed are the entries that left: they were drained.
Removed []string
// Cut are the drained entries whose drain passed the deadline. They keep closing in the background.
Cut []string
}
ReloadSet says what a reload did with the exporters (or the notifiers), by name.
type RetryPolicy ¶
type RetryPolicy struct {
// Drop makes a batch that exhausts the retry dropped and counted as retry_exhausted; the default keeps it for
// the next flush of the engine manager.
Drop bool
MaxAttempts int
InitialBackoff time.Duration
MaxBackoff time.Duration
MaxElapsed time.Duration
}
RetryPolicy is the retry of a failed export: MaxAttempts counts the first attempt (0 is one attempt, like 1: a failed batch then follows Drop), the wait before a retry starts at InitialBackoff, doubles up to MaxBackoff and carries jitter, and the waits of one batch add up to MaxElapsed at most (0: no cap).
type Runtime ¶
type Runtime struct {
Dispatcher *Dispatcher
Notifications *Notifications
// contains filtered or unexported fields
}
Runtime is the dispatcher and the notification worker under one lifecycle.
func NewRuntime ¶
func NewRuntime(cfg *RuntimeConfig) *Runtime
NewRuntime returns a runtime with no exporter and no notifier.
func (*Runtime) Collect ¶
Collect hands an evaluation event to the exporters, see Dispatcher.Collect.
func (*Runtime) DropNotPublic ¶
DropNotPublic counts events of a caller without a key that were refused for a flag that is not public.
func (*Runtime) Reload ¶
Reload builds the exporters and the notifiers of the specs, checks that both sides are open, and applies both in place. When an entry fails to build, or one side is closed, nothing is changed and the error says why (every failing entry is named).
func (*Runtime) Shutdown ¶
func (r *Runtime) Shutdown( ctx context.Context, ) (ShutdownReport, error)
Shutdown shuts down the notification worker and the dispatcher within the deadline of ctx.
type RuntimeConfig ¶
type RuntimeConfig struct {
// Logger receives the logs; nil discards them.
Logger *slog.Logger
// Broadcast is the hook called with every change, see [NotificationsConfig.Broadcast].
Broadcast func(flagruntime.Change)
// NewManager builds the manager of one exporter, see [DispatcherConfig.NewManager].
NewManager NewManagerFunc
// After and Rand are the timer and the source of jitter of the block deadline and of the retries, see
// [DispatcherConfig.After].
After func(time.Duration) <-chan time.Time
Now func() time.Time
Rand func() float64
// Builder builds the exporters and notifiers.
Builder Builder
// QueueSize, Workers and BatchSize size the event channel, the worker pool and its batches.
QueueSize int
Workers int
BatchSize int
// NotifierQueueSize is the queue of changes of each notifier.
NotifierQueueSize int
// DrainTimeout is the deadline of the drain of what a reload replaces or removes, for an exporter that sets none.
DrainTimeout time.Duration
}
RuntimeConfig configures a Runtime. Zero values take the defaults of the dispatcher and the notifications.
type Sealed ¶
type Sealed[T any] struct { // contains filtered or unexported fields }
Sealed holds an engine exporter or notifier, which carries its secrets in clear (a URL, a signing key). It prints the redaction marker with every fmt verb and as a slog value, so that a definition that is logged or formatted by mistake does not show them. Sealed.Unseal gives the value back.
func (Sealed[T]) Format ¶
Format implements fmt.Formatter so that no verb prints the content.
func (Sealed[T]) LogValue ¶
LogValue implements slog.LogValuer.
type ShutdownReport ¶
type ShutdownReport struct {
// Drained has one entry per exporter that was closed.
Drained []DrainResult
// Dropped counts the events dropped before they reached an exporter over the life of the dispatcher, by
// reason. The drops of an exporter are in its status.
Dropped Drops
// Undelivered is the sum of the undelivered events of the exporters.
Undelivered int64
}
ShutdownReport says what a shutdown drained and dropped.
type Specs ¶
type Specs struct {
Connections map[string]bootstrap.Connection
Exporters map[string]bootstrap.Exporter
Notifiers map[string]bootstrap.Notifier
}
Specs are the sections of the bootstrap file the package reads.
type Status ¶
type Status struct {
Exporters []ExporterStatus `json:"exporters"`
Notifiers []NotifierStatus `json:"notifiers"`
Queue QueueStatus `json:"queue"`
}
Status is an immutable snapshot of the exporters and the notifiers, read without blocking.
type StatusReader ¶
type StatusReader interface {
Status() Status
}
StatusReader is implemented by Dispatcher, Notifications and Runtime.