daemon

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LaunchdDaemonLabel = "com.openusage.telemetryd"
	SystemdDaemonUnit  = "openusage-telemetry.service"
)
View Source
const APIVersion = "v1"

Variables

This section is empty.

Functions

func ApplyCredentials

func ApplyCredentials(accounts []core.AccountConfig) []core.AccountConfig

func DisabledAccountsFromConfig

func DisabledAccountsFromConfig() map[string]bool

func DisabledAccountsFromDashboard

func DisabledAccountsFromDashboard(dashboardCfg config.DashboardConfig) map[string]bool

func EnsureSocketPathAvailable

func EnsureSocketPathAvailable(socketPath string) error

func FilterAccountsByDashboard

func FilterAccountsByDashboard(
	accounts []core.AccountConfig,
	dashboardCfg config.DashboardConfig,
) []core.AccountConfig

func FlushInBatches

func FlushInBatches(ctx context.Context, pipeline *telemetry.Pipeline, maxTotal int) (telemetry.FlushResult, []string)

func HealthAPICompatible

func HealthAPICompatible(health HealthResponse) bool

func HealthCurrent

func HealthCurrent(health HealthResponse) bool

func HealthProviderRegistryCompatible added in v0.6.0

func HealthProviderRegistryCompatible(health HealthResponse) bool

func HealthVersion

func HealthVersion(health HealthResponse) string

func InstallService

func InstallService(socketPath string) error

func IsReleaseSemver

func IsReleaseSemver(value string) bool

func LastErrorLine added in v0.6.0

func LastErrorLine(path string) string

func ProviderRegistryHash added in v0.6.0

func ProviderRegistryHash() string

ProviderRegistryHash returns a stable fingerprint for the set of registered providers.

func ReadModelRequestKey

func ReadModelRequestKey(req ReadModelRequest) string

func ReadModelTemplatesFromRequest

func ReadModelTemplatesFromRequest(
	req ReadModelRequest,
	disabledAccounts map[string]bool,
) map[string]core.UsageSnapshot

func ResolveAccounts

func ResolveAccounts(cfg *config.Config) []core.AccountConfig

func ResolveSocketPath

func ResolveSocketPath() string

func ResolveSocketPathWithError

func ResolveSocketPathWithError() (string, error)

func RunCommand

func RunCommand(name string, args ...string) (string, error)

func RunServer

func RunServer(cfg Config) error

func ServiceStatus

func ServiceStatus(socketPath string, details bool) error

func SnapshotsHaveUsableData

func SnapshotsHaveUsableData(snaps map[string]core.UsageSnapshot) bool

func SocketOwnerSummary added in v0.6.0

func SocketOwnerSummary(socketPath string) string

func StartBroadcaster

func StartBroadcaster(
	ctx context.Context,
	rt *ViewRuntime,
	refreshInterval time.Duration,
	handler SnapshotHandler,
	stateHandler StateHandler,
)

func StartupDiagnostics

func StartupDiagnostics(manager ServiceManager, socketPath string) string

func TailFile

func TailFile(path string, maxLines int) string

func TailTextLines

func TailTextLines(text string, maxLines int) string

func UninstallService

func UninstallService(socketPath string) error

func WaitForHealth

func WaitForHealth(ctx context.Context, client *Client, timeout time.Duration) error

Types

type Client

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

func EnsureRunning

func EnsureRunning(ctx context.Context, socketPath string, verbose bool) (*Client, error)

func NewClient

func NewClient(socketPath string) *Client

func (*Client) HealthInfo

func (c *Client) HealthInfo(ctx context.Context) (HealthResponse, error)

func (*Client) IngestHook

func (c *Client) IngestHook(
	ctx context.Context,
	source string,
	accountID string,
	payload []byte,
) (HookResponse, error)

func (*Client) ReadModel

func (c *Client) ReadModel(
	ctx context.Context,
	request ReadModelRequest,
) (map[string]core.UsageSnapshot, error)

type Config

type Config struct {
	DBPath          string
	SpoolDir        string
	SocketPath      string
	CollectInterval time.Duration
	PollInterval    time.Duration
	Verbose         bool
}

type DaemonState

type DaemonState struct {
	Status      DaemonStatus
	Message     string
	InstallHint string
}

func ClassifyEnsureError

func ClassifyEnsureError(err error) DaemonState

type DaemonStatus

