Documentation
¶
Overview ¶
Package usageping is muster's anonymous usage heartbeat (docs/usage-ping.md): once a day, muster-server and muster-mirror each send one small JSON object to a collector, so the project can tell how many installs run, on which version and in which kind of deployment. It is ON by default and turned off by one setting (muster-server: MUSTER_USAGE_PING=off; muster-mirror: MUSTER_MIRROR_USAGE_PING=off or -usage-ping=false) or by DO_NOT_TRACK=1.
🔴 THE PAYLOAD IS THE WHOLE DISCLOSURE, AND IT IS PINNED. Payload's fields are every byte that leaves the machine besides the request itself: a random install id (NewInstallID: random bytes, derived from nothing on the machine), the binary's kind and version, the deployment mode, OS and architecture, and — muster-server only — two counts BANDED to 0 / 1 / 2-5 / 6+ (Band). No name, hostname, path, address or text. TestPayloadKeysArePinned fixes the JSON key set as a literal, so a new field is a deliberate change to that test and to docs/usage-ping.md, never an accident.
🔴 IT CAN NEVER HURT THE PROCESS THAT SENDS IT. One request a day with a short timeout, no retry, nothing waits on it (Pinger.Run is a background loop), and a failure is logged once per process at most. The collector is cmd/muster-ping-collector in this repository, so what it keeps can be read.
Index ¶
- Constants
- func Band(n int) string
- func Bands() []string
- func Deploy(getenv func(string) string, composeMarked bool) string
- func NewInstallID() string
- func ParseSwitch(v string) (on, set bool, err error)
- func ValidInstallID(s string) bool
- type Decision
- type File
- type PG
- type Payload
- type Pinger
- type State
- type Store
Constants ¶
const ( KindServer = "server" KindMirror = "mirror" )
The binary kinds.
const ( DeployCompose = "compose" DeployKubernetes = "kubernetes" DeployBinary = "binary" )
The deployment modes (Deploy).
const DefaultEndpoint = "https://ping.musterchief.com/v1/ping"
DefaultEndpoint is where the heartbeat goes unless the binary's endpoint setting names another (a self-hosted collector, a test stub).
const DoNotTrackEnv = "DO_NOT_TRACK"
DoNotTrackEnv is the cross-tool opt-out (consoledonottrack.com) both binaries honour: set to anything but 0/false, the heartbeat is off, whatever the binary's own setting says (Decide).
const Interval = 24 * time.Hour
Interval is how often a binary sends: once a day.
const MaxBody = 1024
MaxBody is the largest request body the collector accepts. A real payload is about 200 bytes.
Variables ¶
This section is empty.
Functions ¶
func Band ¶
Band is n as one of four bands: "0", "1", "2-5" or "6+". A negative n (no count) reads as "0".
func Bands ¶
func Bands() []string
Bands is every band, in order: what the collector's stats count by.
func Deploy ¶
Deploy is the deployment mode, detected cheaply from the environment: kubernetes when the kubelet's KUBERNETES_SERVICE_HOST is set, compose when the caller read its Compose marker (muster-server's MUSTER_DEPLOY_MODE, which deploy/docker-compose.yml sets to compose), else binary (a package, an archive, `go run`, anything else).
func NewInstallID ¶
func NewInstallID() string
NewInstallID is a fresh install id: 16 random bytes, hex. It is derived from nothing on the machine, so it identifies an install and nothing else.
func ParseSwitch ¶
ParseSwitch reads a binary's own on/off setting. Empty is "not set" (set false): the default, on unless DO_NOT_TRACK says otherwise.
func ValidInstallID ¶
ValidInstallID reports whether s is an id NewInstallID could have made.
Types ¶
type Decision ¶
type Decision struct {
On bool
// Why is the reason it is off ("" when on), naming the setting:
// "<switchName>=off" or "DO_NOT_TRACK is set".
Why string
}
Decision is whether a binary sends, and why not.
func Decide ¶
Decide is the ONE rule for whether a binary sends, from its own setting's name and value and DO_NOT_TRACK's value:
- its setting off: off.
- DO_NOT_TRACK set: off, ALWAYS — even beside an explicit on. The cross-tool opt-out is the person's, and no muster setting overrides it.
- otherwise (unset or on): on.
A malformed setting is an error; each binary decides what that does.
type File ¶
type File struct {
Path string
// contains filtered or unexported fields
}
File is muster-mirror's Store: a small JSON file (mode 0600) in its config directory (mirrorpath.DefaultUsagePingFile), holding the install id and the last attempt. A missing or unreadable file starts a new install id.
type PG ¶
type PG struct {
// contains filtered or unexported fields
}
PG is muster-server's Store: the one usage_ping row (migration 0200).
It reads and writes as authz.System: the row is the server's, owned by no user, under forced row-level security that admits the system scope only.
type Payload ¶
type Payload struct {
InstallID string `json:"install_id"`
Kind string `json:"kind"`
Version string `json:"version"`
Deploy string `json:"deploy"`
OS string `json:"os"`
Arch string `json:"arch"`
// Hosts and Agents are muster-server's banded counts (Band): the
// connected muster-mirror hosts, and the agent sessions (Claude Code or
// opencode windows) on them. Omitted for muster-mirror.
Hosts string `json:"hosts,omitempty"`
Agents string `json:"agents,omitempty"`
}
Payload is the heartbeat, exactly as it is sent.
type Pinger ¶
type Pinger struct {
// Endpoint is the collector's URL; "" is DefaultEndpoint.
Endpoint string
Store Store
// Build fills in everything but the install id.
Build func(ctx context.Context) Payload
// Client is the HTTP client; nil is one with a short timeout.
Client *http.Client
// Logger gets at most one line per process: the first failure.
Logger *log.Logger
// Now and Delay are the clock and the wait before the first send of a
// process (Run); nil is the real clock and 1-10 minutes, at random.
Now func() time.Time
Delay func() time.Duration
// contains filtered or unexported fields
}
Pinger sends the heartbeat about once a day.
type State ¶
type State struct {
InstallID string
// LastSent is when the last heartbeat was attempted; zero for never.
LastSent time.Time
}
State is what a binary keeps between restarts.
type Store ¶
type Store interface {
// Load returns the State, creating and keeping a new install id the
// first time.
Load(ctx context.Context) (State, error)
// MarkSent records an attempt at t.
MarkSent(ctx context.Context, t time.Time) error
}
Store keeps State: muster-server in its database (PG), muster-mirror in a file in its config directory (File).