health

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK   = "OK"
	WARN = "WARN"
	CRIT = "CRIT"

	TypeInternal   = "internal"
	TypeService    = "service"
	TypeThirdParty = "third-party"
)

Variables

View Source
var (

	//CriticalLevels starts with 1 since 0 will be the value for invalid keys
	CriticalLevels = map[string]int{
		OK:   1,
		WARN: 2,
		CRIT: 3,
	}
)

Functions

func IsMoreCritical added in v1.2.1

func IsMoreCritical(a string, b string) bool

IsMoreCritical checks if a's status level is more critical than b

func UpTime

func UpTime() int64

UpTime is the application up time.

Types

type AdditionalHealthData

type AdditionalHealthData struct {
	DependencyChecks []HealthChecker
	//The custom data can override the default health detail values
	DataProvider func(*gin.Context) map[string]interface{}

	//Description is set in server.RegisterDetailedHealth function, so there is no need
	//to set this field when initializing AdditionalHealthData struct
	Description string
}

type AppInfo

type AppInfo struct {
	Version  string
	Revision string

	AppName  string `env:"APPLICATION_NAME"`
	Hostname string `env:"HOSTNAME"`
}

func (*AppInfo) FillFromENV

func (ai *AppInfo) FillFromENV(version, revision string) *AppInfo

FillFromENV will load pre-dfined values for env tags from environment variables

type DependencyInfo

type DependencyInfo struct {
	Name         string          `json:"name"`
	Type         string          `json:"type"`
	Version      string          `json:"version"`
	Revision     string          `json:"revision"`
	State        DependencyState `json:"state"`
	ResponseTime float64         `json:"responseTime"`
}

type DependencyState

type DependencyState struct {
	Status  string `json:"status"`
	Details string `json:"details,omitempty"`
}

type Health

type Health map[string]interface{}

*

// To make data for detailed health check:
h := NewDetailedHealth(c, "some...")
d := DependencyInfo{...}
h.AddDependency(d) // Add as many dependencies as needed.

func NewDetailedHealth

func NewDetailedHealth(ai *AppInfo, pi *ProjectInfo, description string) Health

NewDetailedHealth creates a health struct without any dependency.

func NewSimpleHealth

func NewSimpleHealth(ai *AppInfo, status string) Health

NewSimpleHealth creates a health struct that can be rendered for the simple health check.

func (Health) AddDependency

func (h Health) AddDependency(d *DependencyInfo)

func (Health) SetDependencies

func (h Health) SetDependencies(d []DependencyInfo)

type HealthChecker

type HealthChecker interface {
	Check() *DependencyInfo
	GetName() string
	GetType() string
}

type ProjectInfo

type ProjectInfo struct {
	Repo   string   `json:"repo"   env:"PROJECT_REPO"`
	Home   string   `json:"home"   env:"PROJECT_HOME"`
	Owners []string `json:"owners"`
	Logs   []string `json:"logs"`
	Stats  []string `json:"stats"`

	OwnersStr string `json:"-" env:"PROJECT_OWNERS"`
	LogsStr   string `json:"-" env:"PROJECT_LOG_URLS"`
	StatsStr  string `json:"-" env:"PROJECT_STATS_URLS"`
}

func (*ProjectInfo) FillFromENV

func (pi *ProjectInfo) FillFromENV() *ProjectInfo

FillFromENV will load pre-dfined values for env tags from environment variables

type SQLCheck

type SQLCheck struct {
	Name string
	Type string
	DB   interface{}
}

func (SQLCheck) Check

func (sc SQLCheck) Check() *DependencyInfo

func (SQLCheck) GetName

func (sc SQLCheck) GetName() string

func (SQLCheck) GetType

func (sc SQLCheck) GetType() string

type WebCheck

type WebCheck struct {
	Name string
	URL  string
	Type string
	//ExpectedStatusCode should only be set when you expect a specific response code from
	//the health check. If it is set to a code > 0, when the response code is the same,
	//the dependency state status will be OK; otherwise it will be CRIT. I.e., if
	//you set it to 404, then when the response code is 404, the status will be OK.
	//This is mainly for checking some web server that does not implement a proper
	//health endpoint and you have to compromise the approach to check it.
	ExpectedStatusCode int
}

func (WebCheck) Check

func (wc WebCheck) Check() *DependencyInfo

func (WebCheck) GetName

func (wc WebCheck) GetName() string

func (WebCheck) GetType

func (wc WebCheck) GetType() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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