Skip to content

Commit

Permalink
Merge pull request #71 from K-Phoen/singlestat-stackdriver
Browse files Browse the repository at this point in the history
Support stackdriver targets in singlestat panels
  • Loading branch information
K-Phoen authored Jun 17, 2020
2 parents 0721929 + 2670e1e commit 345af32
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions decoder/singlestat.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ func (singleStatPanel DashboardSingleStat) target(t Target) (singlestat.Option,
if t.Prometheus != nil {
return singlestat.WithPrometheusTarget(t.Prometheus.Query, t.Prometheus.toOptions()...), nil
}
if t.Stackdriver != nil {
stackdriverTarget, err := t.Stackdriver.toTarget()
if err != nil {
return nil, err
}

return singlestat.WithStackdriverTarget(stackdriverTarget), nil
}

return nil, ErrTargetNotConfigured
}
8 changes: 8 additions & 0 deletions singlestat/singlestat.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/K-Phoen/grabana/target/prometheus"
"github.com/K-Phoen/grabana/target/stackdriver"
"github.com/grafana-tools/sdk"
)

Expand Down Expand Up @@ -165,6 +166,13 @@ func WithPrometheusTarget(query string, options ...prometheus.Option) Option {
}
}

// WithStackdriverTarget adds a stackdriver query to the graph.
func WithStackdriverTarget(target *stackdriver.Stackdriver) Option {
return func(singleStat *SingleStat) {
singleStat.Builder.AddTarget(target.Builder)
}
}

// Span sets the width of the panel, in grid units. Should be a positive
// number between 1 and 12. Example: 6.
func Span(span float32) Option {
Expand Down
9 changes: 9 additions & 0 deletions singlestat/singlestat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package singlestat
import (
"testing"

"github.com/K-Phoen/grabana/target/stackdriver"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -42,6 +43,14 @@ func TestSingleStatPanelCanHavePrometheusTargets(t *testing.T) {
req.Len(panel.Builder.SinglestatPanel.Targets, 1)
}

func TestSingleStatPanelCanHaveStackdriverTargets(t *testing.T) {
req := require.New(t)

panel := New("", WithStackdriverTarget(stackdriver.Gauge("pubsub.googleapis.com/subscription/ack_message_count")))

req.Len(panel.Builder.SinglestatPanel.Targets, 1)
}

func TestSingleStatPanelWidthCanBeConfigured(t *testing.T) {
req := require.New(t)

Expand Down

0 comments on commit 345af32

Please sign in to comment.