core

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	Status      string `json:"status"` // "pass", "fail", "warn"
	Message     string `json:"message,omitempty"`
	DurationMS  int64  `json:"duration_ms"`
	LastChecked string `json:"last_checked"`
}

CheckResult represents the result of a health check

type HealthChecker

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

HealthChecker provides health check functionality

func NewHealthChecker

func NewHealthChecker(providers []model.Provider, sinks []model.Sink) *HealthChecker

NewHealthChecker creates a new health checker

func (*HealthChecker) CheckHealth

func (h *HealthChecker) CheckHealth(ctx context.Context) HealthStatus

CheckHealth performs all health checks

func (*HealthChecker) GetStatus

func (h *HealthChecker) GetStatus() HealthStatus

GetStatus returns the current health status

func (*HealthChecker) ServeHealth

func (h *HealthChecker) ServeHealth() http.Handler

ServeHealth provides an HTTP handler for health checks

type HealthStatus

type HealthStatus struct {
	Status    string                 `json:"status"` // "healthy", "degraded", "unhealthy"
	Timestamp time.Time              `json:"timestamp"`
	Checks    map[string]CheckResult `json:"checks"`
}

HealthStatus represents the overall health status

type MemoryOffsetStore

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

MemoryOffsetStore is an in-memory implementation of OffsetStore for testing

func NewMemoryOffsetStore

func NewMemoryOffsetStore() *MemoryOffsetStore

NewMemoryOffsetStore creates a new in-memory offset store

func (*MemoryOffsetStore) GetLastRuntimeTime

func (s *MemoryOffsetStore) GetLastRuntimeTime(ctx context.Context, thermostatID string) (time.Time, error)

GetLastRuntimeTime returns the last runtime timestamp for a thermostat

func (*MemoryOffsetStore) GetLastSnapshotTime

func (s *MemoryOffsetStore) GetLastSnapshotTime(ctx context.Context, thermostatID string) (time.Time, error)

GetLastSnapshotTime returns the last snapshot timestamp for a thermostat

func (*MemoryOffsetStore) SetLastRuntimeTime

func (s *MemoryOffsetStore) SetLastRuntimeTime(ctx context.Context, thermostatID string, timestamp time.Time) error

SetLastRuntimeTime sets the last runtime timestamp for a thermostat

func (*MemoryOffsetStore) SetLastSnapshotTime

func (s *MemoryOffsetStore) SetLastSnapshotTime(ctx context.Context, thermostatID string, timestamp time.Time) error

SetLastSnapshotTime sets the last snapshot timestamp for a thermostat

type Metrics

type Metrics struct {
	UptimeSeconds float64                    `json:"uptime_seconds"`
	Providers     map[string]ProviderMetrics `json:"providers"`
	Sinks         map[string]SinkMetrics     `json:"sinks"`
}

Metrics represents the overall metrics structure

type MetricsCollector

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

MetricsCollector provides basic metrics collection

func NewMetricsCollector

func NewMetricsCollector() *MetricsCollector

NewMetricsCollector creates a new metrics collector

func (*MetricsCollector) GetMetrics

func (m *MetricsCollector) GetMetrics() Metrics

GetMetrics returns current metrics

func (*MetricsCollector) RecordProviderError

func (m *MetricsCollector) RecordProviderError(providerName string)

RecordProviderError records a provider error

func (*MetricsCollector) RecordProviderRequest

func (m *MetricsCollector) RecordProviderRequest(providerName string)

RecordProviderRequest records a provider request

func (*MetricsCollector) RecordSinkError

func (m *MetricsCollector) RecordSinkError(sinkName string)

RecordSinkError records a sink error

func (*MetricsCollector) RecordSinkWrite

func (m *MetricsCollector) RecordSinkWrite(sinkName string, documentCount int64)

RecordSinkWrite records a sink write operation

func (*MetricsCollector) ServeMetrics

func (m *MetricsCollector) ServeMetrics() http.Handler

ServeMetrics provides an HTTP handler for metrics

type Normalizer

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

Normalizer converts provider-specific data to canonical format

func NewNormalizer

func NewNormalizer(timezone string) (*Normalizer, error)

NewNormalizer creates a new normalizer

func (*Normalizer) NormalizeDeviceSnapshot

