daemon

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WatchModeOff   = "off"
	WatchModeLazy  = "lazy"
	WatchModeEager = "eager"
)

Variables

This section is empty.

Functions

func BuildStatusError

func BuildStatusError() error

func EnsureDaemon

func EnsureDaemon(repoRoot string) error

EnsureDaemon attempts to start the daemon if it's not already running. It performs a quick health check (1s timeout) and spawns a new daemon if needed. Returns nil if the daemon is ready, or an error if startup failed or timed out. Errors are not fatal—the caller should fall back to direct mode.

func QueryAccessEvents

func QueryAccessEvents(store *TelemetryStore, query ExportQuery) ([]model.AccessEvent, error)

func RenderCSV

func RenderCSV(events []model.AccessEvent) string

func RenderSummaryTOON added in v0.3.0

func RenderSummaryTOON(summary ExportSummary) (string, error)

func RenderSummaryTable

func RenderSummaryTable(summary ExportSummary) string

func RenderTOON added in v0.3.0

func RenderTOON(events []model.AccessEvent) (string, error)

func ResolveDaemonLogPath added in v0.3.0

func ResolveDaemonLogPath(fallbackRepoRoot string) string

func SpawnBackground

func SpawnBackground(repoRoot string, maxWorkers int, idleTimeout time.Duration) (model.DaemonState, bool, error)

func SpawnBackgroundWithOptions added in v0.3.0

func SpawnBackgroundWithOptions(repoRoot string, maxWorkers int, idleTimeout time.Duration, options StartOptions) (model.DaemonState, bool, error)

func ValidateWatchMode added in v0.3.0

func ValidateWatchMode(mode string) error

Types

type AdminServer

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

func NewAdminServer

func NewAdminServer(manager *Manager, store *TelemetryStore, app *service.App, stateFn func() model.DaemonState, adminToken string) (*AdminServer, error)

func (*AdminServer) Shutdown

func (a *AdminServer) Shutdown() error

func (*AdminServer) URL

func (a *AdminServer) URL() string

type BackendHistogram

type BackendHistogram struct {
	Backend string `json:"backend"`
	Count   int    `json:"count"`
}

func ComputeBackendHistogram

func ComputeBackendHistogram(events []model.AccessEvent) []BackendHistogram

ComputeBackendHistogram groups events by backend and counts occurrences

type Client

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

func NewClient

func NewClient() *Client

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, request model.CommandRequest) (model.Envelope, error)

func (*Client) ExecuteWithDialTimeout added in v0.5.13

func (c *Client) ExecuteWithDialTimeout(ctx context.Context, request model.CommandRequest, dialTimeout time.Duration) (model.Envelope, error)

ExecuteWithDialTimeout executes a request with an optional timeout limited to establishing the daemon connection. Once the connection is established, the original ctx governs the request's write, read, response processing, and cancellation lifecycle.

type ClientMetrics

type ClientMetrics struct {
	ClientName string `json:"client_name"`
	Count      int    `json:"count"`
}

type ErrorFrequency

type ErrorFrequency struct {
	ErrorKind  string   `json:"error_kind,omitempty"`
	ErrorCode  string   `json:"error_code,omitempty"`
	ErrorText  string   `json:"error_text"`
	Count      int      `json:"count"`
	Workspaces []string `json:"workspaces"`
}

type ExportQuery

type ExportQuery struct {
	Since          time.Time
	Workspace      string
	Backend        string
	Operation      string
	SessionID      string
	ClientName     string
	Route          string
	Format         string
	Truncated      *bool
	PatternMode    string
	RoutingOutcome string
	FailureStage   string
	HintCode       string
	ErrorsOnly     bool
	Limit          int
	WindowLabel    string
}

type ExportSummary

type ExportSummary struct {
	TotalOps               int                      `json:"total_ops"`
	WindowLabel            string                   `json:"window_label,omitempty"`
	ByWorkspace            map[string]WorkspaceStat `json:"by_workspace"`
	ByOperation            map[string]WorkspaceStat `json:"by_operation,omitempty"`
	ByRoute                map[string]WorkspaceStat `json:"by_route,omitempty"`
	ByClient               map[string]WorkspaceStat `json:"by_client,omitempty"`
	ByHintCode             map[string]WorkspaceStat `json:"by_hint_code,omitempty"`
	ByFailureStage         map[string]WorkspaceStat `json:"by_failure_stage,omitempty"`
	TopErrors              []ErrorFrequency         `json:"top_errors"`
	ByBackend              []BackendHistogram       `json:"by_backend,omitempty"`
	ByOperationPercentiles []OperationPercentiles   `json:"by_operation_percentiles,omitempty"`
	Recommendations        []UsageRecommendation    `json:"recommendations,omitempty"`
}

