Documentation
¶
Overview ¶
Package state holds the cached health status of a probe along with pub/sub semantics so transports (gRPC Watch, log/metric reporters, cached HTTP) can react to changes without re-running the underlying probe.
Index ¶
- type Registry
- type State
- func (s *State) Get() probe.Status
- func (s *State) HasBeenSet() bool
- func (s *State) Result() probe.Result
- func (s *State) Set(st probe.Status) (prev probe.Status, changed bool)
- func (s *State) SetResult(r probe.Result) (prev probe.Result, changed bool)
- func (s *State) Subscribe(ctx context.Context) <-chan probe.Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps service names to States. The empty name "" is conventionally used for the overall service status (matches grpc.health.v1 semantics).
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is a thread-safe cached probe.Status with subscriber broadcast.
Subscribers receive the current status immediately on Subscribe, then any subsequent changes. The latest value wins — if a subscriber is slow, older updates are dropped while the channel is full.
Notifications are serialized with respect to Set: subscribers will never observe an ordering inconsistent with the status mutations themselves.
func New ¶
func New() *State
New creates a State initialized to StatusUnknown. HasBeenSet returns false until the first Set call.
func (*State) HasBeenSet ¶
HasBeenSet reports whether Set has ever been called on this State. Used by transports (notably gRPC) to distinguish "service exists but its status was never reported" from "service status is genuinely up/down".
func (*State) Result ¶ added in v1.2.0
Result returns the status and reason from the same cached observation.
func (*State) Set ¶
Set replaces the cached status and notifies subscribers if the value changed. Returns the previous status and whether a change occurred.
The lock is held across subscriber notifications. drainSend is non-blocking, so this does not stall callers, and it guarantees that concurrent Set calls produce a notification order consistent with the final status.