gohc

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: MIT Imports: 27 Imported by: 1

README

Gohc

Library for making different type of healthchecks with a common interface.

Different type are:

  • Http(s): which allow HTTP1, HTTP2 and HTTP3 healthcheck and can send data, check for multiple statuses and check for received data.
  • Tcp: which allow TCP healthcheck by trying to connect in tcp send data if set and check for received data if set.
  • GRPC: Perform grpc healthcheck defined in https://github.com/grpc/grpc/blob/master/doc/health-checking.md
  • Program: Execute a program by passing config (json format) in stdin and check for exit code.
  • ICMP (a.k.a ping): Perform icmp healthcheck by sending icmp echo request and check for icmp echo reply.
  • UDP: there is two methods for udp healthcheck:
    • Send data and check for received data.
    • A weaker method which ping the server first and then send data over udp and wait until timeout to ensure to not receive Port Unreachable ICMP error. This method require root privileges to capture this ICMP reply.

Note: Types http, Tcp, GRPC and Program allow tls support. You can, for example, do tcp+tls test.

Usage

Go to examples folder to see how to use it.

Documentation

Index

Constants

View Source
const (
	DefaultUdpSend = "test-gohc"
)

Variables

View Source
var (
	CodecClientType_name = map[int32]string{
		0: "HTTP1",
		1: "HTTP2",
		2: "HTTP3",
	}
	CodecClientType_value = map[string]int32{
		"HTTP1": 0,
		"HTTP2": 1,
		"HTTP3": 2,
	}
)

Enum value maps for CodecClientType.

Functions

func FormatHost

func FormatHost(host string, altPort uint32) (string, error)

Types

type CodecClientType

type CodecClientType int32
const (
	CodecClientType_HTTP1 CodecClientType = 0
	CodecClientType_HTTP2 CodecClientType = 1
	// [#not-implemented-hide:] QUIC implementation is not production ready yet. Use this enum with
	// caution to prevent accidental execution of QUIC code. I.e. `!= HTTP2` is no longer sufficient
	// to distinguish HTTP1 and HTTP2 traffic.
	CodecClientType_HTTP3 CodecClientType = 2
)

type GrpcHealthCheck

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

func NewGrpcHealthCheck

func NewGrpcHealthCheck(opt *GrpcOpt) *GrpcHealthCheck

func (*GrpcHealthCheck) Check

func (h *GrpcHealthCheck) Check(host string) error

type GrpcOpt

type GrpcOpt struct {
	// An optional service name parameter which will be sent to gRPC service in
	// `grpc.health.v1.HealthCheckRequest
	// <https://github.com/grpc/grpc/blob/master/src/proto/grpc/health/v1/health.proto#L20>`_.
	// message. See `gRPC health-checking overview
	// <https://github.com/grpc/grpc/blob/master/doc/health-checking.md>`_ for more information.
	ServiceName string
	// The value of the :authority header in the gRPC health check request. If
	// left empty (default value) this will be host in check.
	// The authority header can be customized for a specific endpoint by setting
	// the HealthCheckConfig.hostname field.
	Authority string
	// Timeout for the gRPC health check request. If left empty (default to 5s)
	Timeout time.Duration
	// TlsEnabled set to true if the gRPC health check request should be sent over TLS.
	TlsEnabled bool
	// TlsConfig specifies the TLS configuration to use for TLS enabled gRPC health check requests.
	TlsConfig *tls.Config
	// AltPort specifies the port to use for gRPC health check requests.
	// If left empty it taks the port from host during check.
	AltPort uint32
}

GrpcOpt Describes the gRPC health check specific options.

type HealthChecker

type HealthChecker interface {
	Check(host string) error
}

type HttpHealthCheck

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

func NewHttpHealthCheck

func NewHttpHealthCheck(opt *HttpOpt) *HttpHealthCheck

func (*HttpHealthCheck) Check

func (h *HttpHealthCheck) Check(host string) error

type HttpOpt

type HttpOpt struct {
	// The value of the host header in the HTTP health check request
	Host string
	// Specifies the HTTP path that will be requested during health checking. For example
	// */healthcheck*.
	Path string
	// HTTP specific payload.
	Send *Payload
	// HTTP specific response.
	Receive *Payload
	// Specifies a list of HTTP headers that should be added to each request that is sent to the
	// health checked cluster.
	Headers http.Header
	// Specifies a list of HTTP response statuses considered healthy. If provided, replaces default
	// 200-only policy - 200 must be included explicitly as needed. Ranges follow half-open
	// semantics of Int64Range. The start and end of each
	ExpectedStatuses *IntRange
	// Use specified application protocol for health checks.
	CodecClientType CodecClientType
	// HTTP Method that will be used for health checking, default is "GET".
	// If a non-200 response is expected by the method, it needs to be set in expected_statuses.
	Method string
	// Timeout for the http health check request. If left empty (default to 5s)
	Timeout time.Duration
	// TlsEnabled set to true if the gRPC health check request should be sent over TLS.
	TlsEnabled bool
	// TlsConfig specifies the TLS configuration to use for TLS enabled gRPC health check requests.
	TlsConfig *tls.Config
	// AltPort specifies the port to use for gRPC health check requests.
	// If left empty it taks the port from host during check.
	AltPort uint32
}