func (n *Normalizer) NormalizeDeviceSnapshot(
	providerData model.Snapshot,
	provider string,
) *model.DeviceSnapshot

NormalizeDeviceSnapshot converts provider snapshot data to canonical format

func (*Normalizer) NormalizeRuntime5m

func (n *Normalizer) NormalizeRuntime5m(providerData model.RuntimeRow, provider string) (*model.Runtime5m, error)

NormalizeRuntime5m converts provider runtime data to canonical format

func (*Normalizer) NormalizeTransition

func (n *Normalizer) NormalizeTransition(
	thermostatRef model.ThermostatRef,
	eventTime time.Time,
	prevState, nextState model.State,
	eventInfo model.EventInfo,
	provider string,
	providerData any,
) *model.Transition

NormalizeTransition creates a transition document from state changes

type OffsetStore

type OffsetStore interface {
	// GetLastRuntimeTime returns the last runtime timestamp for a thermostat
	GetLastRuntimeTime(ctx context.Context, thermostatID string) (time.Time, error)

	// SetLastRuntimeTime sets the last runtime timestamp for a thermostat
	SetLastRuntimeTime(ctx context.Context, thermostatID string, timestamp time.Time) error

	// GetLastSnapshotTime returns the last snapshot timestamp for a thermostat
	GetLastSnapshotTime(ctx context.Context, thermostatID string) (time.Time, error)

	// SetLastSnapshotTime sets the last snapshot timestamp for a thermostat
	SetLastSnapshotTime(ctx context.Context, thermostatID string, timestamp time.Time) error
}

OffsetStore manages persistence of polling offsets

type ProviderMetrics

type ProviderMetrics struct {
	RequestsTotal   int64  `json:"requests_total"`
	ErrorsTotal     int64  `json:"errors_total"`
	LastRequestTime string `json:"last_request_time"`
}

ProviderMetrics represents metrics for a provider

type SQLiteOffsetStore

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

SQLiteOffsetStore implements OffsetStore using SQLite This provides persistent storage of polling offsets across restarts

func NewSQLiteOffsetStore

func NewSQLiteOffsetStore(dbPath string) (*SQLiteOffsetStore, error)

NewSQLiteOffsetStore creates a new SQLite-based offset store The dbPath parameter specifies the path to the SQLite database file

func (*SQLiteOffsetStore) Close

func (s *SQLiteOffsetStore) Close() error

Close closes the database connection

func (*SQLiteOffsetStore) GetLastRuntimeTime

func (s *SQLiteOffsetStore) GetLastRuntimeTime(ctx context.Context, thermostatID string) (time.Time, error)

GetLastRuntimeTime returns the last runtime timestamp for a thermostat

func (*SQLiteOffsetStore) GetLastSnapshotTime

func (s *SQLiteOffsetStore) GetLastSnapshotTime(ctx context.Context, thermostatID string) (time.Time, error)

GetLastSnapshotTime returns the last snapshot timestamp for a thermostat

func (*SQLiteOffsetStore) SetLastRuntimeTime

func (s *SQLiteOffsetStore) SetLastRuntimeTime(ctx context.Context, thermostatID string, timestamp time.Time) error

SetLastRuntimeTime sets the last runtime timestamp for a thermostat

func (*SQLiteOffsetStore) SetLastSnapshotTime

func (s *SQLiteOffsetStore) SetLastSnapshotTime(ctx context.Context, thermostatID string, timestamp time.Time) error

SetLastSnapshotTime sets the last snapshot timestamp for a thermostat

type Scheduler

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

Scheduler manages the polling of thermostats and data collection

func NewScheduler

func NewScheduler(
	providers []model.Provider,
	sinks []model.Sink,
	normalizer *Normalizer,
	offsetStore OffsetStore,
	pollInterval, backfillWindow time.Duration,
	metrics *MetricsCollector,
	logger *slog.Logger,
) *Scheduler

NewScheduler creates a new scheduler

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context) error

Start begins the polling scheduler

type SinkMetrics

type SinkMetrics struct {
	WritesTotal      int64  `json:"writes_total"`
	ErrorsTotal      int64  `json:"errors_total"`
	DocumentsWritten int64  `json:"documents_written"`
	LastWriteTime    string `json:"last_write_time"`
}

SinkMetrics represents metrics for a sink

Jump to

Keyboard shortcuts

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