notify

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 9 Imported by: 0 modules, 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

Overview

Package notify provides a pluggable condition notification system that watches the registry KV bucket for component condition transitions and dispatches events via configurable notifiers.

Index

Constants

View Source
const ConditionComponentUnreachable types.ConditionType = "ComponentUnreachable"

ConditionComponentUnreachable is the condition of a component whose heartbeat expired. Only the notifier sends it: no component reports it, so it is not one of types.ConditionType values.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConditionEvent

type ConditionEvent struct {
	// ComponentType is "agent", "api", or "nats".
	ComponentType string
	// Hostname identifies the component.
	Hostname string
	// Condition is the condition type (e.g., "MemoryPressure").
	Condition types.ConditionType
	// Active is true when the condition fires, false when resolved.
	Active bool
	// Reason describes why the condition triggered or resolved.
	Reason string
	// Timestamp is when the transition occurred.
	Timestamp time.Time
}

ConditionEvent represents a condition state transition on a component.

type LogNotifier

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

LogNotifier logs condition events at INFO level.

func NewLogNotifier

func NewLogNotifier(
	logger *slog.Logger,
) *LogNotifier

NewLogNotifier creates a new LogNotifier that logs condition events using the provided logger.

func (*LogNotifier) Notify

func (n *LogNotifier) Notify(
	_ context.Context,
	event ConditionEvent,
) error

Notify logs the condition event at INFO level and returns nil.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, event ConditionEvent) error
}

Notifier sends notifications when component conditions change.

type Registry added in v0.3.0

type Registry interface {
	KVWatch(
		ctx context.Context,
		bucket string,
		pattern string,
		opts ...jetstream.WatchOpt,
	) (<-chan jetstream.KeyValueEntry, error)
}

Registry watches the registry KV bucket. A *natsclient.Client is one.

type Watcher

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

Watcher monitors the registry KV bucket for condition transitions and emits ConditionEvents via the configured Notifier. Active conditions are re-notified after the configured renotify interval.

func NewWatcher

func NewWatcher(
	kv Registry,
	bucket string,
	notifier Notifier,
	logger *slog.Logger,
	renotifyInterval time.Duration,
) *Watcher

NewWatcher creates a new Watcher that monitors registry KV entries and notifies on condition transitions. Active conditions are re-notified after renotifyInterval elapses (0 disables re-notification).

func (*Watcher) Start

func (w *Watcher) Start(
	ctx context.Context,
) error

Start watches the registry KV for changes. Blocks until ctx is cancelled. Returns nil when the context is cancelled, or an error if WatchAll fails.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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