Prometheus PromQL Variable Go SDK

Constructor#

import "github.com/perses/plugins/prometheus/sdk/go/promql"

var options []promql.Option
promql.PrometheusPromQL("group by (namespace) (kube_namespace_labels{}", options...)

Need to provide the name of the variable and a list of options.

Default options#

  • Expr(): with the expr provided in the constructor.

Available options#

Expr#

import "github.com/perses/plugins/prometheus/sdk/go/promql" 

promql.Expr("group by (namespace) (kube_namespace_labels{}")

Define the promQL metadata name and the display name.

LabelName#

import "github.com/perses/plugins/prometheus/sdk/go/promql"

promql.LabelName("my_super_label_name")

Define a label name that can filter the result of the expression.

Datasource#

import "github.com/perses/plugins/prometheus/sdk/go/promql"

promql.Datasource("datasourceName")

Define the datasource where the expression will be executed.

Example#

package main

import (
	"github.com/perses/perses/go-sdk/dashboard"
	listvariable "github.com/perses/perses/go-sdk/variable/list-variable"
	"github.com/perses/plugins/prometheus/sdk/go/variable/promql"
)

func main() {
	dashboard.New("Example Dashboard",
		dashboard.AddVariable("namespace", listvariable.List(
			promql.PrometheusPromQL("group by (namespace) (kube_namespace_labels{stack=\"$stack\",prometheus=\"$prometheus\",prometheus_namespace=\"$prometheus_namespace\"})",
				promql.LabelName("namespace"),
				promql.Datasource("promDemo"),
			),
			listvariable.AllowMultiple(true),
		)),
	)
}