shared

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ClockSkew = 30 * time.Second
View Source
const MaxBody = 1 << 20

Variables

This section is empty.

Functions

func Read

func Read(body io.Reader) ([]byte, error)

func ValidateURL

func ValidateURL(u *url.URL) error

ValidateURL checks discovery base URLs, retaining deployment paths.

Types

type Collector

type Collector[R Runner] struct {
	Client      *http.Client
	Logger      *slog.Logger
	MaxFailures int
	Observe     func(int, time.Duration, error)
	// contains filtered or unexported fields
}

Collector polls complete discovery endpoints and retains per-source inventories. Configure the client and failure limit before starting workers.

func (*Collector[R]) AcceptEmpty

func (c *Collector[R]) AcceptEmpty()

AcceptEmpty marks a successful empty source selection as initialized. Later source additions are collected by the worker rather than HTTP requests.

func (*Collector[R]) Close

func (c *Collector[R]) Close()

Close cancels and joins pending work, and prevents further refreshes.

func (*Collector[R]) CollectMetrics added in v1.0.7

func (c *Collector[R]) CollectMetrics(emit observability.Emit)

CollectMetrics includes configured sources that have never succeeded and sources whose inventory has been evicted. Labels never contain source URLs.

func (*Collector[R]) Initialized

func (c *Collector[R]) Initialized() bool

func (*Collector[R]) Refresh

func (c *Collector[R]) Refresh(ctx context.Context, initialOnly bool)

Refresh coalesces fetches owned by the collector; any caller may stop waiting.

func (*Collector[R]) Run

func (c *Collector[R]) Run(ctx context.Context, interval time.Duration)

Run polls immediately, on source additions, and periodically, then closes the collector.

func (*Collector[R]) SetSources

func (c *Collector[R]) SetSources(urls []*url.URL)

SetSources preserves retained sources in input order and removes deleted ones.

func (*Collector[R]) Snapshots

func (c *Collector[R]) Snapshots() []Snapshot[R]

Snapshots returns successful observations in source order. Entries are read-only.

type Entry

type Entry[R Runner] struct {
	Address string `json:"address"`
	Runners []R    `json:"runners"`
}

func Decode

func Decode[R Runner](data []byte, now time.Time) ([]Entry[R], error)

Decode ignores source metadata and isolates runner errors from envelope errors. Empty inventories succeed; advertised runners with no valid candidates fail.

func Merge

func Merge[R Runner](entries []Entry[R]) []Entry[R]

Merge chooses whole records by original observation time, breaking ties by input order. It retains empty groups, letting each caller control presentation.

type Runner

type Runner interface {
	DiscoveryIdentity() (url, app, observed string)
}

Runner exposes the fields used to validate and compare an inventory record.

type Snapshot

type Snapshot[R Runner] struct {
	URL         string
	QueriedAt   time.Time
	Entries     []Entry[R]
	Failures    int
	LastSuccess time.Time
}

Snapshot is an immutable successful inventory observation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL