Skip to content

Commit 0ef4627

Browse files
committed
Addressing the final PR comments.
1 parent 91b361d commit 0ef4627

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

docs/resources/kibana_alerting_rule.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ Could not create API key - Unsupported scheme "ApiKey" for granting API Key
6363
- `actions` (Block List) An action that runs under defined conditions. (see [below for nested schema](#nestedblock--actions))
6464
- `alert_delay` (Number) A number that indicates how many consecutive runs need to meet the rule conditions for an alert to occur.
6565
- `enabled` (Boolean) Indicates if you want to run the rule on an interval basis.
66-
- `notify_when` (String) Deprecated in 8.13.0. Use the `notify_when` property in the action `frequency` object instead. Defines how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `notify_when` values.
66+
- `notify_when` (String) Required until v8.6.0. Deprecated in v8.13.0. Use the `notify_when` property in the action `frequency` object instead. Defines how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `notify_when` values.
6767
- `rule_id` (String) A UUID v1 or v4 to use instead of a randomly generated ID.
6868
- `space_id` (String) An identifier for the space. If space_id is not provided, the default space is used.
6969
- `tags` (List of String) A list of tag names that are applied to the rule.
70-
- `throttle` (String) Defines how often an alert generates repeated actions. This custom action interval must be specified in seconds, minutes, hours, or days. For example, 10m or 1h. This property is applicable only if `notify_when` is `onThrottleInterval`. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `throttle` values.
70+
- `throttle` (String) Required until v8.6.0. Deprecated in 8.13.0. Defines how often an alert generates repeated actions. This custom action interval must be specified in seconds, minutes, hours, or days. For example, 10m or 1h. This property is applicable only if `notify_when` is `onThrottleInterval`. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `throttle` values.
7171

7272
### Read-Only
7373

internal/kibana/alerting.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
)
1818

1919
var alertDelayMinSupportedVersion = version.Must(version.NewVersion("8.13.0"))
20+
21+
// when notify_when and throttle became optional
2022
var frequencyMinSupportedVersion = version.Must(version.NewVersion("8.6.0"))
2123

2224
func ResourceAlertingRule() *schema.Resource {
@@ -47,7 +49,7 @@ func ResourceAlertingRule() *schema.Resource {
4749
ForceNew: true,
4850
},
4951
"notify_when": {
50-
Description: "Deprecated in 8.13.0. Use the `notify_when` property in the action `frequency` object instead. Defines how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `notify_when` values.",
52+
Description: "Required until v8.6.0. Deprecated in v8.13.0. Use the `notify_when` property in the action `frequency` object instead. Defines how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `notify_when` values.",
5153
Type: schema.TypeString,
5254
Optional: true,
5355
ValidateFunc: validation.StringInSlice([]string{"onActionGroupChange", "onActiveAlert", "onThrottleInterval"}, false),
@@ -140,7 +142,7 @@ func ResourceAlertingRule() *schema.Resource {
140142
},
141143
},
142144
"throttle": {
143-
Description: "Defines how often an alert generates repeated actions. This custom action interval must be specified in seconds, minutes, hours, or days. For example, 10m or 1h. This property is applicable only if `notify_when` is `onThrottleInterval`. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `throttle` values.",
145+
Description: "Required until v8.6.0. Deprecated in 8.13.0. Defines how often an alert generates repeated actions. This custom action interval must be specified in seconds, minutes, hours, or days. For example, 10m or 1h. This property is applicable only if `notify_when` is `onThrottleInterval`. NOTE: This is a rule level property; if you update the rule in Kibana, it is automatically changed to use action-specific `throttle` values.",
144146
Type: schema.TypeString,
145147
Optional: true,
146148
ValidateFunc: utils.StringIsDuration,
@@ -215,10 +217,30 @@ func getAlertingRuleFromResourceData(d *schema.ResourceData, serverVersion *vers
215217
if v, ok := d.GetOk("throttle"); ok {
216218
t := v.(string)
217219
rule.Throttle = &t
220+
} else {
221+
if serverVersion.LessThan(frequencyMinSupportedVersion) {
222+
return models.AlertingRule{}, diag.Diagnostics{
223+
diag.Diagnostic{
224+
Severity: diag.Error,
225+
Summary: "throttle is required until v8.6",
226+
Detail: "throttle is required until v8.6",
227+
},
228+
}
229+
}
218230
}
219231

220232
if v, ok := d.GetOk("notify_when"); ok {
221233
rule.NotifyWhen = utils.Pointer(v.(string))
234+
} else {
235+
if serverVersion.LessThan(frequencyMinSupportedVersion) {
236+
return models.AlertingRule{}, diag.Diagnostics{
237+
diag.Diagnostic{
238+
Severity: diag.Error,
239+
Summary: "notify_when is required until v8.6",
240+
Detail: "notify_when is required until v8.6",
241+
},
242+
}
243+
}
222244
}
223245

224246
if v, ok := d.GetOk("alert_delay"); ok {
@@ -230,7 +252,6 @@ func getAlertingRuleFromResourceData(d *schema.ResourceData, serverVersion *vers
230252
Detail: "alert_delay is only supported for Elasticsearch v8.13 or higher",
231253
},
232254
}
233-
234255
}
235256

236257
rule.AlertDelay = utils.Pointer(float32(v.(float64)))

0 commit comments

Comments
 (0)