adminhealth

package
v0.38.21 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 15 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.

View Source
const FunnelWeeks = 8

FunnelWeeks is how many weekly cohorts the funnel shows.

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 Engagement added in v0.37.0

type Engagement struct {
	Section
	// Active7d and Active28d count accounts with a session seen in the window
	// (sessions.last_seen_at): the owner looked, not just the truck sending.
	Active7d  int `json:"active_7d"`
	Active28d int `json:"active_28d"`
	// ConnectedNoData counts accounts that have a vehicle but no state sample,
	// drive or charge yet.
	ConnectedNoData int `json:"connected_no_data"`
	// FirstData7d and FirstData28d count accounts whose first closed drive or
	// charge fell in the window, derived from the drives and charges tables
	// (nothing is written for it). MedianSecondsToFirstData is the median gap
	// from the account's first vehicle row to that first drive or charge, over
	// the 28-day set; null when the set is empty. An aggregate only.
	FirstData7d              int  `json:"first_data_7d"`
	FirstData28d             int  `json:"first_data_28d"`
	MedianSecondsToFirstData *int `json:"median_seconds_to_first_data"`
	// EmailsSent counts mails by kind: welcome and statement in the last 28
	// days; setup_first and setup_followup over all time (the account's
	// reminder counter).
	EmailsSent map[string]int `json:"emails_sent"`
	// FunnelWeeks is the signup funnel by week of signup, newest last: how many of
	// each week's signups got to each step. Counts only. See FunnelWeek.
	FunnelWeeks []FunnelWeek `json:"funnel_weeks"`
}

Engagement is the "do people come back?" readout: counts only, read from rows the product already keeps (sessions, vehicles, drives, charges, the sent-mail columns and the events table). No per-account list leaves this section.

type FunnelWeek added in v0.37.8

type FunnelWeek struct {
	// Week is the Monday (UTC) of the signup week, YYYY-MM-DD.
	Week    string `json:"week"`
	Signups int    `json:"signups"`
	// Connected: has a real Rivian vehicle (not an ElectraFi import).
	Connected int `json:"connected"`
	// FirstData: has at least one closed drive or charge, ever.
	FirstData int `json:"first_data"`
	// Day2Eligible counts the signups at least 24 hours old, the only ones that
	// can have returned yet; ReturnedDay2 is how many of them were seen again at
	// least 24 hours after signup (a session's last_seen_at). Both are here so a
	// rate has an honest denominator for the newest, partial week.
	Day2Eligible int `json:"day2_eligible"`
	ReturnedDay2 int `json:"returned_day2"`
}

FunnelWeek is one signup week's funnel, from rows the product already keeps (users, vehicles, drives, charges, sessions), so it needs no event switch and holds for accounts that signed up before any event existed. Disabled accounts and the public demo account are left out.

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"`
	Engagement  Engagement `json:"engagement"`
}

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