Skip to content

Commit

Permalink
allow ProjectName to be configurable on Stackdriver alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan Barrett committed Aug 11, 2023
1 parent e25e564 commit 4daa12d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions alert/queries/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ func Legend(legend string) Option {
}
}

// Project defines the GCP project to use for this target.
func Project(project string) Option {
return func(stackdriver *Stackdriver) {
stackdriver.Builder.Model.MetricQuery.ProjectName = project
}
}

// Aggregation defines how the time series will be aggregated.
func Aggregation(reducer Reducer) Option {
return func(stackdriver *Stackdriver) {
Expand Down
12 changes: 12 additions & 0 deletions alert/queries/stackdriver/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import (
"github.com/stretchr/testify/require"
)

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

project := "some-gcp-project-id"

query := Delta("A", "some metric", Project(project))

builder := query.Builder

req.Equal(project, builder.Model.MetricQuery.ProjectName)
}

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

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/K-Phoen/grabana
go 1.19

require (
github.com/K-Phoen/sdk v0.12.2
github.com/K-Phoen/sdk v0.12.3-0.20230811095259-e77b6356006c
github.com/blang/semver v3.5.1+incompatible
github.com/prometheus/common v0.39.0
github.com/rhysd/go-github-selfupdate v1.2.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/K-Phoen/sdk v0.12.2 h1:0QofDlKE+lloyBOzhjEEMW21061zts/WIpfpQ5NLLAs=
github.com/K-Phoen/sdk v0.12.2/go.mod h1:qmM0wO23CtoDux528MXPpYvS4XkRWkWX6rvX9Za8EVU=
github.com/K-Phoen/sdk v0.12.3-0.20230811095259-e77b6356006c h1:HhFwUniM6YC8r3jOZBOZkCNrmNTcGGP/1+lCFNigmbw=
github.com/K-Phoen/sdk v0.12.3-0.20230811095259-e77b6356006c/go.mod h1:qmM0wO23CtoDux528MXPpYvS4XkRWkWX6rvX9Za8EVU=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/K-Phoen/sdk/alert.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/K-Phoen/sdk v0.12.2
# github.com/K-Phoen/sdk v0.12.3-0.20230811095259-e77b6356006c
## explicit; go 1.19
github.com/K-Phoen/sdk
# github.com/blang/semver v3.5.1+incompatible
Expand Down

0 comments on commit 4daa12d

Please sign in to comment.