healthcheck

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SourceConfig the check is managed by the configuration file
	SourceConfig string = ""
	// SourceAPI the check is managed by the API
	SourceAPI string = "api"
	// SourceHTTPDiscovery the check was created from the http discovery mechanism
	SourceHTTPDiscovery string = "http-discovery"
)

Variables

This section is empty.

Functions

func MergeLabels

func MergeLabels(base *Base, new map[string]string)

MergeLabels merge labels from a base and a map of string

Types

type Base

type Base struct {
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Interval    Duration          `json:"interval"`
	OneOff      bool              `json:"one-off"`
	Source      string            `json:"source"`
	Labels      map[string]string `json:"labels,omitempty"`
}

Base shared fields between healthchecks

func (*Base) DeepCopy

func (in *Base) DeepCopy() *Base

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Base.

func (*Base) DeepCopyInto

func (in *Base) DeepCopyInto(out *Base)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type CommandHealthcheck

type CommandHealthcheck struct {
	Logger *zap.Logger
	Config *CommandHealthcheckConfiguration
	URL    string

	Tick *time.Ticker
}

CommandHealthcheck defines an HTTP healthcheck

func NewCommandHealthcheck

func NewCommandHealthcheck(logger *zap.Logger, config *CommandHealthcheckConfiguration) *CommandHealthcheck

NewCommandHealthcheck creates a Command healthcheck from a logger and a configuration

func (*CommandHealthcheck) Base

func (h *CommandHealthcheck) Base() Base

Base get the base configuration

func (*CommandHealthcheck) Execute

func (h *CommandHealthcheck) Execute() error

Execute executes an healthcheck on the given domain

func (*CommandHealthcheck) GetConfig

func (h *CommandHealthcheck) GetConfig() interface{}

GetConfig get the config

func (*CommandHealthcheck) Initialize

func (h *CommandHealthcheck) Initialize() error

Initialize the healthcheck.

func (*CommandHealthcheck) LogDebug

func (h *CommandHealthcheck) LogDebug(message string)

LogDebug logs a message with context

func (*CommandHealthcheck) LogError

func (h *CommandHealthcheck) LogError(err error, message string)

LogError logs an error with context

func (*CommandHealthcheck) LogInfo

func (h *CommandHealthcheck) LogInfo(message string)

LogInfo logs a message with context

func (*CommandHealthcheck) MarshalJSON

func (h *CommandHealthcheck) MarshalJSON() ([]byte, error)

MarshalJSON marshal to json a command healthcheck

func (*CommandHealthcheck) SetSource

func (h *CommandHealthcheck) SetSource(source string)

SetSource set the healthcheck source

func (*CommandHealthcheck) Summary

func (h *CommandHealthcheck) Summary() string

Summary returns an healthcheck summary

type CommandHealthcheckConfiguration

type CommandHealthcheckConfiguration struct {
	Base      `json:",inline" yaml:",inline"`
	Command   string   `json:"command"`
	Arguments []string `json:"arguments"`
	Timeout   Duration `json:"timeout"`
}

CommandHealthcheckConfiguration defines a COMMAND healthcheck configuration

func (*CommandHealthcheckConfiguration) DeepCopy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CommandHealthcheckConfiguration.

func (*CommandHealthcheckConfiguration) DeepCopyInto

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*CommandHealthcheckConfiguration) Validate

func (config *CommandHealthcheckConfiguration) Validate() error

Validate validates the healthcheck configuration

type Component

type Component struct {
	Logger       *zap.Logger
	Healthchecks map[string]*Wrapper

	ChanResult chan *Result
	// contains filtered or unexported fields
}

Component is the component which will manage healthchecks

func New

func New(logger *zap.Logger, chanResult chan *Result, promComponent *prometheus.Prometheus, healthchecksLabels []string) (*Component, error)

New creates a new Healthcheck component

func (*Component) AddCheck

func (c *Component) AddCheck(check Healthcheck) error

AddCheck add an healthcheck to the component and starts it.

func (*Component) GetCheck

func (c *Component) GetCheck(name string) Healthcheck

GetCheck returns a check if it exists, otherwise an error.

func (*Component) ListChecks

func (c *Component) ListChecks() []Healthcheck

ListChecks returns the healthchecks currently configured, sorted by name

