healing

package module
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: Apache-2.0, MIT Imports: 12 Imported by: 4

README

Healing Go Reference

Healing is package contains a liveness and readiness controllers, compatible with squad package. Also contains postgresql and mysql pools with readiness checker.

Usage

package main

import (
	"context"
	"time"

	"github.com/moeryomenko/healing"
	"github.com/moeryomenko/healing/checkers"
	"github.com/moeryomenko/squad"
)

func main() {
	ctx := context.Background()

	// create health/readiness controller.
	h := healing.New(8081 // health controller port.
		healing.WithCheckPeriod(3 * time.Second),
		healing.WithReadinessTimeout(time.Second),
		healing.WithReadyEndpoint("/readz"),
	)

	// add pool readiness controller to readiness group.
	h.AddReadyChecker("pgx", checkers.PgxReadinessProber(pool))

	// create squad group runner.
	s := squad.NewSquad(squad.WithSiganlHandler())

	// run health/readiness controller in squad group.
	s.RunGracefully(h.Heartbeat, h.Stop)

	...

	s.Wait()
}

License

Healing is primarily distributed under the terms of both the MIT license and Apache License (Version 2.0).

See LICENSE-APACHE and/or LICENSE-MIT for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckGroup

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

CheckGroup launch checker concurrently.

func NewCheckGroup

func NewCheckGroup(timeout time.Duration) *CheckGroup

NewCheckGroup returns new instacnce CheckGroup.

func (*CheckGroup) AddChecker

func (g *CheckGroup) AddChecker(subsystem string, checker checkFunc)

AddChecker adds checker to CheckGroup.

func (*CheckGroup) Check

func (g *CheckGroup) Check(ctx context.Context)

Check runs checkers.

func (*CheckGroup) GetDetails added in v1.0.0

func (g *CheckGroup) GetDetails() map[string]CheckResult

GetDetails returns result of checks.

func (*CheckGroup) IsOK

func (g *CheckGroup) IsOK() bool

IsOK returns true if all checks passed normal.

type CheckResult added in v1.0.0

type CheckResult struct {
	Error  error           `json:"error,omitempty"`
	Status SubsystemStatus `json:"status"`
}

type Health

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

func New

func New(port int, opts ...Option) *Health

func (*Health) AddLiveChecker

func (h *Health) AddLiveChecker(subsystem string, check checkFunc)

AddLiveChecker adds a check routine for `live` state of your service to the registry. Service health check only applies to internal components, whose state identifies the service liveness. see https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#when-should-you-use-a-liveness-probe.

func (*Health) AddReadyChecker

func (h *Health) AddReadyChecker(subsystem string, check checkFunc)

AddReadyChecker adds a check routine for `ready` state of your service to the registry. Service readiness check only applies to external dependencies, whose state identifies the service readiness to accept load. see https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#when-should-you-use-a-readiness-probe.

func (*Health) AddSubsystem added in v1.14.1

func (h *Health) AddSubsystem(subsystem string, liveness, readiness checkFunc)

AddSubsystem adds liveness and readiness checks for given subsystem. For more details see AddLiveChecker and AddReadChecker.

func (*Health) Heartbeat

func (h *Health) Heartbeat(ctx context.Context) error

Heartbeat periodically run all checkers for both `live` and `ready` states.

func (*Health) Stop added in v1.5.0

func (h *Health) Stop(ctx context.Context) error

Stop shutdowns health controller http server and health controller.

type Option

type Option func(*Health)

func WithCheckPeriod

func WithCheckPeriod(period time.Duration) Option

WithCheckPeriod sets period of launch checks.

func WithHealthzEndpoint

func WithHealthzEndpoint(endpoint string) Option

WithHealthzEndpoint sets custom endpoint to probe liveness.

func WithLivenessTimeout

func WithLivenessTimeout(timeout time.Duration) Option

WithLivenessTimeout sets custom timeout for check liveness.

func WithMetrics added in v1.9.0

func WithMetrics(endpoint string) Option

WithMetrics sets route for metrics handler.

func WithPProf added in v1.9.0

func WithPProf() Option

WithProfiling exposes pprof handlers.

func WithReadinessTimeout

func WithReadinessTimeout(timeout time.Duration) Option

WithReadinessTimeout sets custom timeout for check readiness.

func WithReadyEndpoint

func WithReadyEndpoint(endpoint string) Option

WithReadyEndpoint sets custom endpoint to probe readiness.

func WithRequestTimeout added in v1.8.0

func WithRequestTimeout(timeout time.Duration) Option

WithRequestTimeout sets http server write timeout. see: https://github.com/golang/go/blob/180bcad33dcd3d59443fe8eda5ae7556b1b2945b/src/net/http/server.go#L978-L986.

type SubsystemStatus added in v1.6.0

type SubsystemStatus string
const (
	UP   SubsystemStatus = "UP"
	DOWN SubsystemStatus = "DOWN"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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