machinediagnostics

package
v1.20.0-beta.8 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package machinediagnostics implements the portable, user-readable diagnostics contract produced by the machine inactivity daemon.

Index

Constants

View Source
const (
	DefaultRuntimeLockPath = DefaultRuntimeDir + "/" + RuntimeLockFileName
	RuntimeLockPathEnv     = "DEVSY_DAEMON_RUNTIME_LOCK_PATH"
	RuntimeLocatorPathEnv  = "DEVSY_DAEMON_LOCATOR_PATH"
)
View Source
const (
	DefaultRuntimeDir      = "/run/devsy"
	RuntimeLockFileName    = "agent-daemon.lock"
	RuntimeLocatorFileName = "agent-daemon.json"
)
View Source
const (
	SchemaVersion        = 1
	MaxRemoteEventBytes  = 5 * 1024 * 1024
	MaxSegmentBytes      = 512 * 1024
	MaxEventMessageBytes = 4 * 1024
	MaxReadEvents        = 1000
	DefaultReadEvents    = 100
)
View Source
const DefaultLocatorPath = DefaultRuntimeDir + "/" + RuntimeLocatorFileName

Variables

This section is empty.

Functions

func ActiveLocatorCandidates

func ActiveLocatorCandidates(userCacheDir func() (string, error)) ([]string, error)

func DiagnosticsDir

func DiagnosticsDir(root string) string

func EncodeCursor

func EncodeCursor(sessionID string, sequence uint64) string

func EnsureRuntimeDir

func EnsureRuntimeDir(path string, shared bool) error

EnsureRuntimeDir creates a runtime directory, repairing permissions on shared system directories that predate them.

func ValidateCursor

func ValidateCursor(value string) error

ValidateCursor keeps cursor encoding opaque to callers while allowing public command surfaces to reject malformed input before opening a remote session.

func WriteLocator

func WriteLocator(
	path string,
	locator Locator,
) error

Types

type Availability

type Availability string
const (
	AvailabilityAvailable        Availability = "available"
	AvailabilityNotInitialized   Availability = "not_initialized"
	AvailabilityPermissionDenied Availability = "permission_denied"
	AvailabilityCorrupt          Availability = "corrupt"
	AvailabilityUnavailable      Availability = "unavailable"
)

type CursorInfo

type CursorInfo struct {
	Next   string      `json:"next,omitempty"`
	State  CursorState `json:"state"`
	Reason string      `json:"reason,omitempty"`
}

type CursorState

type CursorState string
const (
	CursorOK    CursorState = "ok"
	CursorGap   CursorState = "gap"
	CursorReset CursorState = "reset"
	CursorNone  CursorState = "none"
)

type DaemonHealth

type DaemonHealth string
const (
	DaemonHealthy  DaemonHealth = "healthy"
	DaemonDegraded DaemonHealth = "degraded"
)

type DaemonState

type DaemonState string
const (
	DaemonStarting DaemonState = "starting"
	DaemonRunning  DaemonState = "running"
	DaemonStopping DaemonState = "stopping"
)

type DiagnosticError

type DiagnosticError struct {
	Code      string    `json:"code"`
	Message   string    `json:"message"`
	Timestamp time.Time `json:"timestamp"`
}

type Event

type Event struct {
	SchemaVersion int       `json:"schemaVersion"`
	SessionID     string    `json:"sessionId"`
	Sequence      uint64    `json:"sequence"`
	Timestamp     time.Time `json:"timestamp"`
	Level         Level     `json:"level"`
	Type          EventType `json:"type"`
	WorkspaceID   string    `json:"workspaceId,omitempty"`
	Message       string    `json:"message"`
	ErrorCode     string    `json:"errorCode,omitempty"`
}

type EventType

type EventType string
const (
	EventDaemonStarted       EventType = "daemon.started"
	EventDaemonReady         EventType = "daemon.ready"
	EventDaemonStopping      EventType = "daemon.stopping"
	EventWorkspaceDiscovered EventType = "workspace.discovered"
	EventWorkspaceRemoved    EventType = "workspace.removed"
	EventWorkspaceConfigErr  EventType = "workspace.config_error"
	EventIdleDeadline        EventType = "workspace.idle_deadline_reached"
	EventShutdownStarted     EventType = "shutdown.started"
	EventShutdownSucceeded   EventType = "shutdown.succeeded"
	EventShutdownFailed      EventType = "shutdown.failed"
	EventPatrolFailed        EventType = "patrol.failed"
)

type Freshness

type Freshness string
const (
	FreshnessFresh   Freshness = "fresh"
	FreshnessStale   Freshness = "stale"
	FreshnessUnknown Freshness = "unknown"
)

type Level

type Level string
const (
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
)

type Locator

type Locator struct {
	SchemaVersion  int       `json:"schemaVersion"`
	SessionID      string    `json:"sessionId"`
	DiagnosticsDir string    `json:"diagnosticsDir"`
	StateLayout    string    `json:"stateLayout"`
	StartedAt      time.Time `json:"startedAt"`
}

func ReadLocator

func ReadLocator(path string) (Locator, error)

type Options

