Documentation
¶
Overview ¶
Package loki ships Beacon logs to a Grafana Loki instance via /loki/api/v1/push. Loki is the most common self-hosted target in homelab deployments — easy to compose, low ceremony, plays nicely with Grafana for ad-hoc querying.
Design notes:
- Async, batched, lossy on shutdown. Logs are NOT critical-path: dropping a few records on a network blip is preferable to blocking app code on a remote write. The batcher accumulates up to MaxBatchSize records or MaxBatchInterval seconds (whichever first) and flushes in one POST.
- One stream per service+level. Loki indexes "labels" (the keys you can filter on cheaply); attribute values go in the unindexed log line as JSON. We intentionally keep the label set tiny — `service` and `level` — to avoid the high- cardinality footgun where every (hash, episode) combination creates its own stream.
- Auth: optional X-Scope-OrgID header for multi-tenant setups, plus optional Basic auth user/pass for managed Loki services.
Operator config (via env vars in the host service's main.go):
BEACON_LOG_LOKI_URL — push endpoint base URL (e.g. http://loki:3100) BEACON_LOG_LOKI_TENANT — optional X-Scope-OrgID BEACON_LOG_LOKI_USER — optional basic auth user BEACON_LOG_LOKI_PASS — optional basic auth password
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Service string
URL string
// Auth (all optional)
TenantID string
BasicUser string
BasicPass string
// Batcher tuning. Defaults are reasonable for steady-state
// homelab traffic; bump MaxBatchSize for very chatty services.
MaxBatchSize int // default 200
MaxBatchInterval time.Duration // default 2s
Timeout time.Duration // default 5s per push
// Client overrides for testing.
HTTPClient *http.Client
}
Config controls the Loki plugin. Service is required so log lines are tagged correctly in Loki's label index.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements log.Plugin. Constructed by New, registered via system.Add(plugin).
func New ¶
New validates config and returns a started plugin. Returns an error when URL is empty (so the caller can decide whether to crash startup or just log a warning and continue without Loki).
func (*Plugin) Close ¶
Close drains pending records up to a timeout. Returns the context error if the deadline is exceeded — the host service can decide whether to surface that to the operator.