HttpOpt Describes the health check policy for a given endpoint.

type IcmpHealthCheck

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

func NewIcmpHealthCheck

func NewIcmpHealthCheck(opt *IcmpOpt) *IcmpHealthCheck

func (*IcmpHealthCheck) Check

func (h *IcmpHealthCheck) Check(host string) error

type IcmpOpt

type IcmpOpt struct {
	// Timeout for ping response. If left empty (default to 5s)
	Timeout time.Duration
	// Delay specifies the delay between ICMP reply read try. If left empty (default to 1s)
	Delay time.Duration
}

type IntRange

type IntRange struct {
	// start of the range (inclusive)
	Start int64
	// end of the range (exclusive)
	End int64
}

IntRange Specifies the int64 start and end of the range using half-open interval semantics [start, end).

type NoHealthCheck

type NoHealthCheck struct {
}

func NewNoHealthCheck

func NewNoHealthCheck() *NoHealthCheck

func (*NoHealthCheck) Check

func (h *NoHealthCheck) Check(host string) error

type Payload

type Payload struct {
	// Text payload
	Text string
	// Binary payload.
	Binary []byte
}

Payload Describes the encoding of the payload bytes in the payload. It can be either text or binary.

func (*Payload) GetData

func (pc *Payload) GetData() []byte

type ProgramHealthCheck

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

func NewProgramHealthCheck

func NewProgramHealthCheck(opt *ProgramOpt) *ProgramHealthCheck

func (*ProgramHealthCheck) Check

func (h *ProgramHealthCheck) Check(host string) error

type ProgramOpt

type ProgramOpt struct {
	// The path to the executable.
	Path string
	// The arguments to pass to the executable.
	Args []string
	// Options to pass to the executable.
	Options map[string]any
	// Timeout program finish. If left empty (default to 5s)
	Timeout time.Duration
	// TlsEnabled set to true if the gRPC health check request should be sent over TLS.
	TlsEnabled bool
	// Tls configuration for program
	ProgramTlsConfig *ProgramTlsOpt
	// AltPort specifies the port to use for gRPC health check requests.
	// If left empty it taks the port from host during check.
	AltPort uint32
}

type ProgramTlsOpt

type ProgramTlsOpt struct {
	// Set to true to not verify the server's certificate. This is strongly discouraged.
	InsecureSkipVerify bool
	// ServerName is used to verify the hostname on the returned
	ServerName string
	// Trusted CA certificates for verifying the server certificate. It must be in pem format
	RootCAs []string
}

type TcpHealthCheck

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

func NewTcpHealthCheck

func NewTcpHealthCheck(opt *TcpOpt) *TcpHealthCheck

func (*TcpHealthCheck) Check

func (h *TcpHealthCheck) Check(host string) error

type TcpOpt

type TcpOpt struct {
	// TCP specific payload.
	// Empty payloads imply a connect-only health check.
	Send *Payload
	// When checking the response, “fuzzy” matching is performed such that each
	// binary block must be found, and in the order specified, but not
	// necessarily contiguous.
	Receive []*Payload
	// Timeout for connection and for each receive data. If left empty (default to 5s)
	Timeout time.Duration
	// TlsEnabled set to true if the gRPC health check request should be sent over TLS.
	TlsEnabled bool
	// TlsConfig specifies the TLS configuration to use for TLS enabled gRPC health check requests.
	TlsConfig *tls.Config
	// AltPort specifies the port to use for gRPC health check requests.
	// If left empty it taks the port from host during check.
	AltPort uint32
}

TcpOpt Describes the TCP health check specific options.

type UdpHealthCheck

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

func NewUdpHealthCheck

func NewUdpHealthCheck(opt *UdpOpt) *UdpHealthCheck

func (*UdpHealthCheck) Check

func (h *UdpHealthCheck) Check(host string) error

type UdpOpt

type UdpOpt struct {
	// TCP specific payload.
	// Empty payloads imply a connect-only health check.
	// If left empty (default to "test-gohc")
	Send *Payload
	// When checking the response, “fuzzy” matching is performed such that each
	// binary block must be found, and in the order specified, but not
	// necessarily contiguous.
	Receive []*Payload
	// Timeout for port unreachable response or for each receive read deadline. If left empty (default to 5s)
	Timeout time.Duration
	// PingTimeout specifies the timeout for ICMP requests. If left empty (default to 5s)
	PingTimeout time.Duration
	// Delay specifies the delay between ICMP requests. If left empty (default to 1s)
	Delay time.Duration
	// AltPort specifies the port to use for gRPC health check requests.
	// If left empty it taks the port from host during check.
	AltPort uint32
}

Directories

Path Synopsis
examples
tcp
udp

Jump to

Keyboard shortcuts

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