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

Support for auto-mitigate for Monitor scheduled query rules alerts #13036 #13213

Merged
merged 18 commits into from
Sep 15, 2021

Conversation

cloutier
Copy link
Contributor

@cloutier cloutier commented Sep 1, 2021

No description provided.

@cloutier cloutier changed the title Support for auto-mitigate for Azure scheduled_query #13036 Support for auto-mitigate for Monitor scheduled query rules alerts #13036 Sep 1, 2021
@github-actions github-actions bot added size/M and removed size/XS labels Sep 2, 2021
@cloutier
Copy link
Contributor Author

cloutier commented Sep 2, 2021

I've incorporated changes from feedback from @Klaas- and I'm ready for another round of review

@Klaas-
Copy link
Contributor

Klaas- commented Sep 2, 2021

I think you can use "ConflictsWith" to ensure that no one sets them both, right?

@cloutier
Copy link
Contributor Author

cloutier commented Sep 2, 2021

"ConflictsWith" is interesting! I was looking at other ressources like application_gateway and they were validating in the update function, but ConflictsWith is the prefered way, right? Is it somewhat new?

@Klaas-
Copy link
Contributor

Klaas- commented Sep 2, 2021

I am not sure, I just started with terraform today :)

@cloutier
Copy link
Contributor Author

cloutier commented Sep 2, 2021

Ah no problem! @katbyte and @tombuildsstuff, what do you think?

@Klaas-
Copy link
Contributor

Klaas- commented Sep 3, 2021

So I tested the way it's currently implemented in this PR.
The error when using thorttling and auto_mitigate together, only in apply the error will happen? Is that wanted behavior?

2nd problem: even if I leave throttling away and I test it I still get Status=400 Code="BadRequest" Message="Auto mitigation must be disabled when action suppression is set".
Looking at the debug it still sends "throttlingInMin":0.
I am guessing they need to be not send at all for that API to work -- or would this be considered an API error on microsofts part because 0 minutes equals turned off?

@Klaas-
Copy link
Contributor

Klaas- commented Sep 3, 2021

there is another issue: #12341 that says this will need a new azure go sdk version

@Klaas-
Copy link
Contributor

Klaas- commented Sep 3, 2021

I am not sure where the throttlingInMin must be suppressed when it's zero, would that happen somewhere here:

or should that be handled here:
https://github.com/Azure/azure-sdk-for-go/blob/fbb66cedeb94af0a56ff6e8f31a44314af3ef114/services/preview/monitor/mgmt/2021-07-01-preview/insights/models.go#L479-L481

what I tested is inside the models.go I can just check if it's bigger than 0 and it works as expected.

I do not think it still needs a newer go sdk version, as stated in #12341, maybe that's needed for the 1 minute intervals not the statefulness.

@github-actions github-actions bot added size/XS and removed size/M labels Sep 7, 2021
@cloutier
Copy link
Contributor Author

cloutier commented Sep 7, 2021

I've done changes according to feedback. I've switched to use ConflictsWith and simplified the Update function.

Ideally I would touch as little as possible "throttle" in this PR. I want to help out a coworker that needs "auto_mitigate" as soon as possible.

I'm ready for another round of review

@Klaas-
Copy link
Contributor

Klaas- commented Sep 7, 2021

@cloutier did you see #13213 (comment) I think you also need to change something in

otherwise it will always send "throttlingInMin":0

I am not sure if you should change something in azure sdk or here though :)

@cloutier
Copy link
Contributor Author

cloutier commented Sep 7, 2021

@Klaas- Yes I have! This is outside the scope of what I want to do with this PR though

@Klaas-
Copy link
Contributor

Klaas- commented Sep 7, 2021

but without that auto mitigate won't work

@cloutier
Copy link
Contributor Author

cloutier commented Sep 7, 2021

Can you suggest a test scenario that worries you? I can add that

@cloutier
Copy link
Contributor Author

cloutier commented Sep 8, 2021

Thanks for the feedback @katbyte! I've done the changes you suggested.

I've added a test for the undocumented quirk that @Klaas- was talking about, but I saw it the logs of the pipeline that it hasn't actually run:

     testcase.go:88: Acceptance tests skipped unless env 'TF_ACC' set
--- SKIP: TestAccMonitorScheduledQueryRules_AutoMitigate (0.00s)

When is that test actually run? Also should I do things locally to run the test or is there a way to run it in this PR verification?

@Klaas-
Copy link
Contributor

Klaas- commented Sep 8, 2021

@cloutier I don't think the PR tests actually do tests on azure, if I understood https://github.com/hashicorp/terraform-provider-azurerm/blob/main/README.md#developing-the-provider correctly you need to run those manually.
for the tests I ran last friday I simply compiled your branch myself and put it into my local terraform also as described in the readme. I'll do the same tests with your updates next week (I'm off this week, and I don't have a private azure account). But as I said earlier, I don't think the changes suffice because you need to not send throttlingInMin at all which is not the case currently because the unset int32 is 0 and not nil.

@cloutier
Copy link
Contributor Author

cloutier commented Sep 8, 2021

I think I've finally figured a way to not send throttling if it's not set (in the last commit).

My question for tests is more: Does it run once upon merges? Or just before releases? Or from time to time?

Also another question for @katbyte: The default in this PR is set to true to be consistent with other ressources in this provider, but the default in the api is false. Did I make the right choice?

Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

Hi @cloutier, thanks for the previous changes, unfortunately I was still getting test failures. I've left some comments, once those are fixed up the tests should run and then we can merge this 🙂.

@cloutier
Copy link
Contributor Author

@stephybun Thanks for the feedback! 🙏 You are helping me getting better at Go and Terraform. Thanks also to @Klaas- for the warning about the pitfalls of this API

I think I'm ready for the final round of test and review

@cloutier cloutier requested a review from stephybun September 15, 2021 13:55
Copy link
Contributor

@Klaas- Klaas- left a comment

Choose a reason for hiding this comment

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

I've tested it, it now works and I can switch alerts from suppression to auto mitigation and back, nice work!

@stephybun
Copy link
Member

Thanks @cloutier - tests are passing 🎆. This LGTM 🥳

@stephybun stephybun added this to the v2.77.0 milestone Sep 15, 2021
@stephybun stephybun merged commit 2bfb63b into hashicorp:main Sep 15, 2021
stephybun added a commit that referenced this pull request Sep 15, 2021
@cloutier cloutier deleted the fix-13036 branch September 15, 2021 19:55
@github-actions
Copy link

This functionality has been released in v2.77.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants