Skip to content

Commit

Permalink
Implement histogram_quantile()
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Volz <[email protected]>
  • Loading branch information
juliusv committed May 15, 2019
1 parent 18dfe0e commit ac8e300
Show file tree
Hide file tree
Showing 6 changed files with 1,023 additions and 78 deletions.
16 changes: 16 additions & 0 deletions promflux/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,22 @@ func (t *transpiler) transpileCall(c *promql.Call) (ast.Expression, error) {
"fn": setConstValueFn(args[0]),
}),
), nil
case "histogram_quantile":
if yieldsTable(c.Args[0]) {
return nil, fmt.Errorf("non-const scalar expressions not supported yet")
}

return buildPipeline(
args[1],
call("group", map[string]ast.Expression{
"columns": columnList("_time", "_value", "le"),
"mode": &ast.StringLiteral{Value: "except"},
}),
call("promql.promHistogramQuantile", map[string]ast.Expression{
"quantile": args[0],
}),
dropMeasurementCall,
), nil
default:
return nil, fmt.Errorf("PromQL function %q is not supported yet", c.Func.Name)
}
Expand Down
15 changes: 15 additions & 0 deletions promflux/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,21 @@ var queries = []struct {
{
query: `vector(time())`,
},
{
query: `histogram_quantile({{.quantile}}, rate(demo_api_request_duration_seconds_bucket[1m]))`,
variantArgs: []string{"quantile"},
},
{
query: `histogram_quantile(0.9, nonexistent_metric)`,
},
{
// Missing "le" label.
query: `histogram_quantile(0.9, demo_cpu_usage_seconds_total)`,
},
{
// Missing "le" label only in some series of the same grouping.
query: `histogram_quantile(0.9, {__name__=~"demo_api_request_duration_seconds_.+"})`,
},

// Subqueries. Comparisons are skipped since the implementation cannot guarantee completely identical results.
{
Expand Down
Loading

0 comments on commit ac8e300

Please sign in to comment.