func ComputeExportSummary

func ComputeExportSummary(events []model.AccessEvent) ExportSummary

func QueryAccessSummary added in v0.3.0

func QueryAccessSummary(store *TelemetryStore, query ExportQuery) (ExportSummary, error)

type FileWatcher

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

func NewFileWatcher

func NewFileWatcher(registration model.WorkspaceRegistration, debounceDur time.Duration) (*FileWatcher, error)

NewFileWatcher creates a new file watcher for a workspace.

func (*FileWatcher) PendingEvents added in v0.3.0

func (fw *FileWatcher) PendingEvents() int

func (*FileWatcher) Start

func (fw *FileWatcher) Start(ctx context.Context) error

Start begins watching the workspace for file changes.

func (*FileWatcher) Stop

func (fw *FileWatcher) Stop()

Stop closes the watcher and stops the watch loop.

func (*FileWatcher) WatchedDirCount added in v0.3.0

func (fw *FileWatcher) WatchedDirCount() int

type LogTailLine added in v0.3.0

type LogTailLine struct {
	Line int    `json:"line"`
	Text string `json:"text"`
}

func FilterBenignDaemonLogNoise added in v0.3.0

func FilterBenignDaemonLogNoise(lines []LogTailLine) []LogTailLine

func ReadLogTailFile added in v0.3.0

func ReadLogTailFile(path string, tail int, maxBytes int64) ([]LogTailLine, bool, error)

type Manager

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

func NewManager

func NewManager(repoRoot string, maxWorkers int, idleTimeout time.Duration) *Manager

func NewManagerWithOptions added in v0.3.0

func NewManagerWithOptions(repoRoot string, maxWorkers int, idleTimeout time.Duration, options StartOptions) *Manager

func (*Manager) Call

func (*Manager) EnsureFileWatcher added in v0.3.0

func (m *Manager) EnsureFileWatcher(registration model.WorkspaceRegistration)

func (*Manager) SetTelemetryStore added in v0.5.11

func (m *Manager) SetTelemetryStore(ts *TelemetryStore)

func (*Manager) Shutdown

func (m *Manager) Shutdown()

func (*Manager) StartFileWatchers

func (m *Manager) StartFileWatchers(registrations []model.WorkspaceRegistration)

StartFileWatchers initializes and starts file watchers for registered workspaces.

func (*Manager) Status

func (m *Manager) Status() []model.WorkerStatus

func (*Manager) StopWatchers

func (m *Manager) StopWatchers()

StopWatchers stops all running file watchers.

func (*Manager) Warm

func (m *Manager) Warm(workspace model.WorkspaceRegistration) []string

func (*Manager) WatcherStats added in v0.3.0

func (m *Manager) WatcherStats() model.DaemonWatcherStats

type MetricsSummary

type MetricsSummary struct {
	Window      string             `json:"window,omitempty"`
	WindowLabel string             `json:"window_label,omitempty"`
	WindowDays  int                `json:"window_days"`
	Total       int                `json:"total"`
	ErrorRate   float64            `json:"error_rate"`
	TruncRate   float64            `json:"trunc_rate"`
	Operations  []OperationMetrics `json:"operations"`
	Workspaces  []WorkspaceMetrics `json:"workspaces"`
	Clients     []ClientMetrics    `json:"clients"`
	GeneratedAt time.Time          `json:"generated_at"`
}

type OperationMetrics

type OperationMetrics struct {
	Operation string  `json:"operation"`
	Count     int     `json:"count"`
	AvgMs     float64 `json:"avg_ms"`
	P50Ms     int64   `json:"p50_ms"`
	P95Ms     int64   `json:"p95_ms"`
	ErrorRate float64 `json:"error_rate"`
	TruncRate float64 `json:"trunc_rate"`
}

type OperationPercentiles

type OperationPercentiles struct {
	Operation string `json:"operation"`
	Count     int    `json:"count"`
	P50Ms     int64  `json:"p50_ms"`
	P95Ms     int64  `json:"p95_ms"`
	P99Ms     int64  `json:"p99_ms"`
}

func ComputeOperationPercentiles

func ComputeOperationPercentiles(events []model.AccessEvent) []OperationPercentiles

ComputeOperationPercentiles calculates p50/p95/p99 latency per operation

type PerfSmokeOptions added in v0.3.0

type PerfSmokeOptions struct {
	Callers        int
	MaxWorkingSet  uint64
	MaxPrivate     uint64
	MaxHandles     uint64
	StartOptions   StartOptions
	MaxWorkers     int
	IdleTimeout    time.Duration
	RequestTimeout time.Duration
}

type PerfSmokeResult added in v0.3.0

