Help us shape the future of Go! Take the 2026 Go Developer Survey

metrics

package
v0.1.70 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, req Request, fetch Fetch) ([]map[string]any, error)

func InitializeWorkspace

func InitializeWorkspace(ctx context.Context, db *sql.DB) error

InitializeWorkspace prepares an owned writable database for metric queries.

func ValidateLabels

func ValidateLabels(labels map[string]string) ([]string, error)

Types

type Fetch

type Fetch func(Source, func(Sample) error) error

type Matcher

type Matcher struct {
	Label string
	Op    string
	Value string
}

Matcher is one label predicate pushed down to a metric source, in Prometheus matcher terms: Op is "=", "!=", "=~" or "!~". Pushdown only narrows what a source fetches; SQLite still evaluates the full WHERE clause, so a source may ignore any matcher it cannot express.

type ProfileRows

type ProfileRows func(name string) (ProfileTable, error)

ProfileRows executes the named profile for a `profiles.<name>` reference.

type ProfileTable

type ProfileTable struct {
	Columns []string
	Rows    []map[string]any
}

ProfileTable is the result of a profile referenced as `profiles.<name>` in metric SQL: its column names and its rows.

type QueryPlan

type QueryPlan struct {
	SQL        string
	Sources    []Source
	Prometheus bool
	Profiles   []string
}

QueryPlan is metric SQL rewritten onto its workspace tables. Prometheus reports a `prometheus(...)` reference; Profiles lists each `profiles.<name>` reference, loaded as table __profile_<index>.

func Plan

func Plan(statement string) (QueryPlan, error)

type Range

type Range struct {
	Start, End time.Time
	Step       time.Duration
}

Range is a PromQL range-query window.

type RangeQuery

type RangeQuery struct {
	Window Range
	Fetch  func(expr string, r Range, emit func(Sample) error) error
}

RangeQuery lets metric SQL read `prometheus(query, [start, end, step])`. Window is the provider's request range, the default for omitted bounds; Fetch evaluates one expression over a range, emitting each sample.

type Request

type Request struct {
	SQL      string
	Args     []any
	Labels   map[string]string
	Range    *RangeQuery
	Profiles ProfileRows
}

Request is one metric SQL statement. Range enables `prometheus(...)` and is nil for providers without range queries; Profiles enables `profiles.<name>` and is nil where no profile resolver is reachable.

type Sample

type Sample struct {
	Time                               time.Time
	Value                              float64
	Labels                             map[string]string
	Metric, Namespace, Statistic, Unit string
}

type Source

type Source struct {
	Name, Transform, Window string
	Filters                 []Matcher
	// contains filtered or unexported fields
}

Source is one `FROM <metric>` table. Filters are the WHERE predicates on its label columns, resolved against the request's parameters.

Jump to

Keyboard shortcuts

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