From d07fe1f9ffcbe45e88e8e67f7b8ef3278fefa8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Mon, 14 Aug 2023 12:03:26 +0200 Subject: [PATCH] Decode project name from yaml-defined stackdriver alerts --- decoder/alert_targets.go | 5 +++++ decoder/alert_targets_test.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/decoder/alert_targets.go b/decoder/alert_targets.go index 37ad3f7b..3dd0cf48 100644 --- a/decoder/alert_targets.go +++ b/decoder/alert_targets.go @@ -123,6 +123,7 @@ type AlertStackdriver struct { Ref string `yaml:",omitempty"` Lookback string `yaml:",omitempty"` + Project string `yaml:",omitempty"` Type string Metric string Filters StackdriverAlertFilters `yaml:",omitempty"` @@ -195,6 +196,10 @@ func (t AlertStackdriver) targetOptions() ([]stackdriver.Option, error) { opts = append(opts, stackdriver.GroupBys(t.GroupBy...)) } + if t.Project != "" { + opts = append(opts, stackdriver.Project(t.Project)) + } + if t.Aggregation != "" { opt, err := t.aggregation() if err != nil { diff --git a/decoder/alert_targets_test.go b/decoder/alert_targets_test.go index 72e778d8..0cb86f6b 100644 --- a/decoder/alert_targets_test.go +++ b/decoder/alert_targets_test.go @@ -252,6 +252,7 @@ func TestDecodingStackdriverTarget(t *testing.T) { target := AlertTarget{ Stackdriver: &AlertStackdriver{ Ref: "A", + Project: "some-project", Lookback: "15m", Type: "gauge", Metric: "cloudsql.googleapis.com/database/cpu/utilization", @@ -279,6 +280,7 @@ func TestDecodingStackdriverTarget(t *testing.T) { req.Equal("A", query.RefID) req.Equal("A", query.Model.RefID) req.Equal("GAUGE", stackdriverData.MetricKind) + req.Equal("some-project", stackdriverData.ProjectName) req.Equal("cloudsql.googleapis.com/database/cpu/utilization", stackdriverData.MetricType) req.ElementsMatch([]string{"resource.label.database_id"}, stackdriverData.GroupBys) req.Equal("REDUCE_MEAN", stackdriverData.CrossSeriesReducer)