obs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package obs provides the local observability HTTP server for sqi-worker.

The server is intentionally minimal and listens on a loopback address (default 127.0.0.1:9091) so it is accessible to local monitoring agents and container orchestrators without being reachable from the network.

Endpoints

  • GET /healthz — liveness probe; always 200 while the HTTP event loop runs.
  • GET /readyz — readiness probe; 200 when all registered [health.Checker]s pass, 503 when any fail (e.g. NATS connection is down).
  • GET /metrics — Prometheus text/OpenMetrics exposition.
  • GET /debug/pprof/* — Go runtime profiling (only when pprof is enabled).

Usage

srv := obs.New(cfg, logger, metrics, health)
go srv.Run(ctx)      // starts listening; returns when ctx is canceled
// ... after work is done ...
srv.Shutdown(ctx)    // graceful stop

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server is the local observability HTTP server for sqi-worker. Create with New; start with [Run]; stop with [Shutdown].

func New

func New(
	addr string,
	enablePprof bool,
	logger *slog.Logger,
	m *workmetrics.Metrics,
	h *health.Registry,
) *Server

New creates a *Server with the given configuration.

  • addr — TCP listen address, e.g. "127.0.0.1:9091"
  • enablePprof — when true, registers /debug/pprof/* endpoints
  • logger — used for request logging and startup/shutdown messages
  • m — worker Prometheus metrics; /metrics serves this registry
  • h — health registry consulted by /readyz

func (*Server) Run

func (s *Server) Run(ctx context.Context)

Run starts the HTTP server and blocks until ctx is canceled, at which point it performs a graceful shutdown and returns.

Run also starts a background goroutine that refreshes the uptime metric on [uptimeTick] intervals; that goroutine exits when ctx is canceled.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown gracefully stops the HTTP server within the deadline of the supplied context.

Jump to

Keyboard shortcuts

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