billing

package
v1.108.16 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

fleet.go is the fleet-billing orchestrator — the ONE place the three connected- compute tiers are metered, all through the canonical commerce/metering path (service.NewMeteringClient), per org+project, so a customer sees ONE invoice however their compute is connected:

(a) BYOC cloud account  → 1% of the account's cloud spend (daily, incremental).
(b) BYO hardware/device → flat $1/mo per connected GPU/device (monthly).
(c) hanzo.network validator → FREE (verified on-chain; never billed).

The tier is a property of the compute source (a Provider vs a FleetWorker.Kind), resolved here; there is one debit path, three rates. Money safety: every unit is claimed cluster-wide via object BillingLease before it is billed, because visor runs replicas: 2 with no leader election and commerce does not dedup on requestId. Honesty: no spend or exemption is ever fabricated — an unreadable cost is skipped (no fee) and an unverified validator is billed (flagged), never the reverse.

Brand policy: the upstream cloud TYPE (AWS/DO/…) never leaves the cost readers; the metering line's Model carries only the tier and the customer's OWN provider/worker label, never an upstream provider name.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BillWorkerOnConnect

func BillWorkerOnConnect(ctx context.Context, w *object.FleetWorker)

BillWorkerOnConnect arms billing for a freshly-connected worker — the "armed on connect" half of tier (b). It bills the current month immediately (idempotent per month via the same lease the monthly sweep uses), so a box connected mid-month is billed at once, and the monthly sweep never double-bills it.

func CollectBYOCCosts

func CollectBYOCCosts(ctx context.Context, now time.Time)

CollectBYOCCosts is the daily tier-(a) collector. For every org's active BYOC cloud provider it reads month-to-date spend via that cloud's cost API and meters 1% of the increment since the last run to org+project. No spend → no fee; an unreadable cost (unconfigured scope, transient error) is skipped for this run and recovered on the next (the cursor is only advanced on a successful read). Single-flight per (provider, day) via BillingLease, so replicas never double-bill.

func GetHourlyCostCents

func GetHourlyCostCents(sizeSlug string) int64

GetHourlyCostCents returns the hourly cost in cents for a given DO size slug. Returns 0 if the size is not found.

func MeterConnectedDevices

func MeterConnectedDevices(ctx context.Context, now time.Time)

MeterConnectedDevices is the monthly tier-(b)/(c) sweep: bill every CONNECTED BYO worker $1/device for the current month (validators exempt). It is safe to run more than once a month — the per-(worker, month) lease makes each worker's fee exactly-once.

Types

type BillingReporter

type BillingReporter struct {
	CommerceURL  string
	ServiceToken string
	MeterID      string
	// contains filtered or unexported fields
}

func NewBillingReporter

func NewBillingReporter(commerceURL, serviceToken string) *BillingReporter

func (*BillingReporter) ReportAllNodePools

func (r *BillingReporter) ReportAllNodePools()

ReportAllNodePools fetches all node pools and reports usage for each.

func (*BillingReporter) ReportNodePoolUsage

func (r *BillingReporter) ReportNodePoolUsage(pool *object.NodePool) error

ReportNodePoolUsage sends a meter event for a single node pool's hourly usage.

type MeterEvent

type MeterEvent struct {
	MeterID     string            `json:"meterId"`
	UserID      string            `json:"userId"`
	Value       int64             `json:"value"`
	Timestamp   string            `json:"timestamp"`
	Idempotency string            `json:"idempotency"`
	Dimensions  map[string]string `json:"dimensions"`
}

type MeterEventRequest

type MeterEventRequest struct {
	Events []MeterEvent `json:"events"`
}

Jump to

Keyboard shortcuts

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