Skip to content

Merge some more PRs #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.5
1.12.6
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- "1.11.x"
- "1.12.x"
- tip

env:
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ require (
github.com/hashicorp/hil v0.0.0-20190212132231-97b3a9cdfa93 // indirect
github.com/hashicorp/terraform v0.12.3
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/newrelic/go-agent v2.5.0+incompatible
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/newrelic/go-agent v2.9.0+incompatible
github.com/paultyng/go-newrelic/v4 v4.4.0
github.com/pkg/errors v0.8.1 // indirect
github.com/ulikunitz/xz v0.5.6 // indirect
github.com/vmihailenco/msgpack v4.0.2+incompatible // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542 // indirect
google.golang.org/genproto v0.0.0-20190219182410-082222b4a5c5 // indirect
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20190204112747-618f46f3f0c8 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-shellwords v1.0.4 h1:xmZZyxuP+bYKAKkA9ABYXVNJ+G/Wf3R8d8vAP3LDJJk=
github.com/mattn/go-shellwords v1.0.4/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
Expand Down Expand Up @@ -294,8 +294,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
github.com/newrelic/go-agent v2.5.0+incompatible h1:umBF/DtNZEO1ASmD0C8jMaQKD20nZS6os0l/upoLLfo=
github.com/newrelic/go-agent v2.5.0+incompatible/go.mod h1:a8Fv1b/fYhFSReoTU6HDkTYIMZeSVNffmoS726Y0LzQ=
github.com/newrelic/go-agent v2.9.0+incompatible h1:f47VHKmZ/3KXzMSg77CGroizhcyP4JaE6zMYOeXxkDg=
github.com/newrelic/go-agent v2.9.0+incompatible/go.mod h1:a8Fv1b/fYhFSReoTU6HDkTYIMZeSVNffmoS726Y0LzQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
Expand Down Expand Up @@ -393,8 +393,8 @@ github.com/ulikunitz/xz v0.5.6 h1:jGHAfXawEGZQ3blwU5wnWKQJvAraT7Ftq9EXjnXYgt8=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.2+incompatible h1:6ujmmycMfB62Mwv2N4atpnf8CKLSzhgodqMenpELKIQ=
github.com/vmihailenco/msgpack v4.0.2+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
Expand Down Expand Up @@ -476,6 +476,8 @@ golang.org/x/sys v0.0.0-20190302045720-b6889370fb10/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 h1:vsphBvatvfbhlb4PO1BYSr9dzugGxJ/SQHoNufZJq1w=
golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542 h1:6ZQFf1D2YYDDI7eSwW8adlkkavTB9sw5I24FVtEvNUQ=
golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To=
Expand Down
32 changes: 30 additions & 2 deletions newrelic/resource_newrelic_nrql_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ func resourceNewRelicNrqlAlertCondition() *schema.Resource {
Optional: true,
Default: true,
},
"expected_groups": {
Type: schema.TypeInt,
Optional: true,
},
"ignore_overlap": {
Type: schema.TypeBool,
Optional: true,
},
"nrql": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -75,7 +83,7 @@ func resourceNewRelicNrqlAlertCondition() *schema.Resource {
"duration": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: intInSlice([]int{1, 2, 3, 4, 5, 10, 15, 30, 60, 120}),
ValidateFunc: validation.IntAtLeast(1),
},
"operator": {
Type: schema.TypeString,
Expand Down Expand Up @@ -104,6 +112,12 @@ func resourceNewRelicNrqlAlertCondition() *schema.Resource {
Required: true,
MinItems: 1,
},
"type": {
Type: schema.TypeString,
Optional: true,
Default: "static",
ValidateFunc: validation.StringInSlice([]string{"static", "outlier", "baseline"}, false),
},
"value_function": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -142,6 +156,7 @@ func buildNrqlAlertConditionStruct(d *schema.ResourceData) *newrelic.AlertNrqlCo

condition := newrelic.AlertNrqlCondition{
Name: d.Get("name").(string),
Type: d.Get("type").(string),
Enabled: d.Get("enabled").(bool),
Terms: terms,
PolicyID: d.Get("policy_id").(int),
Expand All @@ -153,6 +168,14 @@ func buildNrqlAlertConditionStruct(d *schema.ResourceData) *newrelic.AlertNrqlCo
condition.RunbookURL = attr.(string)
}

if attr, ok := d.GetOkExists("ignore_overlap"); ok {
condition.IgnoreOverlap = attr.(bool)
}

if attr, ok := d.GetOk("expected_groups"); ok {
condition.ExpectedGroups = attr.(int)
}

return &condition
}

Expand All @@ -168,10 +191,15 @@ func readNrqlAlertConditionStruct(condition *newrelic.AlertNrqlCondition, d *sch
d.Set("name", condition.Name)
d.Set("runbook_url", condition.RunbookURL)
d.Set("enabled", condition.Enabled)
d.Set("value_function", condition.ValueFunction)
d.Set("nrql.0.Query", condition.Nrql.Query)
d.Set("nrql.0.SinceValue", condition.Nrql.SinceValue)

if condition.ValueFunction == "" {
d.Set("value_function", "single_value")
} else {
d.Set("value_function", condition.ValueFunction)
}

var terms []map[string]interface{}

for _, src := range condition.Terms {
Expand Down
146 changes: 143 additions & 3 deletions newrelic/resource_newrelic_nrql_alert_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestAccNewRelicNrqlAlertCondition_Basic(t *testing.T) {
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.#", "1"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.duration", "5"),
"newrelic_nrql_alert_condition.foo", "term.0.duration", "55"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.operator", "below"),
resource.TestCheckResourceAttr(
Expand All @@ -48,6 +48,36 @@ func TestAccNewRelicNrqlAlertCondition_Basic(t *testing.T) {
},
{
Config: testAccCheckNewRelicNrqlAlertConditionConfigUpdated(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicNrqlAlertConditionExists("newrelic_nrql_alert_condition.foo"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "name", fmt.Sprintf("tf-test-updated-%s", rName)),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "runbook_url", "https://bar.example.com"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "enabled", "false"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.#", "1"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.duration", "100"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.operator", "below"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.priority", "critical"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.threshold", "0.65"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.time_function", "all"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "nrql.#", "1"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "nrql.0.query", "SELECT uniqueCount(hostname) as Hosts FROM ComputeSample"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "nrql.0.since_value", "3"),
),
},
{
Config: testAccCheckNewRelicNrqlAlertConditionConfigUpdatedWithStatic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicNrqlAlertConditionExists("newrelic_nrql_alert_condition.foo"),
resource.TestCheckResourceAttr(
Expand All @@ -74,6 +104,55 @@ func TestAccNewRelicNrqlAlertCondition_Basic(t *testing.T) {
"newrelic_nrql_alert_condition.foo", "nrql.0.query", "SELECT uniqueCount(hostname) as Hosts FROM ComputeSample"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "nrql.0.since_value", "3"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "type", "static"),
),
},
},
})
}

func TestAccNewRelicNrqlAlertCondition_Outlier(t *testing.T) {
rName := acctest.RandString(5)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNewRelicNrqlAlertConditionDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckNewRelicNrqlAlertConditionConfigWithOutlier(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicNrqlAlertConditionExists("newrelic_nrql_alert_condition.foo"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "name", fmt.Sprintf("tf-test-updated-%s", rName)),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "runbook_url", "https://bar.example.com"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "enabled", "false"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.#", "1"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.duration", "10"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.operator", "above"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.priority", "critical"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.threshold", "0.65"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "term.0.time_function", "all"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "nrql.#", "1"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "nrql.0.query", "SELECT percentile(duration, 99) FROM Transaction FACET remote_ip"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "nrql.0.since_value", "3"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "type", "outlier"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "expected_groups", "2"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "ignore_overlap", "true"),
),
},
},
Expand Down Expand Up @@ -154,7 +233,7 @@ resource "newrelic_nrql_alert_condition" "foo" {
enabled = false

term {
duration = 5
duration = 55
operator = "below"
priority = "critical"
threshold = "0.75"
Expand All @@ -176,6 +255,35 @@ resource "newrelic_alert_policy" "foo" {
name = "tf-test-%[1]s"
}

resource "newrelic_nrql_alert_condition" "foo" {
policy_id = "${newrelic_alert_policy.foo.id}"

name = "tf-test-updated-%[1]s"
runbook_url = "https://bar.example.com"
enabled = false

term {
duration = 100
operator = "below"
priority = "critical"
threshold = "0.65"
time_function = "all"
}
nrql {
query = "SELECT uniqueCount(hostname) as Hosts FROM ComputeSample"
since_value = "3"
}
}
`, rName)
}

func testAccCheckNewRelicNrqlAlertConditionConfigUpdatedWithStatic(rName string) string {
return fmt.Sprintf(`

resource "newrelic_alert_policy" "foo" {
name = "tf-test-%[1]s"
}

resource "newrelic_nrql_alert_condition" "foo" {
policy_id = "${newrelic_alert_policy.foo.id}"

Expand All @@ -194,7 +302,39 @@ resource "newrelic_nrql_alert_condition" "foo" {
query = "SELECT uniqueCount(hostname) as Hosts FROM ComputeSample"
since_value = "3"
}
value_function = "single_value"
type = "static"
}
`, rName)
}

func testAccCheckNewRelicNrqlAlertConditionConfigWithOutlier(rName string) string {
return fmt.Sprintf(`

resource "newrelic_alert_policy" "foo" {
name = "tf-test-%[1]s"
}

resource "newrelic_nrql_alert_condition" "foo" {
policy_id = "${newrelic_alert_policy.foo.id}"

name = "tf-test-updated-%[1]s"
runbook_url = "https://bar.example.com"
enabled = false

term {
duration = 10
operator = "above"
priority = "critical"
threshold = "0.65"
time_function = "all"
}
nrql {
query = "SELECT percentile(duration, 99) FROM Transaction FACET remote_ip"
since_value = "3"
}
type = "outlier"
expected_groups = 2
ignore_overlap = true
}
`, rName)
}
Expand Down
2 changes: 1 addition & 1 deletion newrelic/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func runTestCases(t *testing.T, cases []testCase) {
}

if !matchErr(errs, tc.expectedErr) {
t.Fatalf("expected test case %d to produce error matching \"%s\", got %v", i, tc.expectedErr, errs)
t.Fatalf("expected test case %d to produce error matching \"%s\", got '%v'", i, tc.expectedErr, errs[0])
}
}
}

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

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

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

Loading