healthcheck

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 4 Imported by: 0

README

Healthcheck 🩺

This package provides a powerful interface for managing liveness and readiness checks within your Kubernetes deployments. Ensuring the health and readiness of your applications is crucial for maintaining their reliability and availability in production environments. With this package, you can easily integrate healthcheck handlers into your Kubernetes deployments to monitor the status of your applications.

Contribution:

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

Let's keep our applications healthy and ready to serve! 💪🚀


Checker:

There are 2 types of k8s checks probes

  • Liveness Checks: Monitor the health of your application instances to ensure continuous operation.
  • Readiness Checks: Determine when application instances are ready to serve traffic to users.
Documentation:

For detailed documentation on how to use the Healthcheck Package for Kubernetes, please refer to the external documentation.

Example Code:
package main

import (
    "net/http"
    "github.com/catalystgo/healthcheck"
)

func main() {
    // Create a new healthcheck handler
    handler := healthcheck.NewHandler()

    // Add liveness and readiness checks
    handler.AddLivenessCheck("database", func() error {
        // Check database connection
        // Return nil if connection is successful, otherwise return an error
    })

    handler.AddReadinessCheck("cache", func() error {
        // Check cache availability
        // Return nil if cache is available, otherwise return an error
    })

    // Add check error handler (optional)
    handler.AddCheckErrorHandler(func(name string, err error) {
        // Handle check error
        // Log the error or take appropriate action
    })

    // Serve healthcheck endpoints
    http.Handle(healthcheck.LivenessHandlerPath, handler)
    http.Handle(healthcheck.ReadinessHandlerPath, handler)
    http.ListenAndServe(":8080", nil)
}

Documentation

Index

Constants

View Source
const (
	// LivenessHandlerPath path to process liveness probe.
	LivenessHandlerPath = "/live"
	// ReadinessHandlerPath path to process readiness probe.
	ReadinessHandlerPath = "/ready"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check func() error

Check signature of check proccess function

type ErrorHandler

type ErrorHandler func(name string, err error)

ErrorHandler error handler's signature for failed checks.

type Handler

type Handler interface {
	// Handler is http.Handler, so it can be exposed directly and processed
	// /live and /ready endpoints.
	http.Handler

	// AddLivenessCheck adds a check indicating that this instance
	// of the application should be destroyed or restarted. A failed liveness check
	// indicates that this instance is not running.
	// Each liveness check is also included as a readiness check.
	AddLivenessCheck(name string, check Check)

	// AddReadinessCheck adds a check indicating that this
	// application instance is currently unable to serve requests due to an external
	// dependency or some kind of temporary failure. If the readiness check fails, this instance
	// should no longer receive requests, but it should not be restarted or destroyed.
	AddReadinessCheck(name string, check Check)

	// LiveEndpoint is an HTTP handler for the /live endpoint only, which
	// is useful if you need to add it to your own HTTP handler tree.
	LiveEndpoint(http.ResponseWriter, *http.Request)

	//ReadyEndpoint is an HTTP handler for the /ready endpoint only, which
	// is useful if you need to add it to your own HTTP handler tree.
	ReadyEndpoint(http.ResponseWriter, *http.Request)

	// AddCheckErrorHandler adds a callback to process a failed check (in order to log errors, etc.).
	AddCheckErrorHandler(handler ErrorHandler)
}

Handler is a wrapper over http.Handler, allowing you to add liveness and readiness checks

func NewHandler

func NewHandler() Handler

NewHandler creates a new basic Handler

Directories

Path Synopsis
checker
db
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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