TimelessMetrics.PromQL (timeless_metrics v6.0.15)

Copy Markdown View Source

PromQL parser and executor for TSBS DevOps query patterns.

Parses PromQL expressions used by TSBS's VictoriaMetrics adapter into a structured query plan, then routes to the appropriate TimelessMetrics query function.

Supported patterns

# Simple selector
cpu_usage_user{hostname="host_0"}

# Regex label matching
cpu_usage_user{hostname=~"host_0|host_1"}

# Range vector with function
max_over_time(cpu_usage_user{hostname="host_0"}[1h])

# Outer aggregation with group-by
max(max_over_time(cpu_usage_user{hostname=~"host_0|host_1"}[1h])) by (hostname)

# Threshold
max(max_over_time(cpu_usage_user{hostname="host_0"}[1h])) by (hostname) > 90

# Multi-metric with regex __name__
max(max_over_time({__name__=~"cpu_.*",hostname=~"host_0"}[1h])) by (hostname)

Summary

Functions

Execute a parsed PromQL plan against a store.

Parse a PromQL query string into a structured query plan.

Types

t()

@type t() :: %TimelessMetrics.PromQL{
  group_by: [String.t()] | nil,
  inner_function: atom() | nil,
  labels: map(),
  metric: String.t() | nil,
  metric_pattern: String.t() | nil,
  outer_aggregate: atom() | nil,
  range_duration: non_neg_integer() | nil,
  threshold: {:gt, float()} | {:lt, float()} | nil
}

Functions

execute(plan, store, start_ts, end_ts, step)

Execute a parsed PromQL plan against a store.

Returns {:ok, prom_response} with Prometheus API formatted results.

parse(query)

Parse a PromQL query string into a structured query plan.

Returns {:ok, %PromQL{}} or {:error, reason}.