usageping

package
v0.323.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	KindServer = "server"
	KindMirror = "mirror"
)

The binary kinds.

View Source
const (
	DeployCompose    = "compose"
	DeployKubernetes = "kubernetes"
	DeployBinary     = "binary"
)

The deployment modes (Deploy).

View Source
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).

View Source
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).

View Source
const Interval = 24 * time.Hour

Interval is how often a binary sends: once a day.

View Source
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

func Band(n int) string

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

func Deploy(getenv func(string) string, composeMarked bool) string

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

func ParseSwitch(v string) (on, set bool, err error)

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

func ValidInstallID(s string) bool

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

func Decide(switchName, switchValue, dntValue string) (Decision, error)

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.

func DecideFlag

func DecideFlag(flagName string, flagOn bool, dntValue string) Decision

DecideFlag is Decide for a command-line flag given explicitly (muster-mirror's -usage-ping): false is off, true is on — unless DO_NOT_TRACK is set, which turns it off whatever the flag says.

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.

func (*File) Load

func (f *File) Load(context.Context) (State, error)

Load implements Store.

func (*File) MarkSent

func (f *File) MarkSent(_ context.Context, t time.Time) error

MarkSent implements Store.

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.

func NewPG

func NewPG(pool *pgxpool.Pool) *PG

NewPG is Store over pool.

func (*PG) Load

func (p *PG) Load(ctx context.Context) (State, error)

Load implements Store. The first call on a database writes its install id; two servers starting at once on one database keep the same one (the INSERT's ON CONFLICT, then one read).

func (*PG) MarkSent

func (p *PG) MarkSent(ctx context.Context, t time.Time) error

MarkSent implements Store.

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.

func (Payload) Validate

func (p Payload) Validate() error

Validate is the ONE schema both sides use: the sender checks what it is about to send, and the collector refuses anything else.

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.

func (*Pinger) Run

func (p *Pinger) Run(ctx context.Context)

Run sends until ctx ends: shortly after start (Delay), or — when the last attempt was less than a day ago — a day after it, then once a day. A restart therefore never sends more than once a day per install, and a fresh install is counted the day it starts.

func (*Pinger) SendOnce

func (p *Pinger) SendOnce(ctx context.Context) error

SendOnce records the attempt, then sends one heartbeat. The attempt is recorded FIRST, so a process that crashes or restarts in a loop still sends at most 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).

Jump to

Keyboard shortcuts

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