-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: alert rule and tests association (#168)
* fix: alert rule and tests association * fix: update go sdk version * fix: add missing readme generation * fix: fix typo Co-authored-by: Jack Browne <[email protected]> * fix: improve ac tests --------- Co-authored-by: Jack Browne <[email protected]>
- Loading branch information
1 parent
d74147c
commit 2beea37
Showing
8 changed files
with
183 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
thousandeyes/acceptance_resources/alert_rule/create_test_with_alert_rule.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
data "thousandeyes_agent" "amsterdam" { | ||
agent_name = "Amsterdam, Netherlands" | ||
} | ||
|
||
resource "thousandeyes_alert_rule" "test" { | ||
severity = "MAJOR" | ||
rule_name = "Agent To Server Alert Rule Test" | ||
alert_type = "End-to-End (Server)" | ||
expression = "((loss >= 50%) || (probDetail != \"\") || (avgLatency >= 200 ms))" | ||
minimum_sources = 2 | ||
rounds_violating_required = 3 | ||
rounds_violating_out_of = 4 | ||
} | ||
|
||
resource "thousandeyes_agent_to_server" "agent_to_server_test" { | ||
test_name = "Agent To Server Test" | ||
interval = 300 | ||
alerts_enabled = true | ||
server = "api.stg.thousandeyes.com" | ||
protocol = "TCP" | ||
port = 443 | ||
enabled = true | ||
bgp_measurements = true | ||
use_public_bgp = true | ||
mtu_measurements = true | ||
|
||
agents { | ||
agent_id = data.thousandeyes_agent.amsterdam.agent_id | ||
} | ||
|
||
alert_rules { | ||
rule_id = thousandeyes_alert_rule.test.id | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
thousandeyes/acceptance_resources/alert_rule/update_alert_rule.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
data "thousandeyes_agent" "amsterdam" { | ||
agent_name = "Amsterdam, Netherlands" | ||
} | ||
|
||
resource "thousandeyes_alert_rule" "test" { | ||
severity = "MAJOR" | ||
rule_name = "Agent To Server Alert Rule Test" | ||
alert_type = "End-to-End (Server)" | ||
expression = "((loss >= 50%) || (probDetail != \"\") || (avgLatency >= 200 ms))" | ||
minimum_sources = 2 | ||
rounds_violating_required = 4 | ||
rounds_violating_out_of = 4 | ||
} | ||
|
||
resource "thousandeyes_agent_to_server" "agent_to_server_test" { | ||
test_name = "Agent To Server Test" | ||
interval = 300 | ||
alerts_enabled = true | ||
server = "api.stg.thousandeyes.com" | ||
protocol = "TCP" | ||
port = 443 | ||
enabled = true | ||
bgp_measurements = true | ||
use_public_bgp = true | ||
mtu_measurements = true | ||
|
||
agents { | ||
agent_id = data.thousandeyes_agent.amsterdam.agent_id | ||
} | ||
|
||
alert_rules { | ||
rule_id = thousandeyes_alert_rule.test.id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package thousandeyes | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
func TestAccThousandEyesAlertRule(t *testing.T) { | ||
var alertRuleResourceName = "thousandeyes_alert_rule.test" | ||
testCases := []struct { | ||
name string | ||
createResourceFile string | ||
updateResourceFile string | ||
checkDestroyFunction func(*terraform.State) error | ||
checkCreateFunc []resource.TestCheckFunc | ||
checkUpdateFunc []resource.TestCheckFunc | ||
}{ | ||
{ | ||
name: "test_association_maintained_after_alert_rule_update", | ||
createResourceFile: "acceptance_resources/alert_rule/create_test_with_alert_rule.tf", | ||
updateResourceFile: "acceptance_resources/alert_rule/update_alert_rule.tf", | ||
checkDestroyFunction: func(state *terraform.State) error { | ||
resourceList := []ResourceType{ | ||
{ | ||
Name: "Agent To Server Test", | ||
ResourceName: "thousandeyes_agent_to_server", | ||
GetResource: func(id int64) (interface{}, error) { | ||
return testClient.GetAgentServer(id) | ||
}}, | ||
{ | ||
Name: "Agent To Server Alert Rule Test", | ||
ResourceName: "thousandeyes_alert_rule", | ||
GetResource: func(id int64) (interface{}, error) { | ||
return testClient.GetAlertRule(id) | ||
}}, | ||
} | ||
return testAccCheckResourceDestroy(resourceList, state) | ||
}, | ||
checkCreateFunc: []resource.TestCheckFunc{ | ||
//alert rule is created | ||
//with 3 required violating rounds | ||
resource.TestCheckResourceAttr(alertRuleResourceName, "rounds_violating_required", "3"), | ||
}, | ||
checkUpdateFunc: []resource.TestCheckFunc{ | ||
//alert rule is updated | ||
//to 4 required violating rounds | ||
resource.TestCheckResourceAttr(alertRuleResourceName, "rounds_violating_required", "4"), | ||
//and the test association is maintained | ||
resource.TestCheckResourceAttr(alertRuleResourceName, "test_ids.#", "1"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
CheckDestroy: tc.checkDestroyFunction, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccThousandEyesAlertRuleConfig(tc.createResourceFile), | ||
Check: resource.ComposeTestCheckFunc(tc.checkCreateFunc...), | ||
}, | ||
{ | ||
Config: testAccThousandEyesAlertRuleConfig(tc.updateResourceFile), | ||
Check: resource.ComposeTestCheckFunc(tc.checkUpdateFunc...), | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func testAccThousandEyesAlertRuleConfig(testResource string) string { | ||
content, err := os.ReadFile(testResource) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return string(content) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters