Binary operators :: Kloudfuse Docs

Binary operators

Binary operators combine two expressions. Between vectors, series are matched by label set — the vector matching keywords control exactly how.

Arithmetic operators

Combines two expressions — or an expression and a scalar — with +, -, *, /, %, or ^. Between two vectors, series with identical label sets are matched pairwise; unmatched series drop out of the result.

Syntax

<expr> <op> <expr>    where <op> is + - * / % ^

Parameters

Parameter Required Description
<expr> Required A vector expression or scalar literal on either side.

Example

Compute each Kloudfuse query service’s share of the group’s total goroutines, as a percentage.

  sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_name=~".*query-service"})
/ on () group_left ()
  sum(go_goroutines{app_kubernetes_io_name=~".*query-service"})
* 100
app_kubernetes_io_name Value
trace-query-service 3.342
events-query-service 3.296
logs-query-service 21.32
rum-query-service 1.438
query-service 70.6

Expected output

Division by zero produces no result for that series rather than an error.
Standard precedence applies (^ highest, then * / %, then + -); parenthesize to override.

Comparison operators

Compares values with ==, !=, >, >=, <, or . Against a scalar the comparison filters: series that fail the test are dropped — exactly the shape an alert condition needs. The bool modifier keeps every series and returns 1 or 0 instead.

Syntax

<expr> > <scalar>    (also ==, !=, >=, <, <=; add bool for 0/1)

Parameters

Parameter Required Description
<scalar> Required The threshold, or another vector for pairwise comparison.
bool Optional Return 1/0 per series instead of filtering: > bool 100.

Example

Keep only the Kloudfuse services currently running more than 100 goroutines.

sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_instance="kfuse"})
> 100
app_kubernetes_io_name Value
zapper 2,566
kfuse-redis 584
az-service 1,009
logs-query-service 19,306
query-service 64,236

Expected output

Alert rules use this form directly: the alert fires while the filtered result is non-empty.

Set operators (and, or, unless)

Combines two vectors as sets keyed by label values: and keeps left-side series with a match on the right, or returns the left plus unmatched right-side series, and unless keeps left-side series with no match on the right. Values come from the left side.

Syntax

<expr> and <expr>  |  <expr> or <expr>  |  <expr> unless <expr>

Parameters

Parameter Required Description
<expr> Required Vector expressions on both sides; matching is by identical label sets.

Example

List Kloudfuse services' goroutine counts, excluding services that are currently above 500 — unless subtracts the right-hand set.

  sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_instance="kfuse"})
unless
  sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_instance="kfuse"}) > 500
app_kubernetes_io_name Value
recorder 14
archive-writer 103
analytics-service 11

Expected output

<query> or vector(0) is the standard fallback idiom for guaranteeing a result row.

Vector matching (on, ignoring, group_left)

By default a binary operator matches series whose full label sets are identical. on (labels) restricts matching to the listed labels; ignoring (labels) matches on everything else. When one side has fewer series, group_left / group_right declare the many-to-one direction and can copy labels from the one side.

Syntax

<expr> <op> on (<labels>) [group_left [(<labels>)] ] <expr>

Parameters

Parameter Required Description
on (<labels>) Optional Match series using only these labels.
ignoring (<labels>) Optional Match series using all labels except these.
group_left / group_right Optional Allow many-to-one matching; the side named by the modifier is the many side.

Example

Divide each service’s goroutine count by the all-service total: on () matches every left series to the single right-side series, and group_left () permits the many-to-one pairing.

  sum by (app_kubernetes_io_name) (go_goroutines{app_kubernetes_io_instance="kfuse"})
/ on () group_left ()
  sum(go_goroutines{app_kubernetes_io_instance="kfuse"})
app_kubernetes_io_name Value
logs-transformer 0.00696586
recorder 3.63482e-05
trace-transformer 0.2496
hydration-service 0.00142796
ingress-nginx 0.01019

Expected output

Without group_left, a many-to-one match is an error — PromQL makes the direction explicit on purpose.