storage

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package storage is the persistence layer above Ent.

Index

Constants

View Source
const AppConfigSingletonID = 1

AppConfigSingletonID — app_config holds exactly one row, enforced in code.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatedRow

type AggregatedRow struct {
	BucketStartUnixMs int64          `json:"bucket_start_unix_ms"`
	TargetLabel       string         `json:"target_label"`
	Count             int            `json:"count"`
	SuccessCount      int            `json:"success_count"`
	FailCount         int            `json:"fail_count"`
	RTTP50Ms          *float64       `json:"rtt_p50_ms,omitempty"`
	RTTP95Ms          *float64       `json:"rtt_p95_ms,omitempty"`
	RTTP99Ms          *float64       `json:"rtt_p99_ms,omitempty"`
	RTTMaxMs          *float64       `json:"rtt_max_ms,omitempty"`
	RTTMeanMs         *float64       `json:"rtt_mean_ms,omitempty"`
	JitterMs          *float64       `json:"jitter_ms,omitempty"`
	Errors            map[string]int `json:"errors,omitempty"`
}

AggregatedRow is the IPC shape shared across the 1min/5min/1h rollup tiers; granularity is signaled by the response wrapper, not the row.

type AppConfig

type AppConfig struct {
	PingIntervalSec   float64 `json:"ping_interval_sec"`
	FlushIntervalSec  int     `json:"flush_interval_sec"`
	PingTimeoutMs     int     `json:"ping_timeout_ms"`
	RetentionRawDays  int     `json:"retention_raw_days"`
	Retention1minDays int     `json:"retention_1min_days"`
	Retention5minDays int     `json:"retention_5min_days"`
	WifiSampleEnabled bool    `json:"wifi_sample_enabled"`
}

AppConfig is the JSON view of the singleton app_config row.

type AppConfigPatch

type AppConfigPatch struct {
	PingIntervalSec   *float64 `json:"ping_interval_sec,omitempty"`
	FlushIntervalSec  *int     `json:"flush_interval_sec,omitempty"`
	PingTimeoutMs     *int     `json:"ping_timeout_ms,omitempty"`
	RetentionRawDays  *int     `json:"retention_raw_days,omitempty"`
	Retention1minDays *int     `json:"retention_1min_days,omitempty"`
	Retention5minDays *int     `json:"retention_5min_days,omitempty"`
	WifiSampleEnabled *bool    `json:"wifi_sample_enabled,omitempty"`
}

AppConfigPatch — pointer fields distinguish "unset" from intentional zero.

type Client

type Client struct {
	Samples *SampleClient
	Outages *OutageClient
	Targets *TargetClient
	Config  *ConfigClient
	Wifi    *WifiClient
	Seed    *SeedClient
}

Client is the storage-layer entry point. Composes per-resource sub- clients, each of which encapsulates its own Ent table interactions.

func NewClient

func NewClient(entClient *ent.Client) *Client

NewClient wraps an Ent client.

type ConfigClient

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

ConfigClient owns the singleton app_config row.

func NewConfigClient

func NewConfigClient(client *ent.Client) *ConfigClient

NewConfigClient wraps an Ent client.

func (*ConfigClient) Get

func (c *ConfigClient) Get(ctx context.Context) (AppConfig, error)

Get returns the singleton app_config row.

func (*ConfigClient) Update

func (c *ConfigClient) Update(ctx context.Context, patch AppConfigPatch) (AppConfig, error)

Update applies a partial patch (nil fields untouched) and returns the new full config.

type Outage

type Outage struct {
	ID                  string         `json:"id"`
	Scope               string         `json:"scope"`
	StartTSUnixMs       int64          `json:"start_ts_unix_ms"`
	EndTSUnixMs         *int64         `json:"end_ts_unix_ms,omitempty"`
	ConsecutiveFailures int            `json:"consecutive_failures"`
	Errors              map[string]int `json:"errors,omitempty"`
}

Outage matches the outage:start / outage:end event payload so the frontend has one type definition.

type OutageClient

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

OutageClient owns reads against the outage table.

func NewOutageClient

func NewOutageClient(client *ent.Client) *OutageClient

NewOutageClient wraps an Ent client.

func (*OutageClient) Query

Query returns outages overlapping [fromMs, toMs] — either started in the window, or started before but still active at fromMs. Catches the in-progress outage that began before the window so the "outage in progress" badge stays accurate.

type QueryAggregatedParams

type QueryAggregatedParams struct {
	FromMs       int64
	ToMs         int64
	TargetLabels []string
}

QueryAggregatedParams scopes a rollup-tier read.

type QueryOutagesParams

type QueryOutagesParams struct {
	FromMs   int64
	ToMs     int64
	Scope    string
	OnlyOpen bool
}

QueryOutagesParams scopes a list-outages call.

type QuerySamplesParams

type QuerySamplesParams struct {
	FromMs       int64
	ToMs         int64
	TargetLabels []string
	Limit        int
}

QuerySamplesParams — FromMs/ToMs are inclusive unix-ms bounds; Limit > 0 caps result count to keep IPC payloads bounded.

