Skip to content

Commit

Permalink
Decode project name from yaml-defined stackdriver alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Aug 14, 2023
1 parent 7a63451 commit d07fe1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions decoder/alert_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions decoder/alert_targets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d07fe1f

Please sign in to comment.