Skip to content
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

fix: alert rule and tests association #168

Merged
merged 5 commits into from
May 13, 2024
Merged

Conversation

brumarqu-te
Copy link
Contributor

@brumarqu-te brumarqu-te commented May 10, 2024

fixes #158
This issue is happening because we currently allow the alert rule <-> test association to be established from both perspectives. From the alert rule update perspective, it will clear any test association if the list of testIds is not sent in the request.
This PR changes the alert rule test_ids schema attribute to be computed so that it is not considered in the TF plan but it's still retrieved from the alert rule get by id operation and passed along the alert rule update request.
Also, since the alert rule returns a field tests when getting by id and receives a field testIds when updating the alert rule, had to implement a map from the GenericTest to get only the testId.

One drawback of this approach (not a huge one IMO) is that the state may not always be accurate. This is because a test <-> alert rules association can be changed from the test perspective and not get reflected on the alert rule perspective. Anyways, it will eventually update the state when the next alert rule update is performed.

@brumarqu-te brumarqu-te marked this pull request as ready for review May 10, 2024 08:20
@brumarqu-te
Copy link
Contributor Author

@brumarqu-te brumarqu-te changed the title Fix alert rule tests fix: alert rule and tests association May 10, 2024
Co-authored-by: Jack Browne <[email protected]>
@brumarqu-te brumarqu-te force-pushed the fix_alert_rule_tests branch from bb62dcf to 03f213c Compare May 10, 2024 08:33
@@ -0,0 +1,34 @@
data "thousandeyes_agent" "amsterdam" {
agent_name = "Amsterdam, Netherlands"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, more ATs for this repo! 💪

},
checkUpdateFunc: []resource.TestCheckFunc{
resource.TestCheckResourceAttr(alertRuleResourceName, "rounds_violating_required", "4"),
resource.TestCheckResourceAttr(alertRuleResourceName, "test_ids.#", "1"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to start adding some comments to these Acceptance tests - the ones that I created also do not have them and they should!
It's not immediate to understand that here we are making sure that if an alertRule is updated, them the tests associated with it are not cleared. Can you add a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried to reflect that in the test name but i guess i failed miserably 😅
i've added the comments, take another look when possible

Copy link
Contributor

@joaomper-TE joaomper-TE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: didn't knew about this computed terraform attribute! This can come in handy in some edge case scenarios, such as this one

@brumarqu-te brumarqu-te force-pushed the fix_alert_rule_tests branch from cf60211 to 08e1aab Compare May 10, 2024 14:17
@brumarqu-te brumarqu-te merged commit 2beea37 into main May 13, 2024
3 checks passed
@brumarqu-te brumarqu-te deleted the fix_alert_rule_tests branch May 13, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants