Documentation
¶
Overview ¶
Package pingcollector receives muster's anonymous usage ping (internal/usageping; docs/usage-ping.md) and answers aggregate questions about it. cmd/muster-ping-collector serves it.
🔴 WHAT IT KEEPS IS EXACTLY THE PAYLOAD, ONE ROW PER (install id, kind, UTC day), AND NOTHING ABOUT THE REQUEST. The table has no column for an address, a user agent or a header (TestOneRowPerInstallPerDayAndNoAddress pins its column set), the handler never reads r.RemoteAddr or a forwarding header, and nothing here logs a request. A later heartbeat the same day replaces that day's row, so an install is one row a day whatever it sends. Rows older than Retention are deleted.
Index ¶
Constants ¶
const MaxStatsDays = 90
MaxStatsDays is the longest window /v1/stats answers for.
const Retention = 180 * 24 * time.Hour
Retention is how long a day's rows are kept.
const Schema = `` /* 615-byte string literal not displayed */
Schema is the collector's whole database: one table, created at start (EnsureSchema). Its own database, not muster's: it shares no migration.
🔴 NO COLUMN FOR THE REQUEST: no address, user agent or header. The columns are the payload's fields, the day, and when that day's row was last written.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Day ¶
type Day struct {
Day string `json:"day"`
Servers int `json:"servers"`
Mirrors int `json:"mirrors"`
ByVersion map[string]map[string]int `json:"by_version"`
ByDeploy map[string]map[string]int `json:"by_deploy"`
Hosts map[string]int `json:"server_hosts"`
Agents map[string]int `json:"server_agents"`
}
Day is one UTC day's counts. Servers and Mirrors are the installs of each kind that sent that day (each mirror is one active host); the maps count installs by version and by deploy mode per kind ("server" / "mirror"), and the servers by their banded host and agent counts.
type PG ¶
type PG struct {
// contains filtered or unexported fields
}
PG is Store on Postgres.
func (*PG) EnsureSchema ¶
EnsureSchema creates the table when it is missing.
type Server ¶
type Server struct {
Store Store
// StatsToken is the bearer token /v1/stats requires; "" turns /v1/stats
// off (404).
StatsToken string
// Now is the clock; nil is time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
Server is the collector's HTTP side.
type Stats ¶
type Stats struct {
From string `json:"from"`
To string `json:"to"`
// Installs is the distinct installs seen in the window, by kind.
Installs map[string]int `json:"installs"`
Days []Day `json:"days"`
}
Stats is /v1/stats's answer: aggregates only, never an install id.
type Store ¶
type Store interface {
// Upsert keeps p as install p.InstallID's row for kind p.Kind on day,
// replacing that day's earlier one.
Upsert(ctx context.Context, day time.Time, p usageping.Payload, seen time.Time) error
// Prune deletes the rows of days before day.
Prune(ctx context.Context, before time.Time) error
// Stats aggregates the days from..to (UTC dates, inclusive).
Stats(ctx context.Context, from, to time.Time) (Stats, error)
}
Store is where the heartbeats go.