loki

package
v0.0.1-dev.137 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package loki implements observe.LogStore against a Loki backend (the light optional sink). It is Core-tier only: it re-emits the parsed Query AST to Loki's HTTP API (it never parses LogQL — the ObserveService does that and hands this store the AST, which renderLogQL turns back into a LogQL string) and writes via Loki's push API.

Loki is object-storage-native: chunks flush to S3/GCS as the primary durable store, so this adapter has no tiering of its own — long retention is a Loki deployment concern, not the adapter's (plan §6.4).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// BaseURL is the Loki HTTP endpoint (e.g. http://loki:3100).
	BaseURL string

	// TenantID is sent as the X-Scope-OrgID header for multi-tenant Loki.
	// Empty for single-tenant deployments.
	TenantID string

	// Timeout bounds a single HTTP request to Loki. Zero uses a default.
	Timeout time.Duration

	// HTTPClient overrides the client used for requests. nil uses a default.
	HTTPClient *http.Client
}

Config configures the Loki store.

type Store

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

Store is the Loki-backed observe.LogStore.

func New

func New(cfg Config) (*Store, error)

New constructs a Loki store. It does not dial Loki; call Health to verify connectivity.

func (*Store) Capabilities

func (s *Store) Capabilities() observe.Capabilities

Capabilities reports the Loki capability handshake: Core tier only. No raw SQL, no percentiles, no cheap high-cardinality filters (cardinality is Loki's OOM failure mode).

func (*Store) Execute

func (s *Store) Execute(ctx context.Context, q *observe.Query) (observe.ResultStream, error)

Execute renders the AST to LogQL and runs it against Loki's query_range endpoint, wrapping the streamed JSON in a ResultStream. RawSQL and Advanced- tier aggregations (percentiles) are rejected with ErrCapabilityUnsupported.

func (*Store) Health

func (s *Store) Health(ctx context.Context) error

Health probes Loki readiness via GET /ready.

func (*Store) Labels

func (s *Store) Labels(ctx context.Context, sel observe.Selector) ([]observe.LabelValue, error)

Labels enumerates label names (sel.Name=="") or the values of a named dimension via Loki's label API. Loki does not return occurrence counts, so LabelValue.Count stays 0.

func (*Store) Write

func (s *Store) Write(ctx context.Context, batch []observe.LogRecord) error

Write persists a batch via Loki's push API. Records are grouped into Loki streams keyed by their StreamLabels, and each stream's values are sorted ascending by timestamp (Loki rejects out-of-order values within a stream on older deployments).

Jump to

Keyboard shortcuts

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