diff --git a/alert/queries/stackdriver/stackdriver.go b/alert/queries/stackdriver/stackdriver.go index 06cbc56a..79ac0567 100644 --- a/alert/queries/stackdriver/stackdriver.go +++ b/alert/queries/stackdriver/stackdriver.go @@ -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) { diff --git a/alert/queries/stackdriver/stackdriver_test.go b/alert/queries/stackdriver/stackdriver_test.go index 96774340..6e055ef0 100644 --- a/alert/queries/stackdriver/stackdriver_test.go +++ b/alert/queries/stackdriver/stackdriver_test.go @@ -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) diff --git a/go.mod b/go.mod index 5aa25a1b..cad9aa4b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 15285953..688eaa51 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/vendor/github.com/K-Phoen/sdk/alert.go b/vendor/github.com/K-Phoen/sdk/alert.go index 08002adb..f8996580 100644 --- a/vendor/github.com/K-Phoen/sdk/alert.go +++ b/vendor/github.com/K-Phoen/sdk/alert.go @@ -74,6 +74,7 @@ type AlertModel struct { } type StackdriverAlertQuery struct { + ProjectName string `json:"projectName,omitempty"` AlignOptions []StackdriverAlignOptions `json:"alignOptions,omitempty"` AliasBy string `json:"aliasBy,omitempty"` MetricType string `json:"metricType,omitempty"` diff --git a/vendor/modules.txt b/vendor/modules.txt index e297abf0..a9b8bef1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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