model

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const SchemaVersion = 2

SchemaVersion is embedded in every serialized Run. Bump when the on-disk / JSON shape of Run or Event changes incompatibly.

Variables

This section is empty.

Functions

This section is empty.

Types

type Confidence

type Confidence int

Confidence is how strongly a finding is proven by evidence.

const (
	ConfidencePossible Confidence = iota
	ConfidenceMedium
	ConfidenceHigh
)

Finding confidence levels.

func (Confidence) MarshalJSON

func (c Confidence) MarshalJSON() ([]byte, error)

MarshalJSON encodes confidence as its string name.

func (Confidence) String

func (c Confidence) String() string

func (*Confidence) UnmarshalJSON

func (c *Confidence) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes confidence from its string name.

type DisplayState

type DisplayState string

DisplayState is the TUI glyph family retained from the status-viewer product. It maps onto ServicePhase so pstree rendering stays stable.

const (
	DisplayHealthy   DisplayState = "healthy"
	DisplayStarting  DisplayState = "starting"
	DisplayBlocked   DisplayState = "blocked"
	DisplayPending   DisplayState = "pending"
	DisplayMissing   DisplayState = "missing"
	DisplayCompleted DisplayState = "completed"
	DisplayFailed    DisplayState = "failed"
	DisplayUnhealthy DisplayState = "unhealthy"
	DisplayDegraded  DisplayState = "degraded"
)

Display states used by the pstree glyphs.

type EffectiveConfig

type EffectiveConfig struct {
	RawYAML     string             `json:"raw_yaml,omitempty"`
	Services    []EffectiveService `json:"services,omitempty"`
	Overrides   []OverrideNote     `json:"overrides,omitempty"`
	SourceFiles []string           `json:"source_files,omitempty"`
}

EffectiveConfig is the fully-merged Compose model plus override explanations.

type EffectiveService

type EffectiveService struct {
	Name        string            `json:"name"`
	Image       string            `json:"image,omitempty"`
	Build       string            `json:"build,omitempty"`
	Ports       []string          `json:"ports,omitempty"`
	Volumes     []string          `json:"volumes,omitempty"`
	Networks    []string          `json:"networks,omitempty"`
	Command     []string          `json:"command,omitempty"`
	EnvNames    []string          `json:"env_names,omitempty"`
	Healthcheck string            `json:"healthcheck,omitempty"`
	DependsOn   map[string]string `json:"depends_on,omitempty"`
}

EffectiveService is one service from `docker compose config`.

type Event

type Event struct {
	RunID       string         `json:"run_id"`
	Timestamp   time.Time      `json:"timestamp"`
	Source      EventSource    `json:"source"`
	Project     string         `json:"project,omitempty"`
	Service     string         `json:"service,omitempty"`
	ContainerID string         `json:"container_id,omitempty"`
	Phase       ServicePhase   `json:"phase"`
	Type        EventType      `json:"type"`
	Severity    Severity       `json:"severity"`
	Message     string         `json:"message,omitempty"`
	Data        map[string]any `json:"data,omitempty"`
}

Event is one normalized signal in a Compose run.

type EventSource

type EventSource int

EventSource identifies which collector/producer emitted an event.

const (
	SourceCompose EventSource = iota
	SourceDocker
	SourceContainer
	SourceHealthcheck
	SourceProbe
	SourceProcess
	SourceNetwork
	SourceResource
	SourceLog
	SourceDiagnosis
)

Event sources in the normalized schema.

func (EventSource) MarshalJSON

func (s EventSource) MarshalJSON() ([]byte, error)

MarshalJSON encodes the source as its string name.

func (EventSource) String

func (s EventSource) String() string

func (*EventSource) UnmarshalJSON

func (s *EventSource) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a source from its string name.

type EventType

type EventType int

EventType is the kind of normalized lifecycle/diagnostic signal.

const (
	EventTypeState EventType = iota
	EventTypeLog
	EventTypeStats
	EventTypeInspect
	EventTypeProbe
	EventTypeDiagnosis
	EventTypeLifecycle
)

Normalized event types.

func (EventType) MarshalJSON

func (t EventType) MarshalJSON() ([]byte, error)

MarshalJSON encodes the type as its string name.

func (EventType) String

func (t EventType) String() string

func (*EventType) UnmarshalJSON

func (t *EventType) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a type from its string name.

type Finding

type Finding struct {
	RuleID          string     `json:"rule_id"`
	Service         string     `json:"service,omitempty"`
	RootCause       string     `json:"root_cause,omitempty"`
	Evidence        []string   `json:"evidence,omitempty"`
	Confidence      Confidence `json:"confidence"`
	BlockedServices []string   `json:"blocked_services,omitempty"`
	SuggestedFixes  []string   `json:"suggested_fixes,omitempty"`
}

Finding is a structured diagnosis produced by the (later) diagnosis engine. Fields align with Phase 2; Phase 0 only defines the schema.

type Invocation

