depcheck

package
v0.111.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 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 depcheck is the fleet's dependency-health registry. Services register the upstream(s) they depend on (html-proxy, js-proxy, rate-coordinator, the keystore, …) and depcheck probes them on every /health request. The probed status is folded into the /health JSON so operators (and the catalog UI) can see at a glance which transitive dependencies are degraded — not just whether the service's own process is up.

Convention: registration happens at service startup; probes run on every /health call (no background polling, no caching). Probes are expected to be cheap — a HEAD request, an in-process check, a single TCP dial. Anything heavier should cache its own result.

Sample wiring:

deps := depcheck.New()
deps.Register("html-proxy", func(ctx context.Context) error {
    return client.ProbeHTMLProxy(ctx)
})
server.Run("go_my_service", version, Handler,
    server.WithDependencies(deps))

/health response then becomes:

{
  "status": "degraded",
  "service": "go_my_service",
  "version": "1.4.0",
  "dependencies": [
    {"name":"html-proxy","ok":true,"latency_ms":42,"checked_at":"..."},
    {"name":"keystore","ok":false,"latency_ms":3001,"error":"context deadline exceeded","checked_at":"..."}
  ]
}

status is "healthy" if all probes pass, "degraded" if any fail. HTTP status code stays 200 either way — operators tail the JSON, not the status code — so liveness probes don't flap when a soft dep blips.

Package depcheck provides a registry of named health probes whose results are included in the /health endpoint JSON.

Services register probes (e.g. ping a database, check a file) via Registry.Register. The server calls Snapshot on every /health request and surfaces {status:"degraded"} if any probe fails (HTTP stays 200).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllOK

func AllOK(statuses []Status) bool

AllOK is a convenience for "should /health report healthy or degraded".

Types

type Event

type Event struct {
	Dep     string
	OK      bool
	Latency time.Duration
	Err     string
}

Event is the per-probe payload handed to an Observer.

type Observer

type Observer interface {
	ObserveDep(Event)
}

Observer receives one event per probed dependency per Snapshot call. Implementations MUST NOT block — callbacks run inline on /health. The canonical implementation lives in go-common/promx.

depcheck deliberately defines the contract here rather than importing a metrics library: depcheck keeps zero metric-stack deps.

type Probe

type Probe func(ctx context.Context) error

Probe is the cheap, idempotent check registered for an upstream. Return nil on success; any non-nil error is reported verbatim.

type Registry

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

Registry is the fan-out registry of probes.

func New

func New() *Registry

New creates an empty registry with a 2s per-probe timeout. Probes run in parallel on Snapshot(); 2s is the cap per probe, total Snapshot latency is therefore ~max(probe-latency) capped at 2s.

func (*Registry) Register

func (r *Registry) Register(name string, probe Probe)

Register adds a named probe. Names should be short and stable ("html-proxy", "keystore"); they appear verbatim in /health JSON and in operator dashboards. Re-registering the same name appends a second entry — callers should register each dep exactly once.

func (*Registry) SetObserver

func (r *Registry) SetObserver(o Observer) *Registry

WithObserver returns a Registry option-equivalent. Apply it after New() via SetObserver — depcheck.New() doesn't take variadic options today, and we'd rather not break callers.

func (*Registry) Snapshot

func (r *Registry) Snapshot(ctx context.Context) []Status

Snapshot fans out every registered probe in parallel with the per-probe timeout and returns one Status per registered dep. Order matches registration order.

If the parent context cancels mid-probe, in-flight probes are reported as failed with the context error.

func (*Registry) WithTimeout

func (r *Registry) WithTimeout(d time.Duration) *Registry

WithTimeout overrides the per-probe timeout. Returns the receiver for chaining at service startup.

type Status

type Status struct {
	Name      string    `json:"name"`
	OK        bool      `json:"ok"`
	LatencyMs int64     `json:"latency_ms"`
	Error     string    `json:"error,omitempty"`
	CheckedAt time.Time `json:"checked_at"`
}

Status is one row in the /health JSON for one registered dependency.

Jump to

Keyboard shortcuts

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