func (*Component) RemoveCheck

func (c *Component) RemoveCheck(name string) error

RemoveCheck Removes an healthcheck

func (*Component) RemoveNonConfiguredHealthchecks

func (c *Component) RemoveNonConfiguredHealthchecks(oldChecks map[string]bool, newChecks map[string]bool) error

RemoveNonConfiguredHealthchecks takes two list of healthchecks. Delete from the healthcheck component the checks which exist in the first list but not in the second one

func (*Component) SourceChecksNames

func (c *Component) SourceChecksNames(source string) map[string]bool

SourceChecksNames returns all checks managed by the given source

func (*Component) Start

func (c *Component) Start() error

Start start the healthcheck component

func (*Component) Stop

func (c *Component) Stop() error

Stop stop the healthcheck component, stopping all healthchecks being executed.

type DNSHealthcheck

type DNSHealthcheck struct {
	Logger *zap.Logger
	Config *DNSHealthcheckConfiguration
	URL    string

	Tick *time.Ticker
}

DNSHealthcheck defines an HTTP healthcheck

func NewDNSHealthcheck

func NewDNSHealthcheck(logger *zap.Logger, config *DNSHealthcheckConfiguration) *DNSHealthcheck

NewDNSHealthcheck creates a DNS healthcheck from a logger and a configuration

func (*DNSHealthcheck) Base

func (h *DNSHealthcheck) Base() Base

Base get the base configuration

func (*DNSHealthcheck) Execute

func (h *DNSHealthcheck) Execute() error

Execute executes an healthcheck on the given domain

func (*DNSHealthcheck) GetConfig

func (h *DNSHealthcheck) GetConfig() interface{}

GetConfig get the config

func (*DNSHealthcheck) Initialize

func (h *DNSHealthcheck) Initialize() error

Initialize the healthcheck.

func (*DNSHealthcheck) LogDebug

func (h *DNSHealthcheck) LogDebug(message string)

LogDebug logs a message with context

func (*DNSHealthcheck) LogError

func (h *DNSHealthcheck) LogError(err error, message string)

LogError logs an error with context

func (*DNSHealthcheck) LogInfo

func (h *DNSHealthcheck) LogInfo(message string)

LogInfo logs a message with context

func (*DNSHealthcheck) MarshalJSON

func (h *DNSHealthcheck) MarshalJSON() ([]byte, error)

MarshalJSON marshal to json a dns healthcheck

func (*DNSHealthcheck) SetSource

func (h *DNSHealthcheck) SetSource(source string)

SetSource set the healthcheck source

func (*DNSHealthcheck) Summary

func (h *DNSHealthcheck) Summary() string

Summary returns an healthcheck summary

type DNSHealthcheckConfiguration

type DNSHealthcheckConfiguration struct {
	Base        `json:",inline" yaml:",inline"`
	Timeout     Duration `json:"timeout"`
	ExpectedIPs []IP     `json:"expected-ips,omitempty" yaml:"expected-ips,omitempty"`
	Domain      string   `json:"domain"`
}

DNSHealthcheckConfiguration defines a DNS healthcheck configuration

func (*DNSHealthcheckConfiguration) DeepCopy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DNSHealthcheckConfiguration.

func (*DNSHealthcheckConfiguration) DeepCopyInto

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*DNSHealthcheckConfiguration) Validate

func (config *DNSHealthcheckConfiguration) Validate() error

Validate validates the healthcheck configuration

type Duration

type Duration time.Duration

Duration an alias for the duration type

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON marshal to json a duration

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(text []byte) error

UnmarshalJSON marshal to json a duration

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText unmarshal a duration

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML read a duration fom yaml

type HTTPHealthcheck

type HTTPHealthcheck struct {
	Logger *zap.Logger
	Config *HTTPHealthcheckConfiguration
	URL    string

	Tick *time.Ticker

	Client *http.Client
	// contains filtered or unexported fields
}

HTTPHealthcheck defines an HTTP healthcheck

func NewHTTPHealthcheck

func NewHTTPHealthcheck(logger *zap.Logger, config *HTTPHealthcheckConfiguration) *HTTPHealthcheck

NewHTTPHealthcheck creates a HTTP healthcheck from a logger and a configuration

func (*HTTPHealthcheck) Base

