healthcheck

package
v1.1.89 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: Apache-2.0 Imports: 18 Imported by: 13

README

Healthchecks

Adding a healthcheck

  • Create a function that implements the CheckStatus type (func(name string) *Status)
    • The name that is sent in will be the name set on Registration
    • Return a pointer to the Status object created in teh function
  • Register the healthcheck by calling RegisterHealthcheck providing a name, endpoint, and the CheckStatus function
  • this function will also add an endpoint to the http library at /status/[endpoint]
  • Healthcheck is now registered

Starting the healthcheck server

  • Within the agent definition make a call to HandleRequests
    • If a new HTTP server should be started provide a port number greater than 0
    • If the HTTP server should not be started provide a 0 as the port number
  • This method will register the /status endpoint with the http library

Check all healthchecks

  • Call the RunChecks function, which will return either an OK or FAIL status

Wait for all healthchecks to Pass

  • Call the WaitForReady function, once it returns all healthchecks have passed

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyRunning = errors.New(1613, "terminating agent, another instance of agent already running")
)

Healthcheck errors

Functions

func CheckIsRunning

func CheckIsRunning() error

CheckIsRunning - Checks if another instance is already running by looking at the healthcheck.

func GetGlobalStatus

func GetGlobalStatus() (string, string)

GetGlobalStatus - return the status of the global health checker

func GetHealthcheckOutput

func GetHealthcheckOutput(url string) (string, error)

GetHealthcheckOutput - query the http endpoint and return the body

func GetStatusConfig

func GetStatusConfig() corecfg.StatusConfig

GetStatusConfig - Set the status config globally

func QueryForStatus

func QueryForStatus(port int) (statusOut string)

QueryForStatus - create a URL string and call teh GetHealthcheckOutput func

func RegisterHealthcheck

func RegisterHealthcheck(name, endpoint string, check CheckStatus) (string, error)

RegisterHealthcheck - register a new dependency with this service

func SetNameAndVersion

func SetNameAndVersion(name, version string)

SetNameAndVersion - sets the name and version of the globalHealthChecker

func SetStatusConfig

func SetStatusConfig(statusCfg corecfg.StatusConfig)

SetStatusConfig - Set the status config globally.

func StartPeriodicHealthCheck

func StartPeriodicHealthCheck()

StartPeriodicHealthCheck - starts a job that runs the periodic health checks

Types

type CheckStatus

type CheckStatus func(name string) *Status

CheckStatus - the format expected for the method to get the Healthcheck status

type GetStatusLevel

type GetStatusLevel func(endpoint string) StatusLevel

GetStatusLevel format for the function to get the StatusLevel of an endpoint

type RegisterHealth

type RegisterHealth func(name, endpoint string, check CheckStatus) (string, error)

RegisterHealth is for registering a healthcheck function

type Server

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

Server contains an http server for health checks.

func NewServer added in v1.1.40

func NewServer(httpprof bool) *Server

func (*Server) HandleRequests

func (s *Server) HandleRequests()

HandleRequests - starts the http server

type Status

type Status struct {
	Result  StatusLevel `json:"result"`
	Details string      `json:"details,omitempty"`
}

Status - the status of this healthcheck

type StatusLevel

type StatusLevel string

StatusLevel - the level of the status of the healthcheck

const (
	// OK - healthcheck is running properly
	OK StatusLevel = "OK"
	// FAIL - healthcheck is failing
	FAIL StatusLevel = "FAIL"
)

func GetStatus

func GetStatus(endpoint string) StatusLevel

GetStatus - returns the current status for specified service

func RunChecks

func RunChecks() StatusLevel

RunChecks - loop through all

Jump to

Keyboard shortcuts

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