k8sprobe

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

k8sprobe

A package to simplify create probe handlers inside the Go service

Documentation

Index

Constants

View Source
const UrlPathValue = "{probeType}"

UrlPathValue is the constant key used to extract the probe type from a request's URL path parameters.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cause

type Cause = string

Cause is a type alias for string, often used to provide reasons or explanations within validation contexts.

const EmptyCause Cause = ""

EmptyCause represents an empty string for Cause, signifying the absence of a specific reason or explanation.

type HttpHandler

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

HttpHandler serves as an HTTP handler for processing health probe requests based on the Manager's registered probes.

func NewHttpHandler

func NewHttpHandler(manager *Manager) *HttpHandler

NewHttpHandler creates and returns a new instance of HttpHandler with the provided Manager.

func (*HttpHandler) ServeHTTP

func (h *HttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles incoming HTTP requests and returns the status of the specified health probe type.

type Manager

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

Manager provides functionality to manage and monitor health probes for applications through a registry.

func NewManager

func NewManager() *Manager

NewManager creates and returns a new instance of Manager with an initialized probe registry.

func (*Manager) CheckProbe

func (m *Manager) CheckProbe(probeType ProbeType) (bool, Cause)

CheckProbe checks the status of the specified health probe type and returns true if the probe passes, otherwise false.

func (*Manager) RegisterProbe

func (m *Manager) RegisterProbe(probeTypo ProbeType, probe ValidityChecker)

RegisterProbe registers a health probe of the specified type with the provided state retriever in the registry.

type Probe

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

Probe represents a thread-safe structure for tracking validation state and cause.

func NewProbe

func NewProbe(isValid bool) *Probe

NewProbe creates a new probe with the specified initial state.

func NewProbeWithCause

func NewProbeWithCause(isValid bool, cause Cause) *Probe

NewProbeWithCause creates a new probe with the specified initial state.

func (*Probe) IsValid

func (p *Probe) IsValid() (bool, Cause)

IsValid returns the current validation state and its associated cause in a thread-safe manner.

func (*Probe) SetValid

func (p *Probe) SetValid(state bool, cause Cause)

SetValid updates the validation state and cause of the Probe in a thread-safe manner.

type ProbeType

type ProbeType int

ProbeType defines an integer-based enumeration representing different types of health probes for applications.

const (

	// LivenessProbe indicates a probe used to determine if an application is still alive and functioning properly.
	LivenessProbe ProbeType = iota

	// ReadinessProbe indicates a probe used to determine if an application is ready to serve requests.
	ReadinessProbe
)

func (ProbeType) String

func (p ProbeType) String() string

String converts a ProbeType to a string.

type ValidityChecker

type ValidityChecker interface {

	// IsValid validates the current state of an object, returning a boolean indicating validity and a string explaining the reason.
	IsValid() (bool, Cause)
}

ValidityChecker represents an interface for objects capable of validating their state and returning a boolean result. It is used for health checks or determining the validity of various entities within the system.

Directories

Path Synopsis
example
custom_probe command

Jump to

Keyboard shortcuts

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