coveragebus

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package coveragebus is the bus plane of the continuous-coverage stream (ADR-0169 §SD4): subjects, the codec seam, producer and consumer. It mirrors sysmetricsbus and stays free of runtime/coverage and decoder imports — the concrete sampler is wired in covscrape, so a consumer importing this package pulls in no acquisition code.

Index

Constants

View Source
const (
	MinInterval = 1 * time.Second
	MaxInterval = 10 * time.Minute
)

MinInterval and MaxInterval clamp the producer's tick period. Coverage churn is slow and each tick serializes the process's counter arrays, so the floor sits well above the metric plane's.

View Source
const DefaultInterval = 5 * time.Second

DefaultInterval is the tick period when ProducerOptions.Interval is unset.

View Source
const ServiceAppId app.AppIdT = "runtime.coverage"

ServiceAppId is the bus identity of the coverage sampler service, mirroring "runtime.sysmetrics". It is the only identity that should hold the coverage publish capability.

View Source
const SubjectRoot = "coverage"

SubjectRoot is the top-level subject family of the coverage plane.

View Source
const SubjectWildcard = SubjectRoot + ".>"

SubjectWildcard matches every coverage subject; the cap pattern for the producer (publish) and consumers (subscribe).

Variables

View Source
var Interval = env.NewString(env.Spec{
	Name:        "IMZERO2_COVERAGE_INTERVAL",
	Default:     "5s",
	Description: "coverage sample interval on -cover -covermode=atomic builds (ADR-0169); a zero or negative duration disables sampling",
	Category:    env.CategorySystem,
})

Interval is the coverage sample cadence knob (ADR-0169 §SD4, registered per ADR-0009). The sampler only exists on -cover -covermode=atomic builds; on those, a zero or negative duration disables sampling.

Functions

func IntervalFromEnv

func IntervalFromEnv() (interval time.Duration, enabled bool)

IntervalFromEnv reads and interprets the knob.

func ParseInterval

func ParseInterval(raw string) (interval time.Duration, enabled bool)

ParseInterval interprets the knob's raw value: a non-positive duration disables sampling, an unparsable value falls back to the default (a misconfigured knob must not silently switch the lane off).

func SampleSubject

func SampleSubject(hostToken string) (subject string)

SampleSubject returns the per-host update subject ("coverage.{host}.sample"). An empty token falls back to "local". Host tokens follow the metric plane's rule — callers pass sysmetricsbus.DefaultHostToken() or an equally sanitised token.

func SampleSubjectWildcard

func SampleSubjectWildcard() (subject string)

SampleSubjectWildcard matches every host's update subject (coverage.*.sample).

Types

type CBORCodec

type CBORCodec struct{}

func NewCBORCodec

func NewCBORCodec() (c CBORCodec)

func (CBORCodec) Decode

func (c CBORCodec) Decode(payload []byte) (upd *covsnap.Update, err error)

func (CBORCodec) Encode

func (c CBORCodec) Encode(upd *covsnap.Update) (payload []byte, err error)

type Codec

type Codec interface {
	Encode(upd *covsnap.Update) (payload []byte, err error)
	Decode(payload []byte) (upd *covsnap.Update, err error)
}

Codec is the wire seam of the coverage plane, and CBORCodec is what it carries.

This followed sysmetricsbus, which shipped CBOR as an interim on the way to ADR-0090 §SD3's facts bus codec. That swap was since abandoned there (ADR-0184), so the precedent no longer carries a pending replacement — only the seam. What the coverage plane's wire should be is ADR-0169's to settle; nothing here is waiting on a decision made elsewhere. ADR-0089 keeps the bus wire distinct from the ingest wire either way.

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer is the subscribing half of the coverage plane: it decodes each published update and hands it to Handler. The handler runs on whatever goroutine the bus dispatches on — under inprocbus that is the publisher's goroutine, synchronously — so it must not block.

func NewConsumer

func NewConsumer(opts ConsumerOptions) (inst *Consumer, err error)

NewConsumer validates opts and returns a Consumer that is not yet subscribed; call Start to subscribe.

func (*Consumer) Close

func (inst *Consumer) Close() (err error)

Close unsubscribes. Safe to call when never started.

func (*Consumer) Start

func (inst *Consumer) Start() (err error)

Start subscribes to the subject. A decode failure on any message is logged and dropped — one corrupt frame must not tear down the stream.

type ConsumerOptions

type ConsumerOptions struct {
	Bus     app.BusI
	Subject string
	Codec   Codec
	Handler func(upd *covsnap.Update)
	Log     zerolog.Logger
}

ConsumerOptions configures NewConsumer. Bus, Subject, Codec, and Handler are required.

type Producer

type Producer struct {
	// contains filtered or unexported fields
}

Producer is the publishing half of the coverage plane (ADR-0169 §SD4): it owns the sampler, ticks at its configured cadence, encodes each update, and publishes it. Deltas ride fire-and-forget Publish; the sampler's periodic full re-statements are what heal a consumer that missed one.

func NewProducer

func NewProducer(opts ProducerOptions) (inst *Producer, err error)

NewProducer validates opts and returns a stopped Producer; call Start to begin ticking.

func (*Producer) Close

func (inst *Producer) Close() (err error)

Close stops the tick loop and closes the underlying sampler (the producer owns it once handed over via ProducerOptions).

func (*Producer) Start

func (inst *Producer) Start(ctx context.Context)

Start launches the tick loop. The first sample is published immediately (the sampler's first update is a full statement by contract), then once per interval until ctx is cancelled or Close is called.

type ProducerOptions

type ProducerOptions struct {
	Sampler  UpdateSampler
	Bus      app.BusI
	Subject  string
	Codec    Codec
	Interval time.Duration
	Log      zerolog.Logger
}

ProducerOptions configures NewProducer. Sampler, Bus, Subject, and Codec are required.

type UpdateSampler

type UpdateSampler interface {
	Sample() (upd *covsnap.Update, err error)
	Close() (err error)
}

UpdateSampler is the producer's view of the coverage source: anything that folds one sample into a pre-aggregated update and can be closed. *coverage.Sampler satisfies it. The interface keeps this package free of runtime/coverage imports — the concrete sampler is wired in covscrape.

Jump to

Keyboard shortcuts

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