From 3d096db969a91d0e36b4c6a175a810c1936c670a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sat, 27 Mar 2021 19:56:22 +0100 Subject: [PATCH 1/2] Update grabana to v0.14.0 --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/K-Phoen/grabana/Makefile | 9 +++++ .../K-Phoen/grabana/decoder/graph.go | 3 ++ .../K-Phoen/grabana/decoder/heatmap.go | 3 ++ .../K-Phoen/grabana/decoder/singlestat.go | 3 ++ .../K-Phoen/grabana/decoder/table.go | 3 ++ .../K-Phoen/grabana/decoder/target.go | 20 ++++++++++ .../github.com/K-Phoen/grabana/graph/graph.go | 10 +++++ .../K-Phoen/grabana/heatmap/heatmap.go | 10 +++++ .../K-Phoen/grabana/singlestat/singlestat.go | 10 +++++ .../github.com/K-Phoen/grabana/table/table.go | 10 +++++ .../grabana/target/graphite/graphite.go | 40 +++++++++++++++++++ vendor/modules.txt | 3 +- 14 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 vendor/github.com/K-Phoen/grabana/target/graphite/graphite.go diff --git a/go.mod b/go.mod index af37703c..f6d3366d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/K-Phoen/dark go 1.13 require ( - github.com/K-Phoen/grabana v0.13.6 + github.com/K-Phoen/grabana v0.14.0 github.com/caarlos0/env v3.5.0+incompatible github.com/go-playground/universal-translator v0.17.0 // indirect github.com/grafana-tools/sdk v0.0.0-20210301100910-d23004341fc8 diff --git a/go.sum b/go.sum index 43aee5ca..7d5489a4 100644 --- a/go.sum +++ b/go.sum @@ -27,8 +27,8 @@ github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbt github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/K-Phoen/grabana v0.13.6 h1:JDmseoI4IVjimgCI3JNoKcMuAtiHT2eY/hloiNYGLJI= -github.com/K-Phoen/grabana v0.13.6/go.mod h1:eQVdbgP2ygxaeSEb08+0Q1K++ewawO0sHXVQgG/SuCw= +github.com/K-Phoen/grabana v0.14.0 h1:dRymBPMrQ5wzXMPUBAtysepDB/up5kaFT0VuR5ufKeo= +github.com/K-Phoen/grabana v0.14.0/go.mod h1:eQVdbgP2ygxaeSEb08+0Q1K++ewawO0sHXVQgG/SuCw= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= diff --git a/vendor/github.com/K-Phoen/grabana/Makefile b/vendor/github.com/K-Phoen/grabana/Makefile index 181df5b5..8b6a82c7 100644 --- a/vendor/github.com/K-Phoen/grabana/Makefile +++ b/vendor/github.com/K-Phoen/grabana/Makefile @@ -26,6 +26,15 @@ up: -p 9090:9090 \ -v $(shell pwd)/testdata/prometheus.yml:/etc/prometheus/prometheus.yml \ prom/prometheus + docker run -d\ + --name graphite\ + --restart=always\ + -p 8081:80\ + -p 2003-2004:2003-2004\ + -p 2023-2024:2023-2024\ + -p 8125:8125/udp\ + -p 8126:8126\ + graphiteapp/graphite-statsd docker run -d \ -p 3000:3000 \ --name=grabana_grafana \ diff --git a/vendor/github.com/K-Phoen/grabana/decoder/graph.go b/vendor/github.com/K-Phoen/grabana/decoder/graph.go index f4cbf3d1..c0740825 100644 --- a/vendor/github.com/K-Phoen/grabana/decoder/graph.go +++ b/vendor/github.com/K-Phoen/grabana/decoder/graph.go @@ -159,6 +159,9 @@ func (graphPanel *DashboardGraph) target(t Target) (graph.Option, error) { if t.Prometheus != nil { return graph.WithPrometheusTarget(t.Prometheus.Query, t.Prometheus.toOptions()...), nil } + if t.Graphite != nil { + return graph.WithGraphiteTarget(t.Graphite.Query, t.Graphite.toOptions()...), nil + } if t.Stackdriver != nil { stackdriverTarget, err := t.Stackdriver.toTarget() if err != nil { diff --git a/vendor/github.com/K-Phoen/grabana/decoder/heatmap.go b/vendor/github.com/K-Phoen/grabana/decoder/heatmap.go index 0ac899d8..eaa83aa0 100644 --- a/vendor/github.com/K-Phoen/grabana/decoder/heatmap.go +++ b/vendor/github.com/K-Phoen/grabana/decoder/heatmap.go @@ -110,6 +110,9 @@ func (heatmapPanel DashboardHeatmap) target(t Target) (heatmap.Option, error) { if t.Prometheus != nil { return heatmap.WithPrometheusTarget(t.Prometheus.Query, t.Prometheus.toOptions()...), nil } + if t.Graphite != nil { + return heatmap.WithGraphiteTarget(t.Graphite.Query, t.Graphite.toOptions()...), nil + } if t.Stackdriver != nil { stackdriverTarget, err := t.Stackdriver.toTarget() if err != nil { diff --git a/vendor/github.com/K-Phoen/grabana/decoder/singlestat.go b/vendor/github.com/K-Phoen/grabana/decoder/singlestat.go index 03a01fb7..b632c5af 100644 --- a/vendor/github.com/K-Phoen/grabana/decoder/singlestat.go +++ b/vendor/github.com/K-Phoen/grabana/decoder/singlestat.go @@ -132,6 +132,9 @@ func (singleStatPanel DashboardSingleStat) target(t Target) (singlestat.Option, if t.Prometheus != nil { return singlestat.WithPrometheusTarget(t.Prometheus.Query, t.Prometheus.toOptions()...), nil } + if t.Graphite != nil { + return singlestat.WithGraphiteTarget(t.Graphite.Query, t.Graphite.toOptions()...), nil + } if t.Stackdriver != nil { stackdriverTarget, err := t.Stackdriver.toTarget() if err != nil { diff --git a/vendor/github.com/K-Phoen/grabana/decoder/table.go b/vendor/github.com/K-Phoen/grabana/decoder/table.go index 840b3a5d..53aa116c 100644 --- a/vendor/github.com/K-Phoen/grabana/decoder/table.go +++ b/vendor/github.com/K-Phoen/grabana/decoder/table.go @@ -60,6 +60,9 @@ func (tablePanel *DashboardTable) target(t Target) (table.Option, error) { if t.Prometheus != nil { return table.WithPrometheusTarget(t.Prometheus.Query, t.Prometheus.toOptions()...), nil } + if t.Graphite != nil { + return table.WithGraphiteTarget(t.Graphite.Query, t.Graphite.toOptions()...), nil + } return nil, ErrTargetNotConfigured } diff --git a/vendor/github.com/K-Phoen/grabana/decoder/target.go b/vendor/github.com/K-Phoen/grabana/decoder/target.go index 584f29bb..86258948 100644 --- a/vendor/github.com/K-Phoen/grabana/decoder/target.go +++ b/vendor/github.com/K-Phoen/grabana/decoder/target.go @@ -3,6 +3,7 @@ package decoder import ( "fmt" + "github.com/K-Phoen/grabana/target/graphite" "github.com/K-Phoen/grabana/target/prometheus" "github.com/K-Phoen/grabana/target/stackdriver" ) @@ -14,6 +15,7 @@ var ErrInvalidStackdriverAlignment = fmt.Errorf("invalid stackdriver alignment m type Target struct { Prometheus *PrometheusTarget `yaml:",omitempty"` + Graphite *GraphiteTarget `yaml:",omitempty"` Stackdriver *StackdriverTarget `yaml:",omitempty"` } @@ -56,6 +58,24 @@ func (t PrometheusTarget) toOptions() []prometheus.Option { return opts } +type GraphiteTarget struct { + Query string + Ref string `yaml:",omitempty"` + Hidden bool `yaml:",omitempty"` +} + +func (t GraphiteTarget) toOptions() []graphite.Option { + opts := []graphite.Option{ + graphite.Ref(t.Ref), + } + + if t.Hidden { + opts = append(opts, graphite.Hide()) + } + + return opts +} + type StackdriverTarget struct { Project string Type string diff --git a/vendor/github.com/K-Phoen/grabana/graph/graph.go b/vendor/github.com/K-Phoen/grabana/graph/graph.go index f19bca49..fbe07727 100644 --- a/vendor/github.com/K-Phoen/grabana/graph/graph.go +++ b/vendor/github.com/K-Phoen/grabana/graph/graph.go @@ -3,6 +3,7 @@ package graph import ( "github.com/K-Phoen/grabana/alert" "github.com/K-Phoen/grabana/axis" + "github.com/K-Phoen/grabana/target/graphite" "github.com/K-Phoen/grabana/target/prometheus" "github.com/K-Phoen/grabana/target/stackdriver" "github.com/grafana-tools/sdk" @@ -128,6 +129,15 @@ func WithPrometheusTarget(query string, options ...prometheus.Option) Option { } } +// WithGraphiteTarget adds a Graphite target to the table. +func WithGraphiteTarget(query string, options ...graphite.Option) Option { + target := graphite.New(query, options...) + + return func(graph *Graph) { + graph.Builder.AddTarget(target.Builder) + } +} + // WithStackdriverTarget adds a stackdriver query to the graph. func WithStackdriverTarget(target *stackdriver.Stackdriver) Option { return func(graph *Graph) { diff --git a/vendor/github.com/K-Phoen/grabana/heatmap/heatmap.go b/vendor/github.com/K-Phoen/grabana/heatmap/heatmap.go index 1333b2e2..9ba52dad 100644 --- a/vendor/github.com/K-Phoen/grabana/heatmap/heatmap.go +++ b/vendor/github.com/K-Phoen/grabana/heatmap/heatmap.go @@ -1,6 +1,7 @@ package heatmap import ( + "github.com/K-Phoen/grabana/target/graphite" "github.com/K-Phoen/grabana/target/prometheus" "github.com/K-Phoen/grabana/target/stackdriver" "github.com/grafana-tools/sdk" @@ -136,6 +137,15 @@ func WithPrometheusTarget(query string, options ...prometheus.Option) Option { } } +// WithGraphiteTarget adds a Graphite target to the table. +func WithGraphiteTarget(query string, options ...graphite.Option) Option { + target := graphite.New(query, options...) + + return func(heatmap *Heatmap) { + heatmap.Builder.AddTarget(target.Builder) + } +} + // WithStackdriverTarget adds a stackdriver query to the graph. func WithStackdriverTarget(target *stackdriver.Stackdriver) Option { return func(heatmap *Heatmap) { diff --git a/vendor/github.com/K-Phoen/grabana/singlestat/singlestat.go b/vendor/github.com/K-Phoen/grabana/singlestat/singlestat.go index 7eef6fa8..32972bee 100644 --- a/vendor/github.com/K-Phoen/grabana/singlestat/singlestat.go +++ b/vendor/github.com/K-Phoen/grabana/singlestat/singlestat.go @@ -3,6 +3,7 @@ package singlestat import ( "strings" + "github.com/K-Phoen/grabana/target/graphite" "github.com/K-Phoen/grabana/target/prometheus" "github.com/K-Phoen/grabana/target/stackdriver" "github.com/grafana-tools/sdk" @@ -147,6 +148,15 @@ func WithPrometheusTarget(query string, options ...prometheus.Option) Option { } } +// WithGraphiteTarget adds a Graphite target to the table. +func WithGraphiteTarget(query string, options ...graphite.Option) Option { + target := graphite.New(query, options...) + + return func(singleStat *SingleStat) { + singleStat.Builder.AddTarget(target.Builder) + } +} + // WithStackdriverTarget adds a stackdriver query to the graph. func WithStackdriverTarget(target *stackdriver.Stackdriver) Option { return func(singleStat *SingleStat) { diff --git a/vendor/github.com/K-Phoen/grabana/table/table.go b/vendor/github.com/K-Phoen/grabana/table/table.go index dff6f523..a3e3afdd 100644 --- a/vendor/github.com/K-Phoen/grabana/table/table.go +++ b/vendor/github.com/K-Phoen/grabana/table/table.go @@ -1,6 +1,7 @@ package table import ( + "github.com/K-Phoen/grabana/target/graphite" "github.com/K-Phoen/grabana/target/prometheus" "github.com/grafana-tools/sdk" ) @@ -85,6 +86,15 @@ func WithPrometheusTarget(query string, options ...prometheus.Option) Option { } } +// WithGraphiteTarget adds a Graphite target to the table. +func WithGraphiteTarget(query string, options ...graphite.Option) Option { + target := graphite.New(query, options...) + + return func(table *Table) { + table.Builder.AddTarget(target.Builder) + } +} + // HideColumn hides the column having a label matching the given pattern. func HideColumn(columnLabelPattern string) Option { return func(table *Table) { diff --git a/vendor/github.com/K-Phoen/grabana/target/graphite/graphite.go b/vendor/github.com/K-Phoen/grabana/target/graphite/graphite.go new file mode 100644 index 00000000..8b62127e --- /dev/null +++ b/vendor/github.com/K-Phoen/grabana/target/graphite/graphite.go @@ -0,0 +1,40 @@ +package graphite + +import "github.com/grafana-tools/sdk" + +// Option represents an option that can be used to configure a graphite query. +type Option func(target *Graphite) + +// Graphite represents a graphite query. +type Graphite struct { + Builder *sdk.Target +} + +func New(target string, options ...Option) *Graphite { + graphite := &Graphite{ + Builder: &sdk.Target{ + Target: target, + }, + } + + for _, opt := range options { + opt(graphite) + } + + return graphite +} + +// Ref sets the reference ID for this query. +func Ref(ref string) Option { + return func(graphite *Graphite) { + graphite.Builder.RefID = ref + } +} + +// Hide the query. Grafana does not send hidden queries to the data source, +// but they can still be referenced in alerts. +func Hide() Option { + return func(graphite *Graphite) { + graphite.Builder.Hide = true + } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 043f0f00..b68fc40b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,6 +1,6 @@ # cloud.google.com/go v0.46.3 cloud.google.com/go/compute/metadata -# github.com/K-Phoen/grabana v0.13.6 +# github.com/K-Phoen/grabana v0.14.0 github.com/K-Phoen/grabana github.com/K-Phoen/grabana/alert github.com/K-Phoen/grabana/axis @@ -11,6 +11,7 @@ github.com/K-Phoen/grabana/heatmap github.com/K-Phoen/grabana/row github.com/K-Phoen/grabana/singlestat github.com/K-Phoen/grabana/table +github.com/K-Phoen/grabana/target/graphite github.com/K-Phoen/grabana/target/prometheus github.com/K-Phoen/grabana/target/stackdriver github.com/K-Phoen/grabana/text From 9b7e2b00c1d356993bcdcadc69c894004ad5a92c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Sat, 27 Mar 2021 19:56:35 +0100 Subject: [PATCH 2/2] Support conversion of graphite targets --- internal/pkg/converter/json.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/pkg/converter/json.go b/internal/pkg/converter/json.go index f37e69d1..0a7a99de 100644 --- a/internal/pkg/converter/json.go +++ b/internal/pkg/converter/json.go @@ -654,6 +654,12 @@ func (converter *JSON) convertTarget(target sdk.Target) *grabana.Target { return converter.convertPrometheusTarget(target) } + // looks like graphite + if target.Target != "" { + return converter.convertGraphiteTarget(target) + } + + // looks like stackdriver if target.MetricType != "" { return converter.convertStackdriverTarget(target) } @@ -677,6 +683,16 @@ func (converter *JSON) convertPrometheusTarget(target sdk.Target) *grabana.Targe } } +func (converter *JSON) convertGraphiteTarget(target sdk.Target) *grabana.Target { + return &grabana.Target{ + Graphite: &grabana.GraphiteTarget{ + Query: target.Target, + Ref: target.RefID, + Hidden: target.Hide, + }, + } +} + func (converter *JSON) convertStackdriverTarget(target sdk.Target) *grabana.Target { switch strings.ToLower(target.MetricKind) { case "cumulative":