carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1// Package usage holds the platform's metering shapes: what a box or console
2// pass writes under usage/ in the deployment bucket, and the canonical meter
3// vocabulary every consumer — statements, scenarios, dashboards, a future
4// billing engine — speaks. Meter names are FROZEN once merged: renaming one
5// orphans every statement already written (spec: billing readiness).
6//
7// Everything here is decision-grade, not invoice-grade (spec: modelling
8// instrument): CAS-merge retries can in rare cases double-count one 5-minute
9// window, and days a writer was down are simply absent. Consumers must treat
10// missing days as reduced coverage, never as zero usage.
11package usage
12
13import "time"
14
15// Meter identifiers — the canonical billing vocabulary.
16const (
17 MeterCPUCoreHours = "cpu_core_hours"
18 MeterMemGBHours = "mem_gb_hours"
19 MeterEgressGB = "egress_gb"
20 MeterRequests1k = "requests_1k"
21 MeterStorageGBMonth = "storage_gb_month"
22 MeterAppMonths = "app_months"
23 MeterInstanceHours = "instance_hours"
24 MeterFleetBoxHoursServer = "fleet_box_hours_server"
25 MeterFleetBoxHoursDevice = "fleet_box_hours_device"
26 // MeterBackhaulGB is the hop SUBSET of MeterEgressGB (usage.EdgeRow's
27 // HopBytesOut): bytes that left a home box for a region edge before
28 // reaching the client. It rides in statements and the economics sweep
29 // as data (#288) and is priced in NO account's cost, revenue or bill —
30 // #284's ruling is absorb. A billing engine iterating meters generically
31 // must skip it, as economics.PriceAccount's usage check does; its priced
32 // terms name their meters. The platform's own cost for it is the
33 // inter-region leg, RateCard.InterRegionGBUSD.
34 MeterBackhaulGB = "backhaul_gb"
35 // MeterBackhaulRequests1k is the request-count twin of MeterBackhaulGB:
36 // requests that crossed a region before being served. Informational,
37 // unpriced, same posture.
38 MeterBackhaulRequests1k = "backhaul_requests_1k"
39 // Scan meters stay in the units the scanner observes. Converting bytes to
40 // decimal gigabytes at collection time would discard small scans forever,
41 // and neither meter is priced today.
42 MeterScanObjects = "scan_objects"
43 MeterScanBytes = "scan_bytes"
44)
45
46// DayOf is the UTC date label used in every usage key.
47func DayOf(t time.Time) string { return t.UTC().Format("2006-01-02") }
48
49// MonthOf is the UTC month label used in statement and bill keys.
50func MonthOf(t time.Time) string { return t.UTC().Format("2006-01") }
51
52// HourLabel is the two-digit UTC hour used inside day objects.
53func HourLabel(t time.Time) string { return t.UTC().Format("15") }
54