type PerfSmokeResult struct {
	Callers       int                      `json:"callers"`
	Failures      int                      `json:"failures"`
	DaemonState   model.DaemonState        `json:"state"`
	DaemonProcess model.DaemonProcessStats `json:"daemon_process"`
	Watchers      model.DaemonWatcherStats `json:"watchers"`
	Passed        bool                     `json:"passed"`
	Warnings      []string                 `json:"warnings,omitempty"`
}

func RunPerfSmoke added in v0.3.0

func RunPerfSmoke(ctx context.Context, repoRoot string, options PerfSmokeOptions) (PerfSmokeResult, error)

type Server

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

func NewServer

func NewServer(repoRoot string, maxWorkers int, idleTimeout time.Duration) (*Server, error)

func NewServerWithOptions added in v0.3.0

func NewServerWithOptions(repoRoot string, maxWorkers int, idleTimeout time.Duration, options StartOptions) (*Server, error)

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

func (*Server) Shutdown

func (s *Server) Shutdown()

type StartOptions added in v0.3.0

type StartOptions struct {
	WatchMode       string
	MaxWatchedRoots int
	MaxInflight     int
}

func DefaultStartOptions added in v0.3.0

func DefaultStartOptions() StartOptions

func NormalizeStartOptions added in v0.3.0

func NormalizeStartOptions(options StartOptions) StartOptions

type TelemetryStore

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

func OpenTelemetryStore

func OpenTelemetryStore() (*TelemetryStore, error)

func (*TelemetryStore) Checkpoint added in v0.5.11

func (s *TelemetryStore) Checkpoint() error

func (*TelemetryStore) Close

func (s *TelemetryStore) Close() error

func (*TelemetryStore) ComputeMetrics

func (s *TelemetryStore) ComputeMetrics(since time.Time) ([]metricsRow, error)

func (*TelemetryStore) NextSeq added in v0.3.0

func (s *TelemetryStore) NextSeq(sessionID string) int

NextSeq returns the next sequence number for the given session_id. Returns 0 if session_id is empty, 1 for the first event in a session.

func (*TelemetryStore) PurgeAndVacuum added in v0.5.0

func (s *TelemetryStore) PurgeAndVacuum(retentionDays int, maxBytes int64) (int, bool, error)

PurgeAndVacuum enforces telemetry retention and reclaims space (PERF-05).

If the database exceeds maxBytes, aggressively purges to 7 days. Otherwise, respects retentionDays. Always runs VACUUM to reclaim space.

Returns (purged_count, vacuum_success, error).

func (*TelemetryStore) PurgeOldEvents

func (s *TelemetryStore) PurgeOldEvents(olderThan time.Time) (int64, error)

func (*TelemetryStore) PurgeOldRuns

func (s *TelemetryStore) PurgeOldRuns(olderThan time.Time) (int64, error)

func (*TelemetryStore) RecentAccesses

func (s *TelemetryStore) RecentAccesses(limit int) ([]model.AccessEvent, error)

func (*TelemetryStore) RecordAccess

func (s *TelemetryStore) RecordAccess(runID int64, event model.AccessEvent) error

func (*TelemetryStore) RecordAccessDirect

func (s *TelemetryStore) RecordAccessDirect(event model.AccessEvent) error

func (*TelemetryStore) ReplaceRuntimeSnapshots

func (s *TelemetryStore) ReplaceRuntimeSnapshots(runID int64, statuses []model.WorkerStatus) error

func (*TelemetryStore) StartRun

func (s *TelemetryStore) StartRun(state model.DaemonState) (int64, error)

func (*TelemetryStore) StopRun

func (s *TelemetryStore) StopRun(runID int64, stoppedAt time.Time) error

type UsageRecommendation added in v0.3.0

type UsageRecommendation struct {
	ID       string   `json:"id"`
	Severity string   `json:"severity"`
	Reason   string   `json:"reason"`
	Command  string   `json:"command,omitempty"`
	Evidence []string `json:"evidence,omitempty"`
}

func ComputeUsageRecommendations added in v0.3.0

func ComputeUsageRecommendations(summary ExportSummary) []UsageRecommendation

type WorkspaceMetrics

type WorkspaceMetrics struct {
	Workspace string  `json:"workspace"`
	Count     int     `json:"count"`
	AvgMs     float64 `json:"avg_ms"`
}

type WorkspaceStat

type WorkspaceStat struct {
	Ops      int     `json:"ops"`
	Errors   int     `json:"errors"`
	Warnings int     `json:"warnings"`
	P50Ms    int64   `json:"p50_ms"`
	AvgMs    float64 `json:"avg_ms"`
}

Jump to

Keyboard shortcuts

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