adminhealth

package
v0.36.21 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package adminhealth builds the read-only "is everything OK?" summary for the admin home: firing alerts (Alertmanager), the kill switch, Rivian call health over the last 24 h, streaming vs leased vehicles, disk, backup age and version.

Every section is independent and degrades to {"status":"unavailable"} with a short reason; nothing here can turn the endpoint into a 500. The two outside sources (Alertmanager, Prometheus) are reached only at URLs from the environment, with fixed paths and fixed queries (no caller input reaches them), a short timeout and a capped response size.

Index

Constants

View Source
const (
	OK          = "ok"
	Unavailable = "unavailable"
)

Status of one section.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	Name     string    `json:"name"`
	Severity string    `json:"severity"`
	Since    time.Time `json:"since"`
}

type Alerts

type Alerts struct {
	Section
	Items []Alert `json:"items"`
}

type Backup

type Backup struct {
	Section
	AgeSeconds *float64 `json:"age_seconds"`
}

type Config

type Config struct {
	DB              *sql.DB
	Flags           *flags.Store
	Version         string
	AlertmanagerURL string // e.g. http://alertmanager-operated.monitoring:9093
	PrometheusURL   string // e.g. http://prometheus-operated.monitoring:9090
	// Namespace scopes the database disk and backup queries to this
	// release's cluster (default "rivolt").
	Namespace string
	Client    *http.Client // nil: a client with a short timeout
}

Config wires the sources. Empty URLs mean "not configured": the sections that need them read unavailable.

type Disk

type Disk struct {
	Section
	UsedPct *float64 `json:"used_pct"`
}

type KillSwitch

type KillSwitch struct {
	Section
	Paused bool `json:"paused"`
}

type Rivian

type Rivian struct {
	Section
	Window string `json:"window"`
	// Results counts Rivian calls by outcome class over the window.
	Results map[string]float64 `json:"results"`
	// ErrorRate is the share of calls that were not "success" (0..1); null
	// when there were no calls.
	ErrorRate *float64 `json:"error_rate"`
	// BreakerState: 0 closed, 1 half open, 2 open (worst across pods).
	BreakerState *float64           `json:"breaker_state"`
	BreakerTrips map[string]float64 `json:"breaker_trips"`
	RateLimited  map[string]float64 `json:"rate_limited"`
}

type Section

type Section struct {
	Status string `json:"status"`
	Reason string `json:"reason,omitempty"`
}

Section is the part every section shares.

type Service

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

Service computes summaries, caching one for a few seconds so a refreshing admin page cannot hammer Alertmanager or Prometheus.

func New

func New(cfg Config) *Service

New builds the Service.

func (*Service) Summary

func (s *Service) Summary(ctx context.Context) Summary

Summary returns the summary, from cache when it is fresh. A nil Service answers with every section unavailable.

type Summary

type Summary struct {
	GeneratedAt time.Time  `json:"generated_at"`
	Version     string     `json:"version"`
	Alerts      Alerts     `json:"alerts"`
	KillSwitch  KillSwitch `json:"kill_switch"`
	Rivian      Rivian     `json:"rivian"`
	Vehicles    Vehicles   `json:"vehicles"`
	Disk        Disk       `json:"disk"`
	Backup      Backup     `json:"backup"`
}

Summary is the response body.

type Vehicles

type Vehicles struct {
	Section
	// Leased: vehicles with an unexpired subscription lease. Streaming:
	// vehicles that wrote a state row in the last 10 minutes.
	Leased    int `json:"leased"`
	Streaming int `json:"streaming"`
}

Jump to

Keyboard shortcuts

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