reporter

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package reporter defines a side-effect interface invoked on probe status transitions. Implementations: logging, metrics emission, alerting hooks.

Reporters are called synchronously from the runner.Runner tick goroutine. A slow reporter blocks the next tick — keep work fast or dispatch to a worker pool inside your implementation. The Multi adapter calls children sequentially for the same reason.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Name is the probe identifier set via runner.WithName.
	// Empty when the runner has no name configured.
	Name string
	// Prev is the status before the transition.
	Prev probe.Status
	// Cur is the new status.
	Cur probe.Status
	// PrevReason and Reason describe the old and new observations. Reporters
	// also receive reason-only changes while the status remains unhealthy.
	PrevReason string
	Reason     string
}

Event describes a probe status transition.

Fields are extensible: future additions (e.g. duration, last error) can be appended without breaking existing Reporter implementations.

type Func

type Func func(ctx context.Context, ev Event)

Func adapts a plain function into a Reporter.

func (Func) OnStatus

func (f Func) OnStatus(ctx context.Context, ev Event)

type Multi

type Multi []Reporter

Multi fans out to several reporters sequentially.

func (Multi) OnStatus

func (m Multi) OnStatus(ctx context.Context, ev Event)

type Nop

type Nop struct{}

Nop discards all reports.

func (Nop) OnStatus

func (Nop) OnStatus(context.Context, Event)

type Reporter

type Reporter interface {
	OnStatus(ctx context.Context, ev Event)
}

Reporter is invoked when a probe's cached status changes.

func Slog

func Slog(logger *slog.Logger) Reporter

Slog returns a Reporter that logs every transition via the given slog.Logger. Up transitions log at Info, anything else at Warn.

Jump to

Keyboard shortcuts

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