type Invocation struct {
	Command        []string          `json:"command"`
	WorkingDir     string            `json:"working_dir"`
	ComposeFiles   []string          `json:"compose_files,omitempty"`
	Profiles       []string          `json:"profiles,omitempty"`
	ProjectName    string            `json:"project_name,omitempty"`
	EnvNames       []string          `json:"env_names,omitempty"`
	EnvValues      map[string]string `json:"env_values,omitempty"` // only when opted in
	DockerContext  string            `json:"docker_context,omitempty"`
	DockerHost     string            `json:"docker_host,omitempty"`
	DockerVersion  string            `json:"docker_version,omitempty"`
	ComposeVersion string            `json:"compose_version,omitempty"`
	OS             string            `json:"os,omitempty"`
	Arch           string            `json:"arch,omitempty"`
	Timestamp      time.Time         `json:"timestamp"`
	GitRoot        string            `json:"git_root,omitempty"`
	GitCommit      string            `json:"git_commit,omitempty"`
	GitDirty       bool              `json:"git_dirty,omitempty"`
}

Invocation captures the exact context of a recorded Compose run. EnvValues is omitted unless the user explicitly opts in; EnvNames is always safe.

type OverrideNote

type OverrideNote struct {
	Service  string `json:"service,omitempty"`
	Field    string `json:"field"`
	From     string `json:"from"`
	FromFile string `json:"from_file,omitempty"`
	To       string `json:"to"`
	ToFile   string `json:"to_file,omitempty"`
	Message  string `json:"message"`
}

OverrideNote explains a value that differed across compose files.

type PhaseTransition

type PhaseTransition struct {
	Phase     ServicePhase `json:"phase"`
	Timestamp time.Time    `json:"timestamp"`
	Source    EventSource  `json:"source,omitempty"`
	Message   string       `json:"message,omitempty"`
}

PhaseTransition records when a service entered a phase.

type Run

type Run struct {
	SchemaVersion   int                 `json:"schema_version"`
	ID              string              `json:"id"`
	StartedAt       time.Time           `json:"started_at"`
	EndedAt         *time.Time          `json:"ended_at,omitempty"`
	Project         string              `json:"project,omitempty"`
	Invocation      *Invocation         `json:"invocation,omitempty"`
	EffectiveConfig *EffectiveConfig    `json:"effective_config,omitempty"`
	Services        map[string]*Service `json:"services,omitempty"`
	Events          []Event             `json:"events,omitempty"`
	Findings        []Finding           `json:"findings,omitempty"`
	Artifacts       []string            `json:"artifacts,omitempty"`
}

Run is the aggregate state of one Compose recording session.

func NewRun

func NewRun(id string, startedAt time.Time) *Run

NewRun creates an empty run with the current schema version.

func (*Run) ApplyEvent

func (r *Run) ApplyEvent(ev Event)

ApplyEvent appends an event and updates derived service state.

func (*Run) ApplyEvents

func (r *Run) ApplyEvents(events []Event)

ApplyEvents applies events in order.

func (*Run) Clone

func (r *Run) Clone() *Run

Clone returns a deep copy suitable for concurrent readers.

func (*Run) MarshalJSON

func (r *Run) MarshalJSON() ([]byte, error)

MarshalJSON ensures schema_version is always present.

func (*Run) ServiceList

func (r *Run) ServiceList() []*Service

ServiceList returns services sorted by project then name (stable for tests).

type Service

type Service struct {
	Name         string            `json:"name"`
	Project      string            `json:"project,omitempty"`
	ContainerID  string            `json:"container_id,omitempty"`
	Phase        ServicePhase      `json:"phase"`
	PhaseHistory []PhaseTransition `json:"phase_history,omitempty"`
	ExitCode     *int              `json:"exit_code,omitempty"`
	Image        string            `json:"image,omitempty"`
	Status       string            `json:"status,omitempty"`
	Ports        []string          `json:"ports,omitempty"`
	UpdatedAt    time.Time         `json:"updated_at,omitempty"`
}

Service is the per-service aggregate derived from a run's events.

type ServicePhase

type ServicePhase int

ServicePhase is the monotonic lifecycle phase of a Compose service.

const (
	PhaseConfigured ServicePhase = iota
	PhasePulling
	PhaseBuilding
	PhaseCreated
	PhaseStarted
	PhaseProcessRunning
	PhasePortListening
	PhaseHealthy
	PhaseApplicationReady
	PhaseExited
	PhaseFailed
)

Service lifecycle phases, ordered from configured through ready, plus terminals.

func (ServicePhase) MarshalJSON

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

MarshalJSON encodes the phase as its string name.

func (ServicePhase) String

func (p ServicePhase) String() string

func (ServicePhase) Terminal

func (p ServicePhase) Terminal() bool

Terminal reports whether the phase is a terminal lifecycle state.

func (ServicePhase) ToDisplayState

func (p ServicePhase) ToDisplayState() DisplayState

ToDisplayState maps a service phase onto the existing DisplayState glyphs. Blocked/missing are graph-derived and are not produced here.

func (*ServicePhase) UnmarshalJSON

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

UnmarshalJSON decodes a phase from its string name.

type Severity

type Severity int

Severity is the urgency of an event or finding.

const (
	SeverityInfo Severity = iota
	SeverityWarn
	SeverityError
	SeverityCritical
)

Event/finding severity levels.

func (Severity) MarshalJSON

func (s Severity) MarshalJSON() ([]byte, error)

MarshalJSON encodes the severity as its string name.

func (Severity) String

func (s Severity) String() string

func (*Severity) UnmarshalJSON

func (s *Severity) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a severity from its string name.

Jump to

Keyboard shortcuts

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