chargewatch

package
v0.41.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package chargewatch measures open live charge rows: the guardrail behind "reliable charging data stays reliable" (#1670). A row stays open while a session is in progress; one that outlives its charge is what stretched a row across the drives that followed (#1619). The stale-charge janitor (internal/rivian sweepStaleCharges) should close a row an hour after its last write, so a not-charging open row that is much older is one it could not close. The figures are counts and ages, with no vehicle or user in them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, db *sql.DB, every time.Duration, clock func() time.Time, report func(Summary), onError func(error))

Run measures every interval until ctx ends and reports each good Summary (a failed read goes to onError and reports nothing). Every replica runs it: the read is cheap and idempotent, and a gauge that every pod exports does not disappear when one pod does (a singleton's series dropped out on each rollout, which flapped the Stripe cancel alert).

Types

type Summary

type Summary struct {
	Charging, NotCharging, NoFrame                            int
	OldestChargingSec, OldestNotChargingSec, OldestNoFrameSec float64
}

Summary is the open live charge rows now, split by what the vehicle's latest frame says. Age is measured from the row's last write (ended_at), which the recorder keeps moving while the car is plugged in and charging: the janitor acts an hour after it stops. A row whose vehicle has sent no frame at all within frameWindow is counted apart (NoFrame): a dormant account's leftover row is not a stuck charge, and is what the --close-stale-open repair (#1641) is for, so it must not trip the not-charging rule.

func Measure

func Measure(ctx context.Context, db *sql.DB, now time.Time) (Summary, error)

Measure reads the open live rows (every user: pass the system pool) and, per vehicle that has one, the latest vehicle_state frame within frameWindow, judged with the janitor's own rule (rivian.FrameStillCharging).

Jump to

Keyboard shortcuts

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