Compare commits

..

1 commit

Author SHA1 Message Date
33660e619e checker: add ObservationSharer interface for result mutualisation
Add an optional ObservationSharer interface that an ObservationProvider can
implement to declare that its observation depends only on a subset of the
inputs. ShareKey returns a stable, pure key derived from the inputs that
affect the result; two collections with the same key produce identical data,
letting the host serve one from the other instead of recollecting per target.

This is the contract a host (happyDomain) uses to mutualise expensive probes
(e.g. a single ping per address set) across every check target that resolves
to the same key, while providers that depend on the target (HTTP host, ...)
simply do not implement it and keep per-target behaviour.
2026-06-18 15:06:21 +09:00

View file

@ -220,6 +220,24 @@ type ObservationProvider interface {
Collect(ctx context.Context, opts CheckerOptions) (any, error)
}
// ObservationSharer is an optional interface an ObservationProvider can
// implement to declare that its observation depends only on a subset of the
// inputs and may therefore be shared across check targets.
//
// ShareKey returns a stable string derived purely from the inputs that affect
// the result (e.g. the sorted IP set + ping count). Two collections with the
// same ShareKey produce identical data; the host may serve one from the other.
// Return "" to opt out (the host falls back to per-target caching).
//
// ShareKey MUST be a pure function of opts: no network, no I/O. The host calls
// it before deciding whether to collect, possibly on the locally registered
// provider even when actual collection is delegated to a remote endpoint.
//
// Detect support with a type assertion: _, ok := provider.(ObservationSharer)
type ObservationSharer interface {
ShareKey(opts CheckerOptions) (string, error)
}
// CheckRuleInfo is the JSON-serializable description of a rule, for API/UI listing.
type CheckRuleInfo struct {
Name string `json:"name"`