type Options struct {
	Dir             string
	Reader          ReaderIdentity
	PatrolInterval  time.Duration
	MaxBytes        int
	MaxSegmentBytes int
	Now             func() time.Time
	ErrorReporter   func(error)
}

type ReadOptions

type ReadOptions struct {
	After    string
	Limit    int
	Interval time.Duration
	Now      time.Time
}

type ReadResponse

type ReadResponse struct {
	SchemaVersion int              `json:"schemaVersion"`
	Availability  Availability     `json:"availability"`
	ObservedAt    time.Time        `json:"observedAt"`
	Freshness     Freshness        `json:"freshness"`
	Status        *Status          `json:"status,omitempty"`
	Events        []Event          `json:"events,omitempty"`
	Cursor        CursorInfo       `json:"cursor"`
	Error         *DiagnosticError `json:"error,omitempty"`
}

func Read

func Read(dir string, options ReadOptions) ReadResponse

func ReadActive

func ReadActive(options ReadOptions, userCacheDir func() (string, error)) (ReadResponse, error)

ReadActive reads the highest-priority active daemon locator, falling through to the per-user fallback unless the system locator is corrupt.

func ReadFromLocator

func ReadFromLocator(path string, options ReadOptions) ReadResponse

ReadFromLocator reads the active daemon store without making callers infer the service user's home directory or parse a systemd unit.

type ReaderIdentity

type ReaderIdentity struct {
	UID int
	GID int
}

type Recorder

type Recorder interface {
	Record(Event)
	Update(Status)
	Close() error
}

func Nop

func Nop() Recorder

type RuntimeLock

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

RuntimeLock prevents two singleton machine daemons from supervising the same host. Its lifetime is the daemon process lifetime.

func AcquireRuntimeLock

func AcquireRuntimeLock(path string) (*RuntimeLock, error)

func (*RuntimeLock) Close

func (l *RuntimeLock) Close() error

type RuntimePaths

type RuntimePaths struct {
	LockPath    string
	LocatorPath string
}

RuntimePaths keeps the daemon's singleton lock and discovery metadata in the same runtime directory.

func SystemRuntimePaths

func SystemRuntimePaths() RuntimePaths

func UserRuntimePaths

func UserRuntimePaths(userCacheDir func() (string, error)) (RuntimePaths, error)

type Sanitizer

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

func NewSanitizer

func NewSanitizer(env []string) *Sanitizer

func (*Sanitizer) Message

func (s *Sanitizer) Message(value string) string

type ShutdownCandidate

type ShutdownCandidate struct {
	WorkspaceID string     `json:"workspaceId"`
	EligibleAt  *time.Time `json:"eligibleAt,omitempty"`
}

type Status

type Status struct {
	SchemaVersion     int                `json:"schemaVersion"`
	SessionID         string             `json:"sessionId"`
	StartedAt         time.Time          `json:"startedAt"`
	UpdatedAt         time.Time          `json:"updatedAt"`
	State             DaemonState        `json:"state"`
	Health            DaemonHealth       `json:"health"`
	PatrolInterval    string             `json:"patrolInterval"`
	LastPatrolAt      *time.Time         `json:"lastPatrolAt,omitempty"`
	LastSuccessAt     *time.Time         `json:"lastSuccessfulPatrolAt,omitempty"`
	LastError         *DiagnosticError   `json:"lastError,omitempty"`
	WorkspaceCount    int                `json:"workspaceCount"`
	Workspaces        []WorkspaceStatus  `json:"workspaces,omitempty"`
	ShutdownCandidate *ShutdownCandidate `json:"shutdownCandidate,omitempty"`
	LatestSequence    uint64             `json:"latestSequence"`
}

type Store

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

func NewRecorder

func NewRecorder(opts Options) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) Record

func (s *Store) Record(event Event)

func (*Store) SessionID

func (s *Store) SessionID() string

func (*Store) Update

func (s *Store) Update(status Status)

type WorkspaceEvaluationState

type WorkspaceEvaluationState string
const (
	WorkspaceActive        WorkspaceEvaluationState = "active"
	WorkspaceIdleDue       WorkspaceEvaluationState = "idle_due"
	WorkspaceBusy          WorkspaceEvaluationState = "busy"
	WorkspaceNotConfigured WorkspaceEvaluationState = "not_configured"
	WorkspaceInvalidConfig WorkspaceEvaluationState = "invalid_config"
	WorkspaceNotRunning    WorkspaceEvaluationState = "not_running"
)

type WorkspaceStatus

type WorkspaceStatus struct {
	ID                    string                   `json:"id"`
	State                 WorkspaceEvaluationState `json:"state"`
	LastActivityAt        *time.Time               `json:"lastActivityAt,omitempty"`
	Timeout               string                   `json:"inactivityTimeout,omitempty"`
	IdleDeadlineAt        *time.Time               `json:"idleDeadlineAt,omitempty"`
	Busy                  bool                     `json:"busy"`
	ShutdownActionEnabled bool                     `json:"shutdownActionEnabled"`
	BlocksMachineShutdown bool                     `json:"blocksMachineShutdown"`
	BlockerReason         string                   `json:"blockerReason,omitempty"`
}

Jump to

Keyboard shortcuts

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