container

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertSeverity

type AlertSeverity string

AlertSeverity represents the alert severity level for a container.

const (
	SeverityCritical AlertSeverity = "critical"
	SeverityWarning  AlertSeverity = "warning"
	SeverityInfo     AlertSeverity = "info"
)

type Container

type Container struct {
	ID                   int64          `json:"id"`
	ExternalID           string         `json:"external_id"`
	Name                 string         `json:"name"`
	Image                string         `json:"image"`
	State                ContainerState `json:"state"`
	HealthStatus         *HealthStatus  `json:"health_status"`
	HasHealthCheck       bool           `json:"has_health_check"`
	OrchestrationGroup   string         `json:"orchestration_group,omitempty"`
	OrchestrationUnit    string         `json:"orchestration_unit,omitempty"`
	CustomGroup          string         `json:"custom_group,omitempty"`
	IsIgnored            bool           `json:"is_ignored"`
	AlertSeverity        AlertSeverity  `json:"alert_severity"`
	RestartThreshold     int            `json:"restart_threshold"`
	AlertChannels        string         `json:"alert_channels,omitempty"`
	Archived             bool           `json:"archived"`
	FirstSeenAt          time.Time      `json:"first_seen_at"`
	LastStateChangeAt    time.Time      `json:"last_state_change_at"`
	ArchivedAt           *time.Time     `json:"archived_at,omitempty"`
	RuntimeType          string         `json:"runtime_type"`
	ErrorDetail          string         `json:"error_detail,omitempty"`
	ControllerKind       string         `json:"controller_kind,omitempty"`
	Namespace            string         `json:"namespace,omitempty"`
	PodCount             int            `json:"pod_count"`
	ReadyCount           int            `json:"ready_count"`
	ComposeWorkingDir    string         `json:"compose_working_dir,omitempty"`
	SwarmServiceID       string         `json:"swarm_service_id,omitempty"`
	SwarmServiceName     string         `json:"swarm_service_name,omitempty"`
	SwarmServiceMode     string         `json:"swarm_service_mode,omitempty"`
	SwarmNodeID          string         `json:"swarm_node_id,omitempty"`
	SwarmTaskSlot        int            `json:"swarm_task_slot,omitempty"`
	SwarmDesiredReplicas int            `json:"swarm_desired_replicas,omitempty"`
}

Container represents a discovered container/workload tracked by maintenant.

func (*Container) GroupName

func (c *Container) GroupName() string

GroupName returns the effective group name for this container.

func (*Container) GroupSource

func (c *Container) GroupSource() string

GroupSource returns the source of the group assignment.

type ContainerEvent

type ContainerEvent struct {
	Action       string
	ExternalID   string
	Name         string
	ExitCode     string
	HealthStatus string
	ErrorDetail  string
	Timestamp    time.Time
	Labels       map[string]string
}

ContainerEvent represents a normalized runtime event for container state changes. This mirrors runtime.RuntimeEvent but lives in the container package to avoid import cycles.

type ContainerGroup

type ContainerGroup struct {
	Name       string       `json:"name"`
	Source     string       `json:"source"` // "compose", "label", "default"
	Containers []*Container `json:"containers"`
}

ContainerGroup represents a logical grouping of containers.

type ContainerState

type ContainerState string

ContainerState represents the possible states of a Docker container.

const (
	StateRunning    ContainerState = "running"
	StateExited     ContainerState = "exited"
	StateCompleted  ContainerState = "completed" // exited with code 0 (normal/expected termination)
	StateRestarting ContainerState = "restarting"
	StatePaused     ContainerState = "paused"
	StateCreated    ContainerState = "created"
	StateDead       ContainerState = "dead"
)

type ContainerStore

type ContainerStore interface {
	// Container CRUD
	InsertContainer(ctx context.Context, c *Container) (int64, error)
	UpdateContainer(ctx context.Context, c *Container) error
	GetContainerByExternalID(ctx context.Context, externalID string) (*Container, error)
	GetContainerByID(ctx context.Context, id int64) (*Container, error)
	ListContainers(ctx context.Context, opts ListContainersOpts) ([]*Container, error)
	ArchiveContainer(ctx context.Context, externalID string, archivedAt time.Time) error
	DeleteContainerByID(ctx context.Context, id int64) error

	// State transitions
	InsertTransition(ctx context.Context, t *StateTransition) (int64, error)
	ListTransitionsByContainer(ctx context.Context, containerID int64, opts ListTransitionsOpts) ([]*StateTransition, int, error)
	CountRestartsSince(ctx context.Context, containerID int64, since time.Time) (int, error)

	// Uptime
	GetTransitionsInWindow(ctx context.Context, containerID int64, from time.Time, to time.Time) ([]*StateTransition, error)

	// Retention
	DeleteTransitionsBefore(ctx context.Context, before time.Time, batchSize int) (int64, error)
	DeleteArchivedContainersBefore(ctx context.Context, before time.Time) (int64, error)
}

ContainerStore defines the persistence interface for container data.

