Skip to content

Commit

Permalink
Merge pull request #1 from breeze7086/support-cloudwatch-target
Browse files Browse the repository at this point in the history
Private fork and add support of Cloudwatch target
  • Loading branch information
breeze7086 authored Jun 18, 2020
2 parents a7962c0 + f71cdc6 commit 29df16c
Show file tree
Hide file tree
Showing 27 changed files with 172 additions and 64 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"net/http"
"strings"

"github.com/K-Phoen/grabana/alert"
"github.com/K-Phoen/grabana/dashboard"
"github.com/breeze7086/grabana/alert"
"github.com/breeze7086/grabana/dashboard"
"github.com/grafana-tools/sdk"
)

Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

builder "github.com/K-Phoen/grabana/dashboard"
builder "github.com/breeze7086/grabana/dashboard"
"github.com/stretchr/testify/require"
)

Expand Down
28 changes: 14 additions & 14 deletions cmd/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"net/http"
"os"

"github.com/K-Phoen/grabana"
"github.com/K-Phoen/grabana/alert"
"github.com/K-Phoen/grabana/axis"
"github.com/K-Phoen/grabana/dashboard"
"github.com/K-Phoen/grabana/graph"
"github.com/K-Phoen/grabana/row"
"github.com/K-Phoen/grabana/singlestat"
"github.com/K-Phoen/grabana/table"
"github.com/K-Phoen/grabana/target/prometheus"
"github.com/K-Phoen/grabana/text"
"github.com/K-Phoen/grabana/variable/constant"
"github.com/K-Phoen/grabana/variable/custom"
"github.com/K-Phoen/grabana/variable/interval"
"github.com/K-Phoen/grabana/variable/query"
"github.com/breeze7086/grabana"
"github.com/breeze7086/grabana/alert"
"github.com/breeze7086/grabana/axis"
"github.com/breeze7086/grabana/dashboard"
"github.com/breeze7086/grabana/graph"
"github.com/breeze7086/grabana/row"
"github.com/breeze7086/grabana/singlestat"
"github.com/breeze7086/grabana/table"
"github.com/breeze7086/grabana/target/prometheus"
"github.com/breeze7086/grabana/text"
"github.com/breeze7086/grabana/variable/constant"
"github.com/breeze7086/grabana/variable/custom"
"github.com/breeze7086/grabana/variable/interval"
"github.com/breeze7086/grabana/variable/query"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/yaml/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"net/http"
"os"

"github.com/K-Phoen/grabana"
"github.com/K-Phoen/grabana/decoder"
"github.com/breeze7086/grabana"
"github.com/breeze7086/grabana/decoder"
)