func (h *HTTPHealthcheck) Base() Base

Base get the base configuration

func (*HTTPHealthcheck) Execute

func (h *HTTPHealthcheck) Execute() error

Execute executes an healthcheck on the given target

func (*HTTPHealthcheck) GetConfig

func (h *HTTPHealthcheck) GetConfig() interface{}

GetConfig get the config

func (*HTTPHealthcheck) Initialize

func (h *HTTPHealthcheck) Initialize() error

Initialize the healthcheck.

func (*HTTPHealthcheck) LogDebug

func (h *HTTPHealthcheck) LogDebug(message string)

LogDebug logs a message with context

func (*HTTPHealthcheck) LogError

func (h *HTTPHealthcheck) LogError(err error, message string)

LogError logs an error with context

func (*HTTPHealthcheck) LogInfo

func (h *HTTPHealthcheck) LogInfo(message string)

LogInfo logs a message with context

func (*HTTPHealthcheck) MarshalJSON

func (h *HTTPHealthcheck) MarshalJSON() ([]byte, error)

MarshalJSON marshal to json a dns healthcheck

func (*HTTPHealthcheck) SetSource

func (h *HTTPHealthcheck) SetSource(source string)

SetSource set the healthcheck source

func (*HTTPHealthcheck) Summary

func (h *HTTPHealthcheck) Summary() string

Summary returns an healthcheck summary

type HTTPHealthcheckConfiguration

type HTTPHealthcheckConfiguration struct {
	Base        `json:",inline" yaml:",inline"`
	ValidStatus []uint `json:"valid-status" yaml:"valid-status"`
	// can be an IP or a domain
	Target     string            `json:"target"`
	Host       string            `json:"host,omitempty"`
	Method     string            `json:"method"`
	Port       uint              `json:"port"`
	Redirect   bool              `json:"redirect"`
	Body       string            `json:"body,omitempty"`
	Query      map[string]string `json:"query,omitempty"`
	Headers    map[string]string `json:"headers,omitempty"`
	Protocol   Protocol          `json:"protocol"`
	Path       string            `json:"path,omitempty"`
	SourceIP   IP                `json:"source-ip,omitempty" yaml:"source-ip,omitempty"`
	BodyRegexp []Regexp          `json:"body-regexp,omitempty" yaml:"body-regexp,omitempty"`
	Insecure   bool              `json:"insecure"`
	ServerName string            `json:"server-name"`
	Timeout    Duration          `json:"timeout"`
	Key        string            `json:"key,omitempty"`
	Cert       string            `json:"cert,omitempty"`
	Cacert     string            `json:"cacert,omitempty"`
}

HTTPHealthcheckConfiguration defines an HTTP healthcheck configuration

func (*HTTPHealthcheckConfiguration) DeepCopy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPHealthcheckConfiguration.

func (*HTTPHealthcheckConfiguration) DeepCopyInto

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*HTTPHealthcheckConfiguration) Validate

func (config *HTTPHealthcheckConfiguration) Validate() error

Validate validates the healthcheck configuration

type Healthcheck

type Healthcheck interface {
	Initialize() error
	GetConfig() interface{}
	Summary() string
	Execute() error
	LogDebug(message string)
	LogInfo(message string)
	Base() Base
	SetSource(source string)
	LogError(err error, message string)
}

Healthcheck is the interface for an healthcheck

type HealthcheckConfiguration

type HealthcheckConfiguration interface {
	Validate() error
}

HealthcheckConfiguration is the interface for the healthcheck configuration

type IP

type IP net.IP

IP an alias for the IP type

func (*IP) MarshalJSON

func (i *IP) MarshalJSON() ([]byte, error)

MarshalJSON marshal to json an IP

func (*IP) MarshalText

func (i *IP) MarshalText() ([]byte, error)

MarshalText marshal an IP

func (*IP) UnmarshalJSON

func (i *IP) UnmarshalJSON(text []byte) error

UnmarshalJSON unmarshal to json an IP

func (*IP) UnmarshalText

func (i *IP) UnmarshalText(text []byte) error

UnmarshalText unmarshal an IP

type Protocol

type Protocol int

Protocol is the healthcheck http protocol

