connectivity

package
v0.27.0-rc.10 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package connectivity reports a server's reachability as transitions rather than as attempts, so a component that retries for as long as it is offline logs when it loses the server and when it gets it back instead of once per retry.

The attempt number is the transition. A caller whose retry loop already counts attempts, as resty's Request.Attempt does, passes the count in to the package-level Lost, Refused and Recovered; one that has no counter of its own uses a Tracker, which keeps it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lost

func Lost(logger logrus.FieldLogger, attempt int, err error)

Lost reports one failed attempt to reach the server. The first attempt is logged at warn level and every one after it at debug, so an outage costs one line however long it lasts.

func Recovered

func Recovered(logger logrus.FieldLogger, attempt int, elapsed time.Duration)

Recovered reports the attempt the server finally answered, naming how many it took and how long since the first one. Callers report only the attempt that ended a run of failures; one that succeeded first time has nothing to say. The wording stays neutral because the run it ends may have been a server that could not answer or one that answered and refused, and only the caller knows which.

func Refused

func Refused(logger logrus.FieldLogger, attempt int, err error)

Refused reports one attempt the server answered by refusing to authorize the device. It reads as a distinct condition from an unreachable server because it is: the server is up, and what has to change is the namespace or the device limit. Levels follow Lost.

Types

type Tracker

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

Tracker counts consecutive failures for a caller whose retry loop has no attempt counter to pass in, and reports them through Lost, Refused and Recovered. It holds no lock: a Tracker belongs to the single goroutine running the loop it counts, and two of them covering one server would each report the same outage.

func NewTracker

func NewTracker(logger logrus.FieldLogger) *Tracker

NewTracker returns a Tracker reporting through logger, with no outage in progress.

func (*Tracker) Lost

func (t *Tracker) Lost(err error)

Lost counts one failed attempt to reach the server and reports it.

func (*Tracker) Recovered

func (t *Tracker) Recovered() bool

Recovered reports the attempt that ended a run of failures and clears the count, returning false when there was no run to end so the caller can say for itself what a first-time success means.

func (*Tracker) Refused

func (t *Tracker) Refused(err error)

Refused counts one attempt the server answered by refusing the device and reports it.

Jump to

Keyboard shortcuts

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