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 ¶
const ( OK = "ok" )
Status of one section.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 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"`
}
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 KillSwitch ¶
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 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.
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.