Skip to content

Commit

Permalink
Add recurrence to muting rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tdudzik-splunk committed May 27, 2024
1 parent f3bf0d7 commit eb22818
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 35 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
github.com/mitchellh/go-homedir v1.1.0
github.com/signalfx/signalfx-go v1.35.0
github.com/signalfx/signalfx-go v1.36.0
github.com/stretchr/testify v1.8.2
)

Expand Down Expand Up @@ -63,7 +63,7 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ github.com/signalfx/signalfx-go v1.34.0 h1:OQ6tyMY4efWB57EPIQqrpWrAfcSdyfa+bLtmA
github.com/signalfx/signalfx-go v1.34.0/go.mod h1:IpGZLPvCKNFyspAXoS480jB02mocTpo0KYd8jbl6/T8=
github.com/signalfx/signalfx-go v1.35.0 h1:/IA4XuvxUOulipT71oawyRInk08JTdHPlA4ETZ20Ae4=
github.com/signalfx/signalfx-go v1.35.0/go.mod h1:IpGZLPvCKNFyspAXoS480jB02mocTpo0KYd8jbl6/T8=
github.com/signalfx/signalfx-go v1.36.0 h1:btfNrjb/MWAku7Ibj5BUamArVkyV9XI/fYqA0ytLdEo=
github.com/signalfx/signalfx-go v1.36.0/go.mod h1:aVrA69k02raBhDtIL1l+KBu+H5eEmS5b0IFbqgKh7eg=
github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down Expand Up @@ -224,8 +226,8 @@ google.golang.org/grpc v1.57.1 h1:upNTNqv0ES+2ZOOqACwVtS3Il8M12/+Hz41RCPzAjQg=
google.golang.org/grpc v1.57.1/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
43 changes: 43 additions & 0 deletions signalfx/resource_signalfx_alert_muting_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ func alertMutingRuleResource() *schema.Resource {
},
},
},
"recurrence": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"unit": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"d", "w"}, false),
Description: "unit of the period. Can be days (d) or weeks (w)",
},
"value": {
Type: schema.TypeInt,
Required: true,
Description: "amount of time, expressed as an integer applicable to the unit",
ValidateFunc: validation.IntAtLeast(1),
},
},
},
},
"start_time": {
Type: schema.TypeInt,
Required: true,
Expand Down Expand Up @@ -126,6 +147,17 @@ func getPayloadAlertMutingRule(d *schema.ResourceData) (*alertmuting.CreateUpdat
StopTime: int64(d.Get("stop_time").(int) * 1000),
}

if recurrence, ok := d.GetOk("recurrence"); ok {
tfRecurrences := recurrence.(*schema.Set).List()
if len(tfRecurrences) > 0 {
recurrence := tfRecurrences[0].(map[string]interface{})
cuamrr.Recurrence = &alertmuting.AlertMutingRuleRecurrence{
Unit: recurrence["unit"].(string),
Value: int32(recurrence["value"].(int)),
}
}
}

return cuamrr, nil
}

Expand Down Expand Up @@ -232,6 +264,17 @@ func alertMutingRuleAPIToTF(d *schema.ResourceData, amr *alertmuting.AlertMuting
}
}

if amr.Recurrence != nil {
d.Set("recurrence", []interface{}{
map[string]interface{}{
"unit": amr.Recurrence.Unit,
"value": amr.Recurrence.Value,
},
})
} else {
d.Set("recurrence", nil)
}

return nil
}

Expand Down
45 changes: 14 additions & 31 deletions signalfx/resource_signalfx_alert_muting_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

const newAlertMutingRuleConfig = `
resource "signalfx_alert_muting_rule" "rool_mooter_one" {
description = "mooted it"
start_time = 1573063243
filter {
property = "foo"
property_value = "bar"
}
}
`

const updatedAlertMutingRuleConfig = `
resource "signalfx_alert_muting_rule" "rool_mooter_one" {
description = "mooted it NEW"
start_time = 1573063243
filter {
property = "foo"
property_value = "bar"
}
}
`

func TestAccCreateUpdateFutureAlertMutingRule(t *testing.T) {

firstTime := time.Now().Unix() + 86400
secondTime := time.Now().Unix() + (86400 * 2)

Expand All @@ -52,6 +25,11 @@ func TestAccCreateUpdateFutureAlertMutingRule(t *testing.T) {
property = "foo"
property_value = "bar"
}
recurrence {
unit = "d"
value = 2
}
}
`, firstTime)

Expand All @@ -65,6 +43,11 @@ func TestAccCreateUpdateFutureAlertMutingRule(t *testing.T) {
property = "foo"
property_value = "bar"
}
recurrence {
unit = "d"
value = 4
}
}
`, secondTime)

Expand All @@ -80,6 +63,8 @@ func TestAccCreateUpdateFutureAlertMutingRule(t *testing.T) {
testAccCreateUpdateAlertMutingRuleResourceExists,
resource.TestCheckResourceAttr("signalfx_alert_muting_rule.rool_mooter_two", "description", "mooted it FUTURE"),
resource.TestCheckResourceAttr("signalfx_alert_muting_rule.rool_mooter_two", "start_time", strconv.Itoa(int(firstTime))),
resource.TestCheckResourceAttr("signalfx_alert_muting_rule.rool_mooter_two", "recurrence.0.unit", "d"),
resource.TestCheckResourceAttr("signalfx_alert_muting_rule.rool_mooter_two", "recurrence.0.value", "2"),
),
},
{
Expand All @@ -97,16 +82,14 @@ func TestAccCreateUpdateFutureAlertMutingRule(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCreateUpdateAlertMutingRuleResourceExists,
resource.TestCheckResourceAttr("signalfx_alert_muting_rule.rool_mooter_two", "start_time", strconv.Itoa(int(secondTime))),
resource.TestCheckResourceAttr("signalfx_alert_muting_rule.rool_mooter_two", "recurrence.0.unit", "d"),
resource.TestCheckResourceAttr("signalfx_alert_muting_rule.rool_mooter_two", "recurrence.0.value", "4"),
),
},
},
})
}

func TestAccCreateUpdateAlertMutingRule(t *testing.T) {

}

func testAccCreateUpdateAlertMutingRuleResourceExists(s *terraform.State) error {
client := newTestClient()
for _, rs := range s.RootModule().Resources {
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/alert_muting_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ resource "signalfx_alert_muting_rule" "rool_mooter_one" {
property = "foo"
property_value = "bar"
}
recurrence {
unit = "d"
value = 2
}
}
```

Expand All @@ -42,6 +47,9 @@ resource "signalfx_alert_muting_rule" "rool_mooter_one" {
* `property` - (Required) The property to filter.
* `property_value` - (Required) The property value to filter.
* `negated` - (Optional) Determines if this is a "not" filter. Defaults to `false`.
* `recurrence` - (Optional) Defines the recurrence of the muting rule. Allows setting a recurring muting rule based on specified days or weeks.
* `unit` - (Required) The unit of the period. Can be days (d) or weeks (w).
* `value` - (Required) The amount of time, expressed as an integer, applicable to the unit specified.

## Attributes

Expand Down

0 comments on commit eb22818

Please sign in to comment.