const (
	// HTTP the HTTP protocol
	HTTP Protocol = 1 + iota
	// HTTPS the HTTPS protocol
	HTTPS
)

func (Protocol) MarshalJSON

func (p Protocol) MarshalJSON() ([]byte, error)

MarshalJSON marshal to json a protocol

func (*Protocol) UnmarshalJSON

func (p *Protocol) UnmarshalJSON(text []byte) error

UnmarshalJSON marshal to json a protocol

func (*Protocol) UnmarshalText

func (p *Protocol) UnmarshalText(text []byte) error

UnmarshalText unmarshal a duration

func (*Protocol) UnmarshalYAML

func (p *Protocol) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML read a protocol fom yaml

type Regexp

type Regexp regexp.Regexp

func (*Regexp) DeepCopy

func (r *Regexp) DeepCopy() *Regexp

DeepCopy implementation

func (*Regexp) DeepCopyInto

func (r *Regexp) DeepCopyInto(out *Regexp)

DeepCopyInto implementation

func (*Regexp) MarshalJSON

func (r *Regexp) MarshalJSON() ([]byte, error)

MarshalJSON marshal to json a Regexp

func (*Regexp) MarshalText

func (r *Regexp) MarshalText() ([]byte, error)

MarshalText marshals Regexp as string

func (*Regexp) UnmarshalJSON

func (r *Regexp) UnmarshalJSON(text []byte) error

UnmarshalJSON unmarshal to json a Regexp

func (*Regexp) UnmarshalText

func (r *Regexp) UnmarshalText(text []byte) error

UnmarshalText unmarshal a duration

type Result

type Result struct {
	Name                 string            `json:"name"`
	Summary              interface{}       `json:"summary"`
	Labels               map[string]string `json:"labels,omitempty"`
	Success              bool              `json:"success"`
	HealthcheckTimestamp int64             `json:"healthcheck-timestamp"`
	Message              string            `json:"message"`
	Duration             int64             `json:"duration"`
	Source               string            `json:"source"`
}

Result represents the result of an healthcheck

func NewResult

func NewResult(healthcheck Healthcheck, duration int64, err error) *Result

NewResult build a a new result for an healthcheck

func (Result) Equals

func (r Result) Equals(v Result) bool

Equals implements Equals for Result

type TCPHealthcheck

type TCPHealthcheck struct {
	Logger *zap.Logger
	Config *TCPHealthcheckConfiguration
	URL    string

	Tick *time.Ticker
	// contains filtered or unexported fields
}

TCPHealthcheck defines a TCP healthcheck

func NewTCPHealthcheck

func NewTCPHealthcheck(logger *zap.Logger, config *TCPHealthcheckConfiguration) *TCPHealthcheck

NewTCPHealthcheck creates a TCP healthcheck from a logger and a configuration

func (*TCPHealthcheck) Base

func (h *TCPHealthcheck) Base() Base

Base get the base configuration

func (*TCPHealthcheck) Execute

func (h *TCPHealthcheck) Execute() error

Execute executes an healthcheck on the given target

func (*TCPHealthcheck) GetConfig

func (h *TCPHealthcheck) GetConfig() interface{}

GetConfig get the config

func (*TCPHealthcheck) Initialize

func (h *TCPHealthcheck) Initialize() error

Initialize the healthcheck.

func (*TCPHealthcheck) LogDebug

func (h *TCPHealthcheck) LogDebug(message string)

LogDebug logs a message with context

func (*TCPHealthcheck) LogError

func (h *TCPHealthcheck) LogError(err error, message string)

LogError logs an error with context

func (*TCPHealthcheck) LogInfo

func (h *TCPHealthcheck) LogInfo(message string)

LogInfo logs a message with context

func (*TCPHealthcheck) MarshalJSON

func (h *TCPHealthcheck) MarshalJSON() ([]byte, error)

MarshalJSON marshal to json a dns healthcheck

func (*TCPHealthcheck) SetSource

func (h *TCPHealthcheck) SetSource(source string)

SetSource set the healthcheck source

func (*TCPHealthcheck) Summary

func (h *TCPHealthcheck) Summary() string

Summary returns an healthcheck summary

type TCPHealthcheckConfiguration

