metering

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package metering emits append-only VM/snapshot lifecycle endpoints; tenant attribution lives upstream.

Index

Constants

View Source
const (
	KindVMComputeStart   Kind = "vm.compute.start"
	KindVMComputeStop    Kind = "vm.compute.stop"
	KindVMStorageStart   Kind = "vm.storage.start"
	KindVMStorageStop    Kind = "vm.storage.stop"
	KindSnapStorageStart Kind = "snap.storage.start"
	KindSnapStorageStop  Kind = "snap.storage.stop"

	ReasonBoot          Reason = "boot"
	ReasonRestart       Reason = "restart"
	ReasonClone         Reason = "clone"
	ReasonRestore       Reason = "restore"
	ReasonHibernateWake Reason = "hibernate-wake"
	ReasonStopUser      Reason = "stop-user"
	ReasonStopCrash     Reason = "stop-crash"
	ReasonVMRemove      Reason = "vm-rm"
	ReasonSnapRemove    Reason = "snap-rm"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CaptureRecorder

type CaptureRecorder struct {
	// contains filtered or unexported fields
}

CaptureRecorder accumulates entries in memory; intended for tests that assert emit sequences.

func (*CaptureRecorder) Emit

func (r *CaptureRecorder) Emit(_ context.Context, e Entry)

func (*CaptureRecorder) Entries

func (r *CaptureRecorder) Entries() []Entry

Entries returns a snapshot copy so callers can mutate freely.

func (*CaptureRecorder) Reset

func (r *CaptureRecorder) Reset()

Reset drops buffered entries.

type Entry

type Entry struct {
	Kind             Kind      `json:"kind"`
	VMID             string    `json:"vm_id,omitempty"`
	SnapshotID       string    `json:"snapshot_id,omitempty"`
	SourceSnapshotID string    `json:"source_snapshot_id,omitempty"`
	Reason           Reason    `json:"reason,omitempty"`
	Hypervisor       string    `json:"hypervisor,omitempty"`
	Shape            Shape     `json:"shape"`
	EmittedAt        time.Time `json:"emitted_at"`
}

Entry is one append-only lifecycle event.

type FileRecorder

type FileRecorder struct {
	// contains filtered or unexported fields
}

FileRecorder appends JSON-encoded entries one per line under sync.Mutex; cross-process atomicity comes from O_APPEND.

func (*FileRecorder) Emit

func (r *FileRecorder) Emit(ctx context.Context, e Entry)

Emit logs and swallows write errors to never block callers.

type Kind

type Kind string

Kind identifies a lifecycle endpoint; downstream pairs *.start with *.stop by id.

type NopRecorder

type NopRecorder struct{}

NopRecorder discards every entry; zero value is usable.

func (NopRecorder) Emit

type Reason

type Reason string

Reason annotates why an endpoint was emitted.

type Recorder

type Recorder interface {
	Emit(context.Context, Entry)
}

Recorder accepts lifecycle entries; implementations must be safe for concurrent use.

func NewFileRecorder

func NewFileRecorder(ctx context.Context, path string) Recorder

NewFileRecorder opens path append-only; returns NopRecorder on failure.

type Shape

type Shape struct {
	CPU          int   `json:"cpu,omitempty"`
	MemBytes     int64 `json:"mem_bytes,omitempty"`
	StorageBytes int64 `json:"storage_bytes,omitempty"`
}

Shape is the resource snapshot at the moment an Entry is emitted.

Jump to

Keyboard shortcuts

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