Skip to main content
Version: 3.7.0

PromQL Syntax Guide

Prerequisites

Important Notes

Due to differences in how metrics are stored in Prometheus versus Bonree, the following modifications have been made to PromQL syntax support:

  1. For instant queries, Bonree frm and custom metric types, as well as metrics lacking a last aggregation method, are not supported.

    • Explanation: The semantics of an instant vector require the most recent value from the last 5 minutes for each time series. Bonree metrics are stored pre-aggregated by time granularity. Only metrics that support the last (latest value) aggregation method can be used for this type of query.
  2. Range vectors do not support querying detailed raw data. Instead, calculations are based on the current time range granularity using the metric's default aggregation method.

    • Explanation: The semantics of a range vector require the detailed raw data points reported over a time range. Bonree uses pre-aggregation, summarizing data by time granularity beforehand. For performance reasons, when the time range is long, the range vector query will use the granularity of the target table and the metric's default aggregation method, making it impossible to retrieve fine-grained raw data.
  3. The <aggregation>_over_time() functions perform calculations on range vector data. Whether a function can be used depends on whether the metric supports the corresponding aggregation method.

    • Explanation: The agg_over_time functions (except stddev_over_time and stdvar_over_time) are used to aggregate detailed data within a range_vector. If the metric does not support the required aggregation method, the query will fail.
  4. It is recommended to use PromQL primarily for querying metrics data ingested from Prometheus.

Query Types

  • Similar to Prometheus, both instant and range query types are supported.
  • Range queries do not support custom step values; internal default rules apply (see Granularity section below).

Granularity

When querying metric data, point aggregation is performed at different time granularities depending on the selected time range.

  • Range Query Granularity:
Time RangeGranularity
≤30 minutes15 seconds
≤3 hours1 minute
≤24 hours10 minutes
≤7 days1 hour
≤14 days6 hours
≥14 days1 day

PromQL Syntax Support List

(Based on Prometheus 2.53, https://prometheus.io/docs/prometheus/latest/querying/basics/)

Items marked in yellow in the table represent unsupported syntax.

CategoryName & DetailsSupported
Basic Data Typesinstant vector
range vectorModified
literals (numeric and string constants)
Selectors= (match string)
!= (not match string)
=~ (regex match)
!~ (regex not match)
Time Selection@ (evaluation time, e.g., http_requests_total @ 1609746000)
offset (time offset, e.g., http_requests_total offset 1m. Note: For range queries, original timestamps are not preserved)Modified
[duration] (range time, e.g., http_requests_total[1m])
Subquerye.g., <instant_query>[<range>:<resolution>]
Arithmetic Binary Ops+ (addition), - (subtraction), * (multiplication), / (division), % (modulo), ^ (exponentiation)
Comparison Binary Ops== (equal), != (not equal), > (greater than), < (less than), ≥ (greater/equal), ≤ (less/equal)
Operation between two scalars
bool keyword
Set Binary Opsand, or, unless
Vector Matchinggroup_left, group_right, on, ignoring
Aggregation Operatorssum (calculate sum over dimensions)
min (select minimum over dimensions)
max (select maximum over dimensions)
avg (calculate average over dimensions)
group (all values in the resulting vector are 1)
stddev (calculate population standard deviation over dimensions)
stdvar (calculate population standard variance over dimensions)
count (count number of elements in the vector)
count_values (count number of elements with the same value)
bottomk (smallest k elements by sample value)Modified
topk (largest k elements by sample value)Modified
Over Time Functionsavg_over_time(range-vector)
min_over_time(range-vector)
max_over_time(range-vector)
sum_over_time(range-vector)
count_over_time(range-vector)
quantile_over_time(scalar, range-vector)
stddev_over_time(range-vector)
stdvar_over_time(range-vector)
last_over_time(range-vector)
Trigonometric Functionsacos(v instant-vector), acosh(v instant-vector), asin(v instant-vector), asinh(v instant-vector),
atan(v instant-vector), atanh(v instant-vector), cos(v instant-vector), cosh(v instant-vector),
sin(v instant-vector), sinh(v instant-vector), tan(v instant-vector), tanh(v instant-vector)
Functionsabs(v instant-vector)
ceil(v instant-vector)
changes(v range-vector)
delta(v range-vector)
deriv(v range-vector)
exp(v instant-vector)
floor(v instant-vector)
holt_winters(v range-vector, sf scalar, tf scalar)
idelta(v range-vector)
increase(v range-vector)
irate(v range-vector)
ln(v instant-vector)
log2(v instant-vector)
log10(v instant-vector)
predict_linear(v range-vector, t scalar)
rate(v range-vector)
resets(v range-vector)
round(v instant-vector, to_nearest=1 scalar)
scalar(v instant-vector)
sgn(v instant-vector)
sort(v instant-vector)
sort_desc(v instant-vector)
sqrt(v instant-vector)
Special Notes1. {job="localhosts"} (querying all metrics with job label) is not supported. A specific metric name must be specified in PromQL queries.
2. The @ modifier must be placed after the selector.

Known Issues & Explanations

  1. Using the @ modifier in Range Queries

    • Issue: Using @ modifies the overall evaluation time (endTime). In Prometheus, the PromQL is executed at each step based on that @ time.
    • Status: Behavior differs from native Prometheus.
  2. Using the offset modifier in Range Queries

    • Issue: Using offset shifts the overall evaluation time (endTime), which also causes the timestamps in the actual result values to be offset. In Prometheus, the PromQL is executed at each step based on the shifted time.
    • Status: Behavior differs from native Prometheus.
  3. Range Vector Duration Exceeding Step in Range Queries

    • Issue: In a range query involving a range vector (e.g., metric_name[1m]), the range duration ([1m]) must be less than or equal to the query step. If it is larger, the effective range duration is set equal to the step.
    • Status: Implemented limitation.
  4. Subqueries and @/offset

    • Issue: Using offset or @ inside the instant query part of a subquery is not supported, as it can affect the overall evaluation time and lead to incorrect query time ranges.
    • Status: Not supported.
  5. topk and bottomk Functions

    • Issue: When these sorting functions are used with grouping (by/without), the results may be inaccurate. The current implementation performs sorting on the entire result set after grouping, rather than sorting within each group.
    • Status: Implemented with limitation.