obs

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

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

The server 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,
	tlsCfg TLSConfig,
) *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
  • tlsCfg — optional TLS termination; zero value serves plaintext

func (*Server) Run

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

Run starts the HTTP server and blocks until the listener stops, which happens when Server.Shutdown is called, not when ctx is canceled. Canceling ctx alone stops the uptime goroutine and leaves the listener serving.

Run also starts a background goroutine that refreshes the uptime metric on [uptimeTick] intervals; that goroutine does exit 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.

type TLSConfig added in v0.4.0

type TLSConfig struct {
	Enabled  bool
	CertFile string
	KeyFile  string
}

TLSConfig terminates TLS on the worker's observability listener.

This listener serves metrics, health and optionally pprof. It defaults to loopback, where plaintext is fine, but an operator scraping it from Prometheus has to bind it wider, and then everything on it, pprof included, crosses the network in the clear. The zero value serves plaintext.

Jump to

Keyboard shortcuts

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