Documentation
¶
Index ¶
- type AlertSeverity
- type Container
- type ContainerEvent
- type ContainerGroup
- type ContainerState
- type ContainerStore
- type Deps
- type EventCallback
- type HealthStatus
- type ListContainersOpts
- type ListTransitionsOpts
- type LogFetcher
- type RestartChecker
- type RuntimeDiscoverer
- type Service
- func (s *Service) DeleteContainer(ctx context.Context, id int64) error
- func (s *Service) GetContainer(ctx context.Context, id int64) (*Container, error)
- func (s *Service) ListContainers(ctx context.Context, opts ListContainersOpts) ([]*Container, error)
- func (s *Service) ListContainersGrouped(ctx context.Context, opts ListContainersOpts) ([]*ContainerGroup, int, int, error)
- func (s *Service) ListTransitions(ctx context.Context, containerID int64, opts ListTransitionsOpts) ([]*StateTransition, int, error)
- func (s *Service) ProcessEvent(ctx context.Context, evt ContainerEvent)
- func (s *Service) Reconcile(ctx context.Context, discoverer RuntimeDiscoverer) error
- func (s *Service) SetEventCallback(cb EventCallback)
- type StateTransition
- type UptimeCalculator
- type UptimeResult
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) GroupSource ¶
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 ¶
ListTransitionsOpts configures transition listing queries.
type LogFetcher ¶
type LogFetcher interface {
FetchLogSnippet(ctx context.Context, externalID string) (string, error)
}
LogFetcher abstracts log retrieval.
type RestartChecker ¶
RestartChecker checks restart thresholds.
type RuntimeDiscoverer ¶
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 ¶
NewService creates a new container service with all dependencies.
func (*Service) DeleteContainer ¶
DeleteContainer removes a container and its transitions from the database.
func (*Service) GetContainer ¶
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.