From 33660e619ea6a0a21192377e331f68d78452e003 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 18 Jun 2026 12:28:07 +0900 Subject: [PATCH] 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. --- checker/types.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/checker/types.go b/checker/types.go index ed4a9fc..ee67132 100644 --- a/checker/types.go +++ b/checker/types.go @@ -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"`