GithubHelp home page GithubHelp logo

isabella232 / go-healthz-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pantheon-systems/go-healthz

0.0 0.0 0.0 10 KB

Package that implements a healthcheck server

License: Apache License 2.0

Go 100.00%

go-healthz-1's Introduction

go-healthz

Unsupported

go get gopkg.in/pantheon-systems/go-healthz.v1

Package that implements a healthz healthcheck server.

Inspired by kelseyhightower:

Add a Healthz() function to your application components, and then register them with this package along with a type and description by adding them to config.Providers. This package creates a HTTP server that runs all the registered handlers when hitting /healthz and returns any errors.

This server does not use TLS, as most of our applications already run their own TLS servers. One approach is to not expose this server's port directly (except for exposing the basic handler for Kube's liveness and readiness), and rather call the healthz handler internally from a TLS handler that you add to your main TLS server.

Example usage

Setup and calling

logger = logrus.WithField("component", "healthz")
config = healthz.Config{
    BindPort: 8080,
    BindAddr: "localhost",
    Hostname: "pod1",  // empty string will autodetect
    Providers: []healthz.ProviderInfo{
        {
            Type:        "DBConn",
            Description: "Ensure the database is reachable",
            Check: db, // `db` implements `healthz.HealthCheckable()`
        },
        {
            Type:        "Metric",
            Description: "Watch a key metric for failure",
            Check: service, // `service` implements `healthz.HealthCheckable()`
        },
    },
    Log: logger, // logrus
    ServerErrorLog: stdlog.New(logger.Logger.Writer(), "", 0), // stdlib log helper that sends http.Server errors to logrus.
}
healthServer, err := healthz.New(config)
if err != nil {
    return err
}
go healthServer.StartHealthz()

Sensu

Can be used as a Sensu check with the http plugin, for example:

"command": "/path/to/ruby /path/to/check-http.rb
  -c /path/to/client/cert/cert.pem
  -q '\"Errors\":null'
  -C /path/to/ca.crt
  -u https://my.service.com/healthz"

Sensu alerts when the check either returns non-200 response, or does not contain "Errors": null in the body. This is useful as it communicates the error message and nature of the failure to the person reading the check result.

go-healthz-1's People

Contributors

greg-1-anderson avatar kporras07 avatar marktheunissen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.