probe

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package probe contains utilities for health probing, as well as health status information.

Index

Constants

View Source
const (
	// DefaultProbePeriod is the default value for the interval between
	// probe invocations.
	DefaultProbePeriod = 10 * time.Second

	// DefaultProbeTimeout is the default value for the timeout when
	// executing a probe to cancel it and consider it failed.
	DefaultProbeTimeout = 1 * time.Second

	// DefaultInitialDelay is the default value for the initial delay
	// before beginning to invoke the probe after the Worker is started.
	DefaultInitialDelay = 0 * time.Second

	// DefaultProbeSuccessThreshold is the default value for the
	// minimum number of consecutive successes required after having
	// failed before the status will transition to probe.Success.
	DefaultProbeSuccessThreshold = 1

	// DefaultProbeFailureThreshold is the default value for the
	// minimum number of consecutive failures required after having
	// succeeded before the status will transition to probe.Failure.
	DefaultProbeFailureThreshold = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ResultFunc added in v0.2.0

type ResultFunc func(result prober.Result, statusChanged bool, output string, err error)

ResultFunc is invoked on every probe execution using WorkerOnProbeResult.

If statusChanged is true, the probe has transitioned. Note that subsequent invocations of ResultFunc might have the same result value but statusChanged set to false if a transition hasn't occurred due to success and failure thresholds.

type Worker

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

Worker handles executing probes and reporting results.

It's loosely based (but simplified) on the k8s.io/kubernetes/pkg/kubelet/prober design.

func NewWorker

func NewWorker(p prober.Prober, opts ...WorkerOption) *Worker

NewWorker creates a Worker instance using the provided probe.Prober and options (if any).

func (*Worker) Run

func (w *Worker) Run(ctx context.Context)

Run periodically executes a probe until stopped.

The Worker can be stopped by cancelling the context.

Calling Run() on an instance that is already running will result in a panic.

func (*Worker) Running added in v0.2.0

func (w *Worker) Running() bool

func (*Worker) Status

func (w *Worker) Status() prober.Result

Status returns the current probe result.

If not running, this will always return probe.Unknown.

type WorkerOption

type WorkerOption func(w *Worker)

WorkerOption can be passed when creating a Worker to configure the instance.

func WorkerFailureThreshold

func WorkerFailureThreshold(v int) WorkerOption

WorkerFailureThreshold sets the number of consecutive failures required after a probe has succeeded before the status will transition to probe.Failure.

func WorkerInitialDelay

func WorkerInitialDelay(delay time.Duration) WorkerOption

WorkerInitialDelay sets the amount of time that will be waited when the prober starts before beginning to invoke the probe.

The status will be probe.Failure during the initial delay period.

func WorkerOnProbeResult added in v0.2.0

func WorkerOnProbeResult(f ResultFunc) WorkerOption

WorkerOnProbeResult sets the function to invoke after every probe execution regardless of whether it results in a status transition.

func WorkerPeriod

func WorkerPeriod(period time.Duration) WorkerOption

WorkerPeriod sets the period between probe invocations.

func WorkerSuccessThreshold

func WorkerSuccessThreshold(v int) WorkerOption

WorkerSuccessThreshold sets the number of consecutive successes required after a probe has failed before the status will transition to probe.Success.

func WorkerTimeout

func WorkerTimeout(timeout time.Duration) WorkerOption

WorkerTimeout sets the duration before a running probe is canceled and considered to have failed.

Jump to

Keyboard shortcuts

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