Documentation
¶
Overview ¶
Package pollsource provides a reusable polling loop with bounded exponential backoff and jitter for pull-based catalog collector sources.
A pull source supplies a collection callback and receives polling, backoff, cancellation, and collection-attempt notification behavior without coupling that behavior to the shared pipeline. Process readiness is not managed here; it is owned by the healthcheck extension.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackoffConfig ¶
type BackoffConfig struct {
// InitialInterval is the base delay after the first failed cycle.
InitialInterval util.Duration `json:"initialInterval,omitempty"`
// MaxInterval is the maximum actual retry delay, including jitter.
MaxInterval util.Duration `json:"maxInterval,omitempty"`
// Multiplier advances the base interval after each consecutive failure.
Multiplier float64 `json:"multiplier,omitempty"`
// RandomizationFactor applies symmetric jitter around the base interval.
// It must be within [0, 1].
RandomizationFactor float64 `json:"randomizationFactor,omitempty"`
}
BackoffConfig configures bounded exponential backoff with symmetric jitter.
func DefaultBackoffConfig ¶
func DefaultBackoffConfig() BackoffConfig
DefaultBackoffConfig returns the default bounded-backoff configuration.
func (*BackoffConfig) Validate ¶
func (c *BackoffConfig) Validate() error
Validate verifies that the backoff configuration can safely drive the polling loop.
type CollectFunc ¶
type CollectFunc func( ctx context.Context, ) (*catalogcollector.CatalogSnapshot, error)
CollectFunc performs one complete collection cycle.
A successful call returns one complete desired-state snapshot. An error must return no usable partial snapshot; the helper does not forward a snapshot when collection fails.
type Helper ¶
type Helper struct {
// OnCollect is called exactly once for every collection attempt, after
// collection finishes and before the snapshot is handed to the downstream
// consumer. elapsed measures collection alone and therefore excludes
// downstream consumption. err is the collection error, or nil when the
// attempt produced a usable snapshot.
//
// Because the callback runs before consumption, a downstream failure or a
// cancellation observed during consumption cannot change the recorded
// collection outcome.
OnCollect func(elapsed time.Duration, err error)
// contains filtered or unexported fields
}
Helper drives a periodic complete-snapshot polling loop.
The first cycle starts immediately. After collection and downstream consumption both succeed, the helper resets backoff and waits pollInterval. Any collection or downstream failure advances backoff.
Collection cycles never overlap. Context cancellation interrupts collection, downstream processing when supported by the consumer, and inter-cycle waits.
func NewHelper ¶
func NewHelper( id string, pollInterval time.Duration, backoff BackoffConfig, log *logrus.Entry, now NowFunc, jitter JitterFunc, ) *Helper
NewHelper constructs a polling helper.
now and jitter may be nil. Production clock and random-jitter implementations are used when they are not supplied.
func (*Helper) Run ¶
func (h *Helper) Run( ctx context.Context, collect CollectFunc, next catalogcollector.Consumer, ) error
Run executes polling cycles until the context is cancelled or invalid helper configuration is detected.
Backoff resets only after both collection and downstream consumption succeed.
type JitterFunc ¶
JitterFunc returns a random duration in [0, max). Tests may inject a deterministic implementation.