health

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// OK means health check is passing
	OK Status = 0
	// Failed means health check is responsive, but failing
	Failed = 1
	// Timeout means health check is non-responsive in the given time
	Timeout = 2
	// Unknown means the instance hasn't checked in within the provided time
	// limit.
	Unknown = 3
	// NotRunning means the instance is not running
	NotRunning = 4
)
View Source
const DefaultExpiration time.Duration = time.Minute

DefaultExpiration is the default expiration for deprecated health status updates.

View Source
const DefaultTimeout time.Duration = 30 * time.Second

DefaultTimeout is the default timeout setting used to determine when a health check is non-responsive

View Source
const DefaultTolerance int = 2

DefaultTolerance is the default coefficient used to determine when a health check is expired

Variables

This section is empty.

Functions

This section is empty.

Types

type HealthCheck

type HealthCheck struct {
	Script    string
	Timeout   time.Duration
	Interval  time.Duration
	Tolerance int
	// Kill properties will kill the container if the observed error code is in the error code list
	// and this happens <count>-times.  If the error codes list is empty and the kill count is >0, then any
	// non-zero error code will count toward the kill count.
	KillExitCodes  []int
	KillCountLimit int
	KillCounter    int
}

HealthCheck is the health check object.

func (*HealthCheck) Expires

func (hc *HealthCheck) Expires() time.Duration

Expires calculates the time to live on the cache item.

func (*HealthCheck) GetTimeout

func (hc *HealthCheck) GetTimeout() time.Duration

GetTimeout returns the timeout duration.

func (HealthCheck) MarshalJSON

func (hc HealthCheck) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaller

func (*HealthCheck) NotRunning

func (hc *HealthCheck) NotRunning() HealthStatus

NotRunning returns the health status for a service instance that is not running.

func (*HealthCheck) Ping

func (hc *HealthCheck) Ping(cancel <-chan struct{}, key HealthStatusKey, report func(HealthStatus))

Ping performs the health check on the specified interval.

func (*HealthCheck) Run

func (hc *HealthCheck) Run(key HealthStatusKey) (stat HealthStatus)

Run returns the health status as a result of running the health check script.

func (*HealthCheck) Unknown

func (hc *HealthCheck) Unknown() HealthStatus

Unknown returns the health status for a service instance whose health check response is unknown.

func (*HealthCheck) UnmarshalJSON

func (hc *HealthCheck) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaller

func (HealthCheck) ValidEntity

func (hc HealthCheck) ValidEntity() error

type HealthStatus

type HealthStatus struct {
	Status    Status
	StartedAt time.Time
	Duration  time.Duration
	KillFlag  bool
}

HealthStatus is the output from a provided health check.

type HealthStatusCache

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

HealthStatusCache keeps track of the health status items in memory.

func New

func New() *HealthStatusCache

New returns a new HealthStatusCache instance

func (*HealthStatusCache) Delete

func (cache *HealthStatusCache) Delete(key HealthStatusKey)

Delete removes an item from the cache.

func (*HealthStatusCache) DeleteExpired

func (cache *HealthStatusCache) DeleteExpired()

DeleteExpired removes all expired items from the cache.

func (*HealthStatusCache) DeleteInstance

func (cache *HealthStatusCache) DeleteInstance(serviceID string, instanceID int)

DeleteInstance removes all health checks per instance.

func (*HealthStatusCache) Get

Get returns an item from the cache if it hasn't yet expired.

func (*HealthStatusCache) Set

func (cache *HealthStatusCache) Set(key HealthStatusKey, value HealthStatus, expire time.Duration)

Set sets an item into the cache.

func (*HealthStatusCache) SetPurgeFrequency

func (cache *HealthStatusCache) SetPurgeFrequency(interval time.Duration)

SetPurgeFrequency sets the autopurge interval for cache cleanup. Stops autopurge if interval is <= 0.

func (*HealthStatusCache) Size

func (cache *HealthStatusCache) Size() int

Size returns the size of the cache.

type HealthStatusItem

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

HealthStatusItem is an item stored in the health status cache.

func (*HealthStatusItem) Expired

func (item *HealthStatusItem) Expired() bool

Expired returns true when a health status item has expired in the cache.

func (*HealthStatusItem) Value

func (item *HealthStatusItem) Value() HealthStatus

Value returns the HealthStatus data

type HealthStatusKey

type HealthStatusKey struct {
	ServiceID       string
	InstanceID      int
	HealthCheckName string
}

HealthStatusKey is the key to the health status item in the cache.

type Status

type Status int

Status is the status of a health check

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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