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.
const FunnelWeeks = 8
FunnelWeeks is how many weekly cohorts the funnel shows.
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"`
// 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 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.