type Deps added in v1.1.0

type Deps struct {
	Store          ContainerStore    // required
	Logger         *slog.Logger      // required
	EventCallback  EventCallback     // optional — nil-safe
	LogFetcher     LogFetcher        // optional — nil-safe
	RestartChecker RestartChecker    // optional — nil-safe
	Discoverer     RuntimeDiscoverer // optional — nil-safe
}

Deps holds all dependencies for the container Service.

type EventCallback

type EventCallback func(eventType string, data interface{})

EventCallback is called when a container event occurs (for SSE broadcasting).

type HealthStatus

type HealthStatus string

HealthStatus represents the health check status of a container.

const (
	HealthHealthy   HealthStatus = "healthy"
	HealthUnhealthy HealthStatus = "unhealthy"
	HealthStarting  HealthStatus = "starting"
)

type ListContainersOpts

type ListContainersOpts struct {
	IncludeArchived bool
	IncludeIgnored  bool
	GroupFilter     string
	StateFilter     string
}

ListContainersOpts configures container listing queries.

type ListTransitionsOpts

type ListTransitionsOpts struct {
	Since  *time.Time
	Until  *time.Time
	Limit  int
	Offset int
}

ListTransitionsOpts configures transition listing queries.

type LogFetcher

type LogFetcher interface {
	FetchLogSnippet(ctx context.Context, externalID string) (string, error)
}

LogFetcher abstracts log retrieval.

type RestartChecker

type RestartChecker interface {
	Check(ctx context.Context, c *Container) (interface{}, error)
}

RestartChecker checks restart thresholds.

type RuntimeDiscoverer

type RuntimeDiscoverer interface {
	DiscoverAll(ctx context.Context) ([]*Container, error)
}

RuntimeDiscoverer abstracts container/workload discovery operations.

type Service

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

Service orchestrates container discovery, event processing, and persistence.

func NewService

func NewService(d Deps) *Service

NewService creates a new container service with all dependencies.

func (*Service) DeleteContainer

func (s *Service) DeleteContainer(ctx context.Context, id int64) error

DeleteContainer removes a container and its transitions from the database.

func (*Service) GetContainer

func (s *Service) GetContainer(ctx context.Context, id int64) (*Container, error)

GetContainer retrieves a container by its maintenant ID.

func (*Service) ListContainers

func (s *Service) ListContainers(ctx context.Context, opts ListContainersOpts) ([]*Container, error)

ListContainers returns containers matching the given options.

func (*Service) ListContainersGrouped

func (s *Service) ListContainersGrouped(ctx context.Context, opts ListContainersOpts) ([]*ContainerGroup, int, int, error)

ListContainersGrouped returns containers organized into groups.

func (*Service) ListTransitions

func (s *Service) ListTransitions(ctx context.Context, containerID int64, opts ListTransitionsOpts) ([]*StateTransition, int, error)

ListTransitions returns state transitions for a container.

func (*Service) ProcessEvent

func (s *Service) ProcessEvent(ctx context.Context, evt ContainerEvent)

ProcessEvent handles a single container/workload event.

func (*Service) Reconcile

func (s *Service) Reconcile(ctx context.Context, discoverer RuntimeDiscoverer) error

Reconcile compares stored container states with actual runtime state and generates synthetic transitions for changes that occurred while maintenant was offline.

func (*Service) SetEventCallback

func (s *Service) SetEventCallback(cb EventCallback)

SetEventCallback sets the callback for broadcasting container events.

type StateTransition

type StateTransition struct {
	ID             int64          `json:"id"`
	ContainerID    int64          `json:"container_id"`
	PreviousState  ContainerState `json:"previous_state"`
	NewState       ContainerState `json:"new_state"`
	PreviousHealth *HealthStatus  `json:"previous_health,omitempty"`
	NewHealth      *HealthStatus  `json:"new_health,omitempty"`
	ExitCode       *int           `json:"exit_code,omitempty"`
	LogSnippet     string         `json:"log_snippet,omitempty"`
	Timestamp      time.Time      `json:"timestamp"`
}

StateTransition records a container state change event.

type UptimeCalculator

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

UptimeCalculator computes container uptime percentages from state transitions.

func NewUptimeCalculator

func NewUptimeCalculator(store ContainerStore) *UptimeCalculator

NewUptimeCalculator creates a new uptime calculator.

func (*UptimeCalculator) Calculate

func (u *UptimeCalculator) Calculate(ctx context.Context, containerID int64, proLicense bool) (*UptimeResult, error)

Calculate computes uptime for a container across all windows. Community tier receives only 24h; Pro+ gets all windows.

type UptimeResult

type UptimeResult struct {
	Hours24 *float64 `json:"24h"`
	Days7   *float64 `json:"7d,omitempty"`
	Days30  *float64 `json:"30d,omitempty"`
	Days90  *float64 `json:"90d,omitempty"`
}

UptimeResult holds calculated uptime for a container.

Jump to

Keyboard shortcuts

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