type Sample

type Sample struct {
	TSUnixMs    int64    `json:"ts_unix_ms"`
	TargetLabel string   `json:"target_label"`
	TargetKind  string   `json:"target_kind"`
	TargetHost  string   `json:"target_host"`
	TargetPort  *int     `json:"target_port,omitempty"`
	Success     bool     `json:"success"`
	RTTMs       *float64 `json:"rtt_ms,omitempty"`
	Error       *string  `json:"error,omitempty"`
}

Sample is the IPC-shape view of a single probe result.

type SampleClient

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

SampleClient owns reads against the raw + rollup sample tables.

func NewSampleClient

func NewSampleClient(client *ent.Client) *SampleClient

NewSampleClient wraps an Ent client.

func (*SampleClient) Query

Query returns raw samples in [FromMs, ToMs] ordered ascending by timestamp.

func (*SampleClient) Query1H

Query1H returns 1-hour rollup buckets in the window.

func (*SampleClient) Query1Min

Query1Min returns 1-minute rollup buckets in the window.

func (*SampleClient) Query5Min

Query5Min returns 5-minute rollup buckets in the window.

type SeedClient

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

SeedClient owns first-run seeding of builtin targets and the singleton app_config row.

func NewSeedClient

func NewSeedClient(client *ent.Client) *SeedClient

NewSeedClient wraps an Ent client.

func (*SeedClient) AppConfig

func (c *SeedClient) AppConfig(ctx context.Context) error

AppConfig inserts the singleton app_config row on first run.

func (*SeedClient) DefaultTargets

func (c *SeedClient) DefaultTargets(ctx context.Context) error

DefaultTargets inserts the builtin probe targets only when the table is empty — a user who has deleted every default should not see them resurrected on the next boot.

type Target

type Target struct {
	ID        string      `json:"id"`
	Label     string      `json:"label"`
	Kind      probes.Kind `json:"kind"`
	Host      string      `json:"host"`
	Port      *int        `json:"port,omitempty"`
	Enabled   bool        `json:"enabled"`
	IsBuiltin bool        `json:"is_builtin"`
}

Target adds DB-level metadata (id, is_builtin) on top of probes.Target, which deliberately omits CRUD identity.

type TargetClient

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

TargetClient owns CRUD against the target table.

func NewTargetClient

func NewTargetClient(client *ent.Client) *TargetClient

NewTargetClient wraps an Ent client.

func (*TargetClient) Create

func (c *TargetClient) Create(ctx context.Context, req TargetRequest) (Target, error)

Create inserts a user-defined target with is_builtin=false.

func (*TargetClient) Delete

func (c *TargetClient) Delete(ctx context.Context, id string) error

Delete — builtin guard lives at the handler so it can return a typed error.

func (*TargetClient) Get

func (c *TargetClient) Get(ctx context.Context, id string) (Target, error)

Get fetches a target by id.

func (*TargetClient) List

func (c *TargetClient) List(ctx context.Context) ([]Target, error)

List returns every target ordered by label.

func (*TargetClient) ListEnabledProbes

func (c *TargetClient) ListEnabledProbes(ctx context.Context) ([]probes.Probe, error)

ListEnabledProbes returns built Probe instances for every enabled target.

func (*TargetClient) Update

func (c *TargetClient) Update(ctx context.Context, id string, req TargetUpdateRequest) (Target, error)

Update — handler enforces the builtin host/port/kind immutability; this layer trusts its caller.

type TargetRequest

type TargetRequest struct {
	Label string
	Kind  probes.Kind
	Host  string
	Port  *int
}

TargetRequest is the input shape for Create.

type TargetUpdateRequest

type TargetUpdateRequest struct {
	Enabled *bool
	Host    *string
	Port    *int
}

TargetUpdateRequest is the input shape for Update. All fields optional; nil means "leave unchanged".

type WifiClient

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

WifiClient owns reads against the wifi_sample table.

func NewWifiClient

func NewWifiClient(client *ent.Client) *WifiClient

NewWifiClient wraps an Ent client.

func (*WifiClient) Query

func (c *WifiClient) Query(ctx context.Context, fromMs, toMs int64) ([]WifiSample, error)

Query returns Wi-Fi samples in [fromMs, toMs] ordered by time. One sample per minute means a 7-day window is ~10K rows — no pagination needed.

type WifiSample

type WifiSample struct {
	TSUnixMs      int64    `json:"ts_unix_ms"`
	SSID          *string  `json:"ssid,omitempty"`
	BSSID         *string  `json:"bssid,omitempty"`
	SignalPercent *int     `json:"signal_percent,omitempty"`
	RSSIDbm       *int     `json:"rssi_dbm,omitempty"`
	RxRateMbps    *float64 `json:"rx_rate_mbps,omitempty"`
	TxRateMbps    *float64 `json:"tx_rate_mbps,omitempty"`
	Channel       *string  `json:"channel,omitempty"`
}

WifiSample is the IPC-shape view of one Wi-Fi observation.

Jump to

Keyboard shortcuts

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