metrics

package
v1.801.475 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package metrics is the fleet SaaS-operations god-view (/v1/admin/metrics) — the operator's business dashboard: MRR/ARR, net-new vs churned MRR, the plan/category mix, the top customers, and the recent subscription movements. SuperAdmin only (core.Admit).

It reads the ONE shared warehouse (commerce.events) — the table the commerce analytics collector lands every subscription/invoice/usage-lifecycle event in — over the SAME client (datastore.Query) the o11y/compute lenses use, with ZERO per-org fan-out. Each panel is ONE aggregate query that folds the whole fleet (subscription state = latest-event-wins via argMax; new/churn/usage = windowed), exactly the way o11y.go composes independent per-signal reads. An unconnected warehouse — or the collector's events table not provisioned yet — degrades to an honest empty snapshot (real zeros, `[]` not null) with a not-ok source, never a fabricated number. Money is USD cents end to end; time bounds are POSITIONAL args.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Routes

func Routes(z *zip.App)

Routes registers the SaaS-metrics god-view (SuperAdmin only, cross-tenant business aggregate).

Types

type MetricsData

type MetricsData struct {
	SaaSMetrics
	GeneratedAt string              `json:"generatedAt"`
	Sources     []core.SourceStatus `json:"sources"`
}

MetricsData is the GET /v1/admin/metrics payload: the SaaS snapshot, flat, plus the admin read time and the upstream freshness strip every god-view carries.

type MetricsIn

type MetricsIn struct {
	// Window is the movement window the new/churned MRR and the recent feed are
	// measured over. Anything unrecognised falls back to the board default.
	Window string `json:"window"`
	// Limit caps the top-customers table.
	Limit string `json:"limit"`
}

MetricsIn is the GET /v1/admin/metrics query.

type MetricsOut

type MetricsOut struct {
	Status string       `json:"status"`
	Msg    string       `json:"msg"`
	Data   *MetricsData `json:"data"`
}

MetricsOut is the GET /v1/admin/metrics envelope.

func Metrics

func Metrics(ctx context.Context, in *MetricsIn) (*MetricsOut, error)

Metrics answers GET /v1/admin/metrics by aggregating commerce.events directly (fleet-wide, no per-org fan-out). SuperAdmin only.

GET /v1/admin/metrics?window=30d&limit=20

type SaaSCategory

type SaaSCategory struct {
	Category      string      `json:"category"`
	MRRCents      money.Cents `json:"mrrCents"`
	Subscriptions int         `json:"subscriptions"`
}

SaaSCategory is one plan-category bucket of run-rate MRR (the plan mix).

type SaaSCustomer

type SaaSCustomer struct {
	Org        string      `json:"org"`
	Plan       string      `json:"plan"`
	Category   string      `json:"category"`
	Status     string      `json:"status"`
	MRRCents   money.Cents `json:"mrrCents"`
	UsageCents money.Cents `json:"usageCents"`
	Seats      int         `json:"seats"`
	Since      string      `json:"since,omitempty"`
}

SaaSCustomer is one top customer by MRR + windowed usage.

type SaaSEvent

type SaaSEvent struct {
	At            string      `json:"at"`
	Org           string      `json:"org"`
	Type          string      `json:"type"`
	Plan          string      `json:"plan"`
	Category      string      `json:"category"`
	MRRDeltaCents money.Cents `json:"mrrDeltaCents"`
}

SaaSEvent is one recent subscription movement ("created" or "canceled").

type SaaSMetrics

type SaaSMetrics struct {
	AsOf      string         `json:"asOf"`
	Currency  string         `json:"currency"`
	Window    string         `json:"window"`
	Revenue   SaaSRevenue    `json:"revenue"`
	Subs      SaaSSubs       `json:"subscriptions"`
	Usage     SaaSUsage      `json:"usage"`
	Customers []SaaSCustomer `json:"customers"`
	Orgs      int            `json:"orgs"`
	Gaps      []string       `json:"gaps"`
}

SaaSMetrics is the whole-business SaaS-operations aggregate.

type SaaSPlan

type SaaSPlan struct {
	Plan     string      `json:"plan"`
	Name     string      `json:"name"`
	Category string      `json:"category"`
	Active   int         `json:"active"`
	Trialing int         `json:"trialing"`
	Seats    int         `json:"seats"`
	MRRCents money.Cents `json:"mrrCents"`
}

SaaSPlan is one plan's active/trialing counts, seats, and MRR contribution.

type SaaSRevenue

type SaaSRevenue struct {
	MRRCents            money.Cents    `json:"mrrCents"`
	ARRCents            money.Cents    `json:"arrCents"`
	ActiveSubscriptions int            `json:"activeSubscriptions"`
	PayingCustomers     int            `json:"payingCustomers"`
	Trials              int            `json:"trials"`
	NewMRRCents         money.Cents    `json:"newMrrCents"`
	ChurnedMRRCents     money.Cents    `json:"churnedMrrCents"`
	NetNewMRRCents      money.Cents    `json:"netNewMrrCents"`
	ByCategory          []SaaSCategory `json:"byCategory"`
}

SaaSRevenue is the recurring-revenue headline (run-rate MRR/ARR + windowed movement).

type SaaSSubs

type SaaSSubs struct {
	ByPlan       []SaaSPlan  `json:"byPlan"`
	TrialsActive int         `json:"trialsActive"`
	New          int         `json:"new"`
	Canceled     int         `json:"canceled"`
	Recent       []SaaSEvent `json:"recent"`
}

SaaSSubs is the subscription-operations panel (per-plan mix, trials, new/canceled, recent movements).

type SaaSUsage

type SaaSUsage struct {
	Instrumented     bool        `json:"instrumented"`
	WindowUsageCents money.Cents `json:"windowUsageCents"`
	Requests         int64       `json:"requests"`
}

SaaSUsage is the metered / pay-as-you-go revenue headline for the window.

Jump to

Keyboard shortcuts

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