event

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package event carries the canonical event schema every platform is normalized into: the wire types, their validation rules, and the categorization that derives an event's effect from its type. It is the contract collectors write against and the ingestion pipeline reads, so it holds no provider-specific knowledge and does no I/O.

The normative specification is roadmap/00-conventions.md section 4.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category is the effect an event has on a resource.

const (
	// CategoryCreate starts a resource's life: it sets created_at and requires a
	// full payload (state and size).
	CategoryCreate Category = "create"
	// CategoryUpdate changes a resource's state, size, or owner.
	CategoryUpdate Category = "update"
	// CategoryDelete ends a resource's life: it sets deleted_at and forces the
	// state to "deleted".
	CategoryDelete Category = "delete"
)

func Categorize

func Categorize(eventType string) Category

Categorize derives an event's effect from its type alone, which is what keeps the core free of per-platform code. See roadmap/00-conventions.md section 4.2.

type Event

type Event struct {
	EventID      string          `json:"event_id"`
	Timestamp    time.Time       `json:"timestamp"`
	EventType    string          `json:"event_type"`
	Platform     string          `json:"platform"`
	Cloud        string          `json:"cloud"`
	ResourceType string          `json:"resource_type"`
	ResourceID   string          `json:"resource_id"`
	ProjectID    string          `json:"project_id"`
	Source       Source          `json:"source"`
	Payload      PayloadEnvelope `json:"payload"`
}

Event is an immutable lifecycle fact. The events table is the system's single source of truth; everything else is derived from it and rebuildable.

func (*Event) Validate

func (e *Event) Validate() error

Validate reports every rule the event breaks, joined into one error, so a caller sees the whole picture rather than the first problem.

type PayloadEnvelope

type PayloadEnvelope struct {
	// State is the resource state at or after the event. It is required on every
	// event except a delete, where the core sets "deleted" itself.
	State *string `json:"state,omitempty"`
	// Size is the full replacement size object, required on create and on any
	// size-changing event. Absent means the size did not change.
	Size map[string]any `json:"size,omitempty"`
	// Provider is free-form raw provider data, kept for debugging and audit. Core
	// logic never reads it.
	Provider map[string]any `json:"provider,omitempty"`
	// contains filtered or unexported fields
}

PayloadEnvelope is the normalized payload every event carries. Collectors map provider data into it so that projection, timeline, and metering never need provider-specific code.

Unknown fields survive a decode/encode round-trip untouched, which keeps an event byte-faithful to what the provider sent even as this struct grows.

func (PayloadEnvelope) MarshalJSON

func (p PayloadEnvelope) MarshalJSON() ([]byte, error)

MarshalJSON encodes the named fields alongside every unknown field a previous decode preserved.

func (*PayloadEnvelope) UnmarshalJSON

func (p *PayloadEnvelope) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the envelope, routing every field this struct does not name into an unexported map so MarshalJSON can put it back.

type Source

type Source string

Source names the pipeline an event came from.

const (
	// SourceCollector marks an event pushed by a provider-side collector. It is
	// the default: an event that names no source is treated as a collector event.
	SourceCollector Source = "collector"
	// SourceReconciliation marks a synthetic event emitted by a server-side sync
	// run to correct drift between a platform and the projection.
	SourceReconciliation Source = "reconciliation"
)

type Stored

type Stored struct {
	Event
	ReceivedAt time.Time `json:"received_at"`
}

Stored pairs an Event with the server-side timestamp that breaks ordering ties between events sharing an instant.

Jump to

Keyboard shortcuts

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