func main() {
Expand Down
10 changes: 5 additions & 5 deletions dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package dashboard
import (
"encoding/json"

"github.com/K-Phoen/grabana/row"
"github.com/K-Phoen/grabana/variable/constant"
"github.com/K-Phoen/grabana/variable/custom"
"github.com/K-Phoen/grabana/variable/interval"
"github.com/K-Phoen/grabana/variable/query"
"github.com/breeze7086/grabana/row"
"github.com/breeze7086/grabana/variable/constant"
"github.com/breeze7086/grabana/variable/custom"
"github.com/breeze7086/grabana/variable/interval"
"github.com/breeze7086/grabana/variable/query"
"github.com/grafana-tools/sdk"
)

Expand Down
4 changes: 2 additions & 2 deletions decoder/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package decoder
import (
"fmt"

"github.com/K-Phoen/grabana/dashboard"
"github.com/K-Phoen/grabana/row"
"github.com/breeze7086/grabana/dashboard"
"github.com/breeze7086/grabana/row"
)

var ErrPanelNotConfigured = fmt.Errorf("panel not configured")
Expand Down
8 changes: 4 additions & 4 deletions decoder/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package decoder
import (
"fmt"

"github.com/K-Phoen/grabana/alert"
"github.com/K-Phoen/grabana/axis"
"github.com/K-Phoen/grabana/graph"
"github.com/K-Phoen/grabana/row"
"github.com/breeze7086/grabana/alert"
"github.com/breeze7086/grabana/axis"
"github.com/breeze7086/grabana/graph"
"github.com/breeze7086/grabana/row"
)

var ErrNoAlertThresholdDefined = fmt.Errorf("no threshold defined")
Expand Down
4 changes: 2 additions & 2 deletions decoder/row.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package decoder

import (
"github.com/K-Phoen/grabana/dashboard"
"github.com/K-Phoen/grabana/row"
"github.com/breeze7086/grabana/dashboard"
"github.com/breeze7086/grabana/row"
)

type DashboardRow struct {
Expand Down
4 changes: 2 additions & 2 deletions decoder/singlestat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package decoder
import (
"fmt"

"github.com/K-Phoen/grabana/row"
"github.com/K-Phoen/grabana/singlestat"
"github.com/breeze7086/grabana/row"
"github.com/breeze7086/grabana/singlestat"
)

var ErrInvalidColoringTarget = fmt.Errorf("invalid coloring target")
Expand Down
2 changes: 1 addition & 1 deletion decoder/singlestat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package decoder
import (
"testing"

"github.com/K-Phoen/grabana/singlestat"
"github.com/breeze7086/grabana/singlestat"

"github.com/stretchr/testify/require"
)
Expand Down
4 changes: 2 additions & 2 deletions decoder/table.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package decoder

import (
"github.com/K-Phoen/grabana/row"
"github.com/K-Phoen/grabana/table"
"github.com/breeze7086/grabana/row"
"github.com/breeze7086/grabana/table"
)

type DashboardTable struct {
Expand Down
4 changes: 2 additions & 2 deletions decoder/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package decoder
import (
"fmt"

"github.com/K-Phoen/grabana/target/prometheus"
"github.com/K-Phoen/grabana/target/stackdriver"
"github.com/breeze7086/grabana/target/prometheus"
"github.com/breeze7086/grabana/target/stackdriver"
)

var ErrTargetNotConfigured = fmt.Errorf("target not configured")
Expand Down
2 changes: 1 addition & 1 deletion decoder/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package decoder
import (
"testing"

"github.com/K-Phoen/grabana/target/stackdriver"
"github.com/breeze7086/grabana/target/stackdriver"

"github.com/stretchr/testify/require"
)
Expand Down
4 changes: 2 additions & 2 deletions decoder/text.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package decoder

import (
"github.com/K-Phoen/grabana/row"
"github.com/K-Phoen/grabana/text"
"github.com/breeze7086/grabana/row"
"github.com/breeze7086/grabana/text"
)

type DashboardText struct {
Expand Down
10 changes: 5 additions & 5 deletions decoder/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package decoder
import (
"fmt"

"github.com/K-Phoen/grabana/variable/interval"
"github.com/breeze7086/grabana/variable/interval"

"github.com/K-Phoen/grabana/dashboard"
"github.com/K-Phoen/grabana/variable/constant"
"github.com/K-Phoen/grabana/variable/custom"
"github.com/K-Phoen/grabana/variable/query"
"github.com/breeze7086/grabana/dashboard"
"github.com/breeze7086/grabana/variable/constant"
"github.com/breeze7086/grabana/variable/custom"
"github.com/breeze7086/grabana/variable/query"
)

var ErrVariableNotConfigured = fmt.Errorf("variable not configured")
Expand Down
2 changes: 1 addition & 1 deletion decoder/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package decoder
import (
"io"

builder "github.com/K-Phoen/grabana/dashboard"
builder "github.com/breeze7086/grabana/dashboard"
"gopkg.in/yaml.v2"
)

Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ creation of dashboards, this library is meant for you.
),
)
For a more information visit https://github.com/K-Phoen/grabana
For a more information visit https://github.com/breeze7086/grabana
*/
package grabana
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/K-Phoen/grabana
module github.com/breeze7086/grabana

go 1.13

Expand Down
29 changes: 25 additions & 4 deletions graph/graph.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package graph

import (
"github.com/K-Phoen/grabana/alert"
"github.com/K-Phoen/grabana/axis"
"github.com/K-Phoen/grabana/target/prometheus"
"github.com/K-Phoen/grabana/target/stackdriver"
"github.com/breeze7086/grabana/alert"
"github.com/breeze7086/grabana/axis"
"github.com/breeze7086/grabana/target/cloudwatch"
"github.com/breeze7086/grabana/target/prometheus"
"github.com/breeze7086/grabana/target/stackdriver"
"github.com/grafana-tools/sdk"
)

Expand Down Expand Up @@ -129,6 +130,26 @@ func WithPrometheusTarget(query string, options ...prometheus.Option) Option {
}
}

// WithCloudwatchTarget adds a cloudwatch query to the graph.
func WithCloudwatchTarget(namespace string, metricName string, statistics []string, dimensions map[string]string, region string, period string, options ...cloudwatch.Option) Option {
target := cloudwatch.New(namespace, metricName, statistics, dimensions, region, period, options...)

return func(graph *Graph) {
graph.Builder.AddTarget(&sdk.Target{
RefID: target.Ref,
Hide: target.Hidden,
Expr: target.Expression,
Alias: target.Alias,
Namespace: target.Namespace,
MetricName: target.MetricName,
Statistics: target.Statistics,
Dimensions: target.Dimensions,
Period: target.Period,
Region: target.Region,
})
}
}

// WithStackdriverTarget adds a stackdriver query to the graph.
func WithStackdriverTarget(target *stackdriver.Stackdriver) Option {
return func(graph *Graph) {
Expand Down
4 changes: 2 additions & 2 deletions graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package graph
import (
"testing"

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

Expand Down
8 changes: 4 additions & 4 deletions row/row.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package row

import (
"github.com/K-Phoen/grabana/graph"
"github.com/K-Phoen/grabana/singlestat"
"github.com/K-Phoen/grabana/table"
"github.com/K-Phoen/grabana/text"
"github.com/breeze7086/grabana/graph"
"github.com/breeze7086/grabana/singlestat"
"github.com/breeze7086/grabana/table"
"github.com/breeze7086/grabana/text"
"github.com/grafana-tools/sdk"
)

Expand Down
2 changes: 1 addition & 1 deletion singlestat/singlestat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package singlestat
import (
"strings"

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

Expand Down
2 changes: 1 addition & 1 deletion table/table.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package table

import (
"github.com/K-Phoen/grabana/target/prometheus"
"github.com/breeze7086/grabana/target/prometheus"
"github.com/grafana-tools/sdk"
)

Expand Down
58 changes: 58 additions & 0 deletions target/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cloudwatch

type Option func(target *Cloudwatch)

type Cloudwatch struct {
Namespace string
MetricName string
Statistics []string
Dimensions map[string]string
Region string
Period string

Ref string
Hidden bool
Alias string
Expression string
}

func New(namespace string, metricName string, statistics []string, dimensions map[string]string, region string, period string, options ...Option) *Cloudwatch {
cloudwatch := &Cloudwatch{
Namespace: namespace,
MetricName: metricName,
Statistics: statistics,
Dimensions: dimensions,
Region: region,
Period: period,
}

for _, opt := range options {
opt(cloudwatch)
}

return cloudwatch
}

func Ref(ref string) Option {
return func(cloudwatch *Cloudwatch) {
cloudwatch.Ref = ref
}
}

func Hide() Option {
return func(cloudwatch *Cloudwatch) {
cloudwatch.Hidden = true
}
}

func Alias(alias string) Option {
return func(cloudwatch *Cloudwatch) {
cloudwatch.Alias = alias
}
}

func Expression(expr string) Option {
return func(cloudwatch *Cloudwatch) {
cloudwatch.Expression = expr
}
}
29 changes: 29 additions & 0 deletions target/cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cloudwatch_test

import (
"github.com/breeze7086/grabana/target/cloudwatch"
"github.com/stretchr/testify/require"
"testing"
)

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

namespace := "LBProvisionedLCU"
metricName := "ProvisionedLCU"
statistics := []string{"Average"}
dimensions := map[string]string{
"Loadbalancer Name": "9f2e1c28-default-prometheu-0928",
}
region := "us-east-1"
period := ""

target := cloudwatch.New(namespace, metricName, statistics, dimensions, region, period)

req.Equal(namespace, target.Namespace)
req.Equal(metricName, target.MetricName)
req.Equal(statistics, target.Statistics)
req.Equal(dimensions, target.Dimensions)
req.Equal(region, target.Region)
req.Equal(period, target.Period)
}
Loading

0 comments on commit 29df16c

Please sign in to comment.