type TCPHealthcheckConfiguration struct {
	Base `json:",inline" yaml:",inline"`
	// can be an IP or a domain
	Target     string   `json:"target"`
	Port       uint     `json:"port"`
	SourceIP   IP       `json:"source-ip,omitempty" yaml:"source-ip,omitempty"`
	Timeout    Duration `json:"timeout"`
	ShouldFail bool     `json:"should-fail" yaml:"should-fail"`
}

TCPHealthcheckConfiguration defines a TCP healthcheck configuration

func (*TCPHealthcheckConfiguration) DeepCopy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TCPHealthcheckConfiguration.

func (*TCPHealthcheckConfiguration) DeepCopyInto

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*TCPHealthcheckConfiguration) Validate

func (config *TCPHealthcheckConfiguration) Validate() error

Validate validates the healthcheck configuration

type TLSHealthcheck

type TLSHealthcheck struct {
	Logger    *zap.Logger
	Config    *TLSHealthcheckConfiguration
	URL       string
	TLSConfig *cryptotls.Config

	Tick *time.Ticker
	// contains filtered or unexported fields
}

TLSHealthcheck defines a TLS healthcheck

func NewTLSHealthcheck

func NewTLSHealthcheck(logger *zap.Logger, config *TLSHealthcheckConfiguration) *TLSHealthcheck

NewTLSHealthcheck creates a TLS healthcheck from a logger and a configuration

func (*TLSHealthcheck) Base

func (h *TLSHealthcheck) Base() Base

Base get the base configuration

func (*TLSHealthcheck) Execute

func (h *TLSHealthcheck) Execute() error

Execute executes an healthcheck on the given target

func (*TLSHealthcheck) GetConfig

func (h *TLSHealthcheck) GetConfig() interface{}

GetConfig get the config

func (*TLSHealthcheck) Initialize

func (h *TLSHealthcheck) Initialize() error

Initialize the healthcheck.

func (*TLSHealthcheck) LogDebug

func (h *TLSHealthcheck) LogDebug(message string)

LogDebug logs a message with context

func (*TLSHealthcheck) LogError

func (h *TLSHealthcheck) LogError(err error, message string)

LogError logs an error with context

func (*TLSHealthcheck) LogInfo

func (h *TLSHealthcheck) LogInfo(message string)

LogInfo logs a message with context

func (*TLSHealthcheck) MarshalJSON

func (h *TLSHealthcheck) MarshalJSON() ([]byte, error)

MarshalJSON marshal to json a dns healthcheck

func (*TLSHealthcheck) SetSource

func (h *TLSHealthcheck) SetSource(source string)

SetSource set the healthcheck source

func (*TLSHealthcheck) Summary

func (h *TLSHealthcheck) Summary() string

Summary returns an healthcheck summary

type TLSHealthcheckConfiguration

type TLSHealthcheckConfiguration struct {
	Base `json:",inline" yaml:",inline"`
	// can be an IP or a domain
	Target          string   `json:"target"`
	Port            uint     `json:"port"`
	SourceIP        IP       `json:"source-ip,omitempty" yaml:"source-ip,omitempty"`
	Timeout         Duration `json:"timeout"`
	Key             string   `json:"key,omitempty"`
	Cert            string   `json:"cert,omitempty"`
	Cacert          string   `json:"cacert,omitempty"`
	ServerName      string   `json:"server-name,omitempty" yaml:"server-name"`
	Insecure        bool     `json:"insecure"`
	ExpirationDelay Duration `json:"expiration-delay" yaml:"expiration-delay"`
}

TLSHealthcheckConfiguration defines a TLS healthcheck configuration

func (*TLSHealthcheckConfiguration) DeepCopy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TLSHealthcheckConfiguration.

func (*TLSHealthcheckConfiguration) DeepCopyInto

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*TLSHealthcheckConfiguration) Validate

func (config *TLSHealthcheckConfiguration) Validate() error

Validate validates the healthcheck configuration

type Wrapper

type Wrapper struct {
	Tick *time.Ticker
	// contains filtered or unexported fields
}

Wrapper Wrap an healthcheck

func NewWrapper

func NewWrapper(healthcheck Healthcheck) *Wrapper

NewWrapper creates a new wrapper struct

func (*Wrapper) Stop

func (w *Wrapper) Stop() error

Stop an Healthcheck wrapper

Jump to

Keyboard shortcuts

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