type DaemonStatus int
const (
	DaemonStatusUnknown      DaemonStatus = iota
	DaemonStatusConnecting                // attempting to reach daemon
	DaemonStatusNotInstalled              // service not installed
	DaemonStatusStarting                  // service installed, waiting for health
	DaemonStatusRunning                   // healthy and current
	DaemonStatusOutdated                  // healthy but wrong version
	DaemonStatusError                     // unrecoverable error
)

type HealthResponse

type HealthResponse struct {
	Status             string `json:"status"`
	DaemonVersion      string `json:"daemon_version,omitempty"`
	APIVersion         string `json:"api_version,omitempty"`
	IntegrationVersion string `json:"integration_version,omitempty"`
	ProviderRegistry   string `json:"provider_registry_hash,omitempty"`
}

func WaitForHealthInfo

func WaitForHealthInfo(
	ctx context.Context,
	client *Client,
	timeout time.Duration,
) (HealthResponse, error)

type HookResponse

type HookResponse struct {
	Source    string   `json:"source"`
	Enqueued  int      `json:"enqueued"`
	Processed int      `json:"processed"`
	Ingested  int      `json:"ingested"`
	Deduped   int      `json:"deduped"`
	Failed    int      `json:"failed"`
	Warnings  []string `json:"warnings,omitempty"`
}

type ReadModelAccount

type ReadModelAccount struct {
	AccountID  string `json:"account_id"`
	ProviderID string `json:"provider_id"`
}

type ReadModelRequest

type ReadModelRequest struct {
	Accounts      []ReadModelAccount `json:"accounts"`
	ProviderLinks map[string]string  `json:"provider_links"`
	TimeWindow    string             `json:"time_window,omitempty"`
}

func BuildReadModelRequest

func BuildReadModelRequest(
	accounts []core.AccountConfig,
	providerLinks map[string]string,
	timeWindow string,
) ReadModelRequest

func BuildReadModelRequestFromConfig

func BuildReadModelRequestFromConfig() (ReadModelRequest, error)

type ReadModelResponse

type ReadModelResponse struct {
	Snapshots map[string]core.UsageSnapshot `json:"snapshots"`
}

type Service

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

func (*Service) Close

func (s *Service) Close() error

type ServiceManager

type ServiceManager struct {
	Kind string
	// contains filtered or unexported fields
}

func NewServiceManager

func NewServiceManager(socketPath string) (ServiceManager, error)

func (ServiceManager) Install

func (m ServiceManager) Install() error

func (ServiceManager) InstallHint

func (m ServiceManager) InstallHint() string

func (ServiceManager) IsInstalled

func (m ServiceManager) IsInstalled() bool

func (ServiceManager) IsSupported

func (m ServiceManager) IsSupported() bool

func (ServiceManager) Start

func (m ServiceManager) Start() error

func (ServiceManager) StatusHint

func (m ServiceManager) StatusHint() string

func (ServiceManager) StderrLogPath

func (m ServiceManager) StderrLogPath() string

func (ServiceManager) StdoutLogPath

func (m ServiceManager) StdoutLogPath() string

func (ServiceManager) Uninstall

func (m ServiceManager) Uninstall() error

type SnapshotHandler

type SnapshotHandler func(map[string]core.UsageSnapshot)

type StateHandler

type StateHandler func(DaemonState)

type ViewRuntime

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

func NewViewRuntime

func NewViewRuntime(
	client *Client,
	socketPath string,
	verbose bool,
) *ViewRuntime

func (*ViewRuntime) CurrentClient

func (r *ViewRuntime) CurrentClient() *Client

func (*ViewRuntime) EnsureClient

func (r *ViewRuntime) EnsureClient(ctx context.Context) *Client

func (*ViewRuntime) ReadWithFallback

func (r *ViewRuntime) ReadWithFallback(ctx context.Context) map[string]core.UsageSnapshot

func (*ViewRuntime) ResetEnsureThrottle

func (r *ViewRuntime) ResetEnsureThrottle()

func (*ViewRuntime) SetClient

func (r *ViewRuntime) SetClient(client *Client)

func (*ViewRuntime) SetTimeWindow added in v0.5.2

func (r *ViewRuntime) SetTimeWindow(tw string)

func (*ViewRuntime) State

func (r *ViewRuntime) State() DaemonState

func (*ViewRuntime) TimeWindow added in v0.5.2

func (r *ViewRuntime) TimeWindow() string

Jump to

Keyboard shortcuts

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