-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
azurerm_monitor_metric_alert
supports multiple scopes and different criteria
#7159
azurerm_monitor_metric_alert
supports multiple scopes and different criteria
#7159
Conversation
… criterias Originally, the resource only allows user to specify one scope. Furthermore, it only allow user to specify static criteria, while there are dynamic criterias and "webtest available location" criterias. This PR tries to support both facets and not to introduce breaking change.
:-( got pushed back a week ... was hanging on this one... |
* `operator` - (Required) The criteria operator. Possible values are `LessThan`, `GreaterThan` and `GreaterOrLessThan`. | ||
* `alert_sensitivity` - (Required) The extent of deviation required to trigger an alert. Possible values are `Low`, `Medium` and `High`. | ||
* `dimension` - (Optional) One or more `dimension` blocks as defined below. | ||
* `evaluation_total_account` - (Optional) The number of aggregated lookback points. The lookback time window is calculated based on the aggregation granularity (`window_size`) and the selected number of aggregated points. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here, should be evaluation_total_count
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, Thank you!
@katbyte can i confirm if this will make the cut for 2.16? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments whilst passing through
azurerm/internal/services/monitor/monitor_metric_alert_resource.go
Outdated
Show resolved
Hide resolved
azurerm/internal/services/monitor/tests/monitor_metric_alert_resource_test.go
Outdated
Show resolved
Hide resolved
|
||
return []interface{}{ | ||
map[string]interface{}{ | ||
"webtest_id": webtestID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this make more sense as web_test_id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think webtest is a better fit as it emphasize it is special name called webtest, rather than some test of web?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's an existing resource for this with web_test
- so it'd be worth making this consistent to be clearer
arguably this could make sense as application_insights_web_test_id
rather than such a generic name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rename the criteria name (the name of the nested block) into application_insights_web_test_location_availability_criteria
, and keep the including attributes still (e.g. component_id
), except renaming the included webtest_id
into web_test_id
.
azurerm/internal/services/monitor/monitor_metric_alert_resource.go
Outdated
Show resolved
Hide resolved
Hey @tombuildsstuff Thank you for your review! Test Result💤 make testacc TEST=./azurerm/internal/services/monitor/tests TESTARGS="-run=TestAccAzureRMMonitorMetricAlert_multiScope"
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test ./azurerm/internal/services/monitor/tests -v -run=TestAccAzureRMMonitorMetricAlert_multiScope -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN TestAccAzureRMMonitorMetricAlert_multiScope
=== PAUSE TestAccAzureRMMonitorMetricAlert_multiScope
=== CONT TestAccAzureRMMonitorMetricAlert_multiScope
--- PASS: TestAccAzureRMMonitorMetricAlert_multiScope (1060.25s)
PASS
ok github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor/tests 1060.277s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@magodo I've taken another look through and this mostly LGTM - if we can ensure all the fields are set then this otherwise LGTM 👍
"target_resource_type": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be Computed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for the single scope of a certain resource, the target_resource_type
will be deduced by service and returned in the response.
"target_resource_location": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be Computed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reason as above.
azurerm/internal/services/monitor/monitor_metric_alert_resource.go
Outdated
Show resolved
Hide resolved
azurerm/internal/services/monitor/monitor_metric_alert_resource.go
Outdated
Show resolved
Hide resolved
return expandMonitorMetricAlertWebtestLocAvailCriteria(d.Get("webtest_location_availability_criteria").([]interface{})), nil | ||
default: | ||
// Guaranteed by schema `AtLeastOne` constraint | ||
return nil, errors.New("unknwon criteria type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, errors.New("unknwon criteria type") | |
return nil, fmt.Errorf("unknown criteria type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this as there is no argument except the format string here.
azurerm/internal/services/monitor/monitor_metric_alert_resource.go
Outdated
Show resolved
Hide resolved
|
||
return []interface{}{ | ||
map[string]interface{}{ | ||
"webtest_id": webtestID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's an existing resource for this with web_test
- so it'd be worth making this consistent to be clearer
arguably this could make sense as application_insights_web_test_id
rather than such a generic name?
@tombuildsstuff I have updated some code per your comments and replied the other comments with justifications, please take a look! |
This has been released in version 2.19.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example: provider "azurerm" {
version = "~> 2.19.0"
}
# ... other configuration ... |
thanks @jackofallops appreciate this! :-D |
…tiMetricCriteria for legacy metric alerts (#7995) The change in #7159 deprecates the usage of SingleResourceMultiMetricCriteria outright (replaced by MultipleResourceMultipleMetricCriteria). Unfortunately, that breaks the users who have metric alert created before that PR merged, which was using SingleResourceMultiMetricCriteria as its type. Then once those metric alerts get updated, current code will trigger an update from SingleResourceMultiMetricCriteria to MultipleResourceMultipleMetricCriteria, which seems not supported by service (as reported in #7910). This PR keeps those legacy resource to use the SingleResourceMultiMetricCriteria. If user wants to use the MultipleResourceMultipleMetricCriteria, they will have to recreate the resource. (fixes #7910)
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Originally, the resource only allows users to specify one scope. Furthermore, it only allows the user to specify static criteria, while there are dynamic criteria and "web test location availability" criteria.
This PR tries to support both facets and not to introduce breaking change.
The complex part of kinds of criteria is that there are two levels of discriminator defined in swagger, as shown below:
Previous code was using the
SingleResourceMultipleMetricCriteria
, while this is superseded byMultipleResourceMultipleMetricCriteria
, which in turns derives intoStaticMetricCriteria
(actuallyMetricCriteria
, which was underused) andDynamicMetricCriteria
. Additionally, there is another criteriaWebtestLocationAvailabilityMetricCriteria
. In order to keep schema use to use and (most importantly) to keep backward compatibility, I defined three criteria in schema:criteria
: same as before represents theStaticMetricCriteria
. Each alert can specify one or morecriteria
.dynamic_criteria
: represents theDynamicMetricCriteria
. Each alert can only have one such criterion.webtest_location_availability_criteria
: representsWebtestLocationAvailabilityMetricCriteria
. Each alert can only have one such criteria.And then set them Optional and add the
ExactlyOneOf
constraints among them.Another change is that I added two more attributes called
target_resource_type
andtarget_resource_location
, which are mandatory when either multiplescopes
are set or the subscription/resource group scope is specified, in which case the service need to use this information to identify the resource type and resource location.Test Result
(fxes #3719, fixes #3886)