probes

package
v1.26.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func LivezHandler

func LivezHandler() http.HandlerFunc

func ReadyzHandler

func ReadyzHandler(log *slog.Logger, pinger Pinger, timeout time.Duration) http.HandlerFunc

func Register

func Register(mux *http.ServeMux, log *slog.Logger, pinger Pinger, timeout time.Duration)

Register mounts /livez and /readyz on the provided mux.

Example
package main

import (
	"context"
	"fmt"
	"log/slog"
	"net/http"
	"net/http/httptest"
	"time"

	"github.com/krateo-platformops/plumbing/server/probes"
)

type okPinger struct{}

func (okPinger) Ping(context.Context) error { return nil }

func main() {
	mux := http.NewServeMux()
	probes.Register(mux, slog.Default(), okPinger{}, time.Second)

	req := httptest.NewRequest(http.MethodGet, "/readyz", nil)
	rr := httptest.NewRecorder()
	mux.ServeHTTP(rr, req)

	fmt.Println(rr.Code)
}
Output:
200

Types

type HealthServer

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

func New

func New(log *slog.Logger, pinger Pinger, port int) *HealthServer

New builds an HTTP health server exposing /livez and /readyz.

The readiness probe requires that the Pinger does not return error. Liveness always returns 200.

Example
package main

import (
	"context"
	"log/slog"
	"time"

	"github.com/krateo-platformops/plumbing/server/probes"
)

type okPinger struct{}

func (okPinger) Ping(context.Context) error { return nil }

func main() {
	hs := probes.New(slog.Default(), okPinger{}, 0)
	hs.Start()

	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
	defer cancel()
	_ = hs.Shutdown(ctx)
}

func (*HealthServer) Shutdown

func (h *HealthServer) Shutdown(ctx context.Context) error

Shutdown gracefully stops the HTTP server.

func (*HealthServer) Start

func (h *HealthServer) Start()

Start runs the HTTP server in a background goroutine.

type Pinger

type Pinger interface {
	Ping(context.Context) error
}

Jump to

Keyboard shortcuts

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