File: utils_example_test.go

package info (click to toggle)
golang-github-victoriametrics-metricsql 0.84.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 344 kB
  • sloc: makefile: 2
file content (28 lines) | stat: -rw-r--r-- 690 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package metricsql_test

import (
	"fmt"
	"log"

	"github.com/VictoriaMetrics/metricsql"
)

func ExampleExpandWithExprs() {
	// mql can contain arbitrary MetricsQL extensions - see https://docs.victoriametrics.com/metricsql/
	mql := `WITH (
		commonFilters = {job="$job", instance="$instance"},
		f(a, b) = 100*(a/b),
	)
	f(disk_free_bytes{commonFilters}, disk_total_bytes{commonFilters})`

	// Convert mql to PromQL
	pql, err := metricsql.ExpandWithExprs(mql)
	if err != nil {
		log.Fatalf("cannot expand with expressions: %s", err)
	}

	fmt.Printf("%s\n", pql)

	// Output:
	// 100 * (disk_free_bytes{job="$job",instance="$instance"} / disk_total_bytes{job="$job",instance="$instance"})
}