physical

package module
v0.0.0-...-b32e693 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

README

Physical

Go Report Card

Health Checks for Go

Compatible with DropWizard-style health checks, and extends it with more fields

Purpose

Make a very simple way of adding custom health checks for your services.

Usage

Given you use gorilla-mux you can use this as:

import "github.com/alde/physical"
...

...
  path := "/healthcheck"
  router := mux.NewRouter().StrictSlash(true)
  physical.CreateHealthCheck(router, path)

  check := func() physical.HealthCheckResponse {
    return physical.HealthCheckResponse{
      Actionable: true,
      Healthy:    true,
      Name:       "Sample Check",
      Type:       physical.TypeSelf,
    }
  }
  physical.AddCheck(check)
...

AddCheck takes a func() physical.HealthCheckResponse

Response Structure

Calls to the healthcheck endpoint will respond with:

Status: 200 OK or 500 Internal Server Error depending on whether there are failing checks or not.

Response Object:

{
  "healthy": [
    ...
  ],
  "unhealthy": [
    ...
  ]
}

the healthy or unhealthy fields contains:

{
  // True or False depending on whether an action can be taken to resolve.
  "actionable": true,
  // True or False depending on whether a check is healthy
  "healthy": true,
  // Name of the check
  "name": "A Sample Check",
  // Type of the check. Constants are provided for:
  // SELF, METRICS, INFRASTRUCTURE, INTERNAL_DEPENDENCY, EXTERNAL_DEPENDENCY, INTERNET_CONNECTIVITY
  "type": "The type of check",
  // Severity of the check. Should be included on failing checks.
  // Constants are provided for: CRITICAL,WARNING, DOWN
  "severity": "CRITICAL",
  // A message attached to the check status. Should be included on failing checks.
  "message": "A message with more information",
  // Services this service is dependent on
  "dependent_on": {
    "service_name": "Name of upstream service"
  },
  // Additional information that can be useful
  "additional_info": {
    "foo": "bar"
  },
  // A link with more information, for example an incident matrix
  "link": "https://www.wolframalpha.com/input/?i=why+are+firetrucks+red%3F"
}

License

See LICENSE file.

Documentation

Index

Constants

View Source
const (
	SeverityCritical = "CRITICAL"
	SeverityWarning  = "WARNING"
	SeverityDown     = "DOWN"

	TypeSelf                 = "SELF"
	TypeMetrics              = "METRICS"
	TypeInfrastructure       = "INFRASTRUCTURE"
	TypeInternalDependency   = "INTERNAL_DEPENDENCY"
	TypeExternalDependency   = "EXTERNAL_DEPENDENCY"
	TypeInternetConnectivity = "INTERNET_CONNECTIVITY"
)

Convenience constants

Variables

This section is empty.

Functions

func AddCheck

func AddCheck(hc func() HealthCheckResponse)

AddCheck is used to add more checks

func CreateHealthCheck

func CreateHealthCheck(router *mux.Router, path string)

CreateHealthCheck is used to create a healthcheck on the given route

Types

type Dependency

type Dependency struct {
	Name string `json:"service_name,omitempty"`
}

The Dependency struct holds the name of an upstream service that the health check depends on for it's status.

type HealthCheckResponse

type HealthCheckResponse struct {
	Actionable     bool                   `json:"actionable"`
	Healthy        bool                   `json:"healthy"`
	Name           string                 `json:"name"`
	Type           string                 `json:"type"`
	Severity       string                 `json:"severity,omitempty"`
	Message        string                 `json:"message,omitempty"`
	Dependency     Dependency             `json:"dependent_on,omitempty"`
	AdditionalInfo map[string]interface{} `json:"additional_info,omitempty"`
	Link           string                 `json:"link,omitempty"`
}

The HealthCheckResponse struct defines the return type of a HealthCheck call

Jump to

Keyboard shortcuts

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