Skip to content

Commit 08fdb80

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add critical_query / critical_recovery_query to MonitorThresholds (#3873)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 17462a2 commit 08fdb80

4 files changed

Lines changed: 87 additions & 2 deletions

File tree

.generator/schemas/v1/openapi.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9229,11 +9229,19 @@ components:
92299229
description: The monitor `CRITICAL` threshold.
92309230
format: double
92319231
type: number
9232+
critical_query:
9233+
description: Query evaluated as a dynamic `CRITICAL` threshold. Only supported on metric monitors with a formula query and options['variables']. Cannot be combined with static thresholds. This field is in preview.
9234+
example: 'formula("2 * query1").rollup("avg").last("6mo")'
9235+
type: string
92329236
critical_recovery:
92339237
description: The monitor `CRITICAL` recovery threshold.
92349238
format: double
92359239
nullable: true
92369240
type: number
9241+
critical_recovery_query:
9242+
description: Query evaluated as a dynamic `CRITICAL` recovery threshold. Only supported on metric monitors with a formula query and options['variables']. Cannot be combined with static thresholds. This field is in preview.
9243+
example: 'formula("1.5 * query1").rollup("avg").last("3mo")'
9244+
type: string
92379245
ok:
92389246
description: The monitor `OK` threshold.
92399247
format: double
@@ -33700,6 +33708,10 @@ paths:
3370033708
- `operator`: <, <=, >, >=, ==, or !=
3370133709
- `#`: an integer or decimal number used to set the threshold
3370233710

33711+
To use a dynamic threshold on a metric monitor with a formula query, replace `#` with the `threshold` keyword
33712+
(for example, `... > threshold`) and provide the threshold as a query via `critical_query` on `options.thresholds`.
33713+
This feature is in preview.
33714+
3370333715
If you are using the `_change_` or `_pct_change_` time aggregator, instead use `change_aggr(time_aggr(time_window),
3370433716
timeshift):space_aggr:metric{tags} [by {key}] operator #` with:
3370533717

src/main/java/com/datadog/api/client/v1/api/MonitorsApi.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ public CompletableFuture<Monitor> createMonitorAsync(Monitor body) {
279279
* <li><code>#</code>: an integer or decimal number used to set the threshold
280280
* </ul>
281281
*
282+
* <p>To use a dynamic threshold on a metric monitor with a formula query, replace <code>#</code>
283+
* with the <code>threshold</code> keyword (for example, <code>... &gt; threshold</code>) and
284+
* provide the threshold as a query via <code>critical_query</code> on <code>options.thresholds
285+
* </code>. This feature is in preview.
286+
*
282287
* <p>If you are using the <code>_change_</code> or <code>_pct_change_</code> time aggregator,
283288
* instead use <code>change_aggr(time_aggr(time_window),
284289
* timeshift):space_aggr:metric{tags} [by {key}] operator #</code> with:

src/main/java/com/datadog/api/client/v1/model/MonitorThresholds.java

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
/** List of the different monitor threshold available. */
2121
@JsonPropertyOrder({
2222
MonitorThresholds.JSON_PROPERTY_CRITICAL,
23+
MonitorThresholds.JSON_PROPERTY_CRITICAL_QUERY,
2324
MonitorThresholds.JSON_PROPERTY_CRITICAL_RECOVERY,
25+
MonitorThresholds.JSON_PROPERTY_CRITICAL_RECOVERY_QUERY,
2426
MonitorThresholds.JSON_PROPERTY_OK,
2527
MonitorThresholds.JSON_PROPERTY_UNKNOWN,
2628
MonitorThresholds.JSON_PROPERTY_WARNING,
@@ -33,9 +35,15 @@ public class MonitorThresholds {
3335
public static final String JSON_PROPERTY_CRITICAL = "critical";
3436
private Double critical;
3537

38+
public static final String JSON_PROPERTY_CRITICAL_QUERY = "critical_query";
39+
private String criticalQuery;
40+
3641
public static final String JSON_PROPERTY_CRITICAL_RECOVERY = "critical_recovery";
3742
private JsonNullable<Double> criticalRecovery = JsonNullable.<Double>undefined();
3843

44+
public static final String JSON_PROPERTY_CRITICAL_RECOVERY_QUERY = "critical_recovery_query";
45+
private String criticalRecoveryQuery;
46+
3947
public static final String JSON_PROPERTY_OK = "ok";
4048
private JsonNullable<Double> ok = JsonNullable.<Double>undefined();
4149

@@ -69,6 +77,29 @@ public void setCritical(Double critical) {
6977
this.critical = critical;
7078
}
7179

80+
public MonitorThresholds criticalQuery(String criticalQuery) {
81+
this.criticalQuery = criticalQuery;
82+
return this;
83+
}
84+
85+
/**
86+
* Query evaluated as a dynamic <code>CRITICAL</code> threshold. Only supported on metric monitors
87+
* with a formula query and options['variables']. Cannot be combined with static thresholds. This
88+
* field is in preview.
89+
*
90+
* @return criticalQuery
91+
*/
92+
@jakarta.annotation.Nullable
93+
@JsonProperty(JSON_PROPERTY_CRITICAL_QUERY)
94+
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
95+
public String getCriticalQuery() {
96+
return criticalQuery;
97+
}
98+
99+
public void setCriticalQuery(String criticalQuery) {
100+
this.criticalQuery = criticalQuery;
101+
}
102+
72103
public MonitorThresholds criticalRecovery(Double criticalRecovery) {
73104
this.criticalRecovery = JsonNullable.<Double>of(criticalRecovery);
74105
return this;
@@ -100,6 +131,29 @@ public void setCriticalRecovery(Double criticalRecovery) {
100131
this.criticalRecovery = JsonNullable.<Double>of(criticalRecovery);
101132
}
102133

134+
public MonitorThresholds criticalRecoveryQuery(String criticalRecoveryQuery) {
135+
this.criticalRecoveryQuery = criticalRecoveryQuery;
136+
return this;
137+
}
138+
139+
/**
140+
* Query evaluated as a dynamic <code>CRITICAL</code> recovery threshold. Only supported on metric
141+
* monitors with a formula query and options['variables']. Cannot be combined with static
142+
* thresholds. This field is in preview.
143+
*
144+
* @return criticalRecoveryQuery
145+
*/
146+
@jakarta.annotation.Nullable
147+
@JsonProperty(JSON_PROPERTY_CRITICAL_RECOVERY_QUERY)
148+
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
149+
public String getCriticalRecoveryQuery() {
150+
return criticalRecoveryQuery;
151+
}
152+
153+
public void setCriticalRecoveryQuery(String criticalRecoveryQuery) {
154+
this.criticalRecoveryQuery = criticalRecoveryQuery;
155+
}
156+
103157
public MonitorThresholds ok(Double ok) {
104158
this.ok = JsonNullable.<Double>of(ok);
105159
return this;
@@ -281,7 +335,9 @@ public boolean equals(Object o) {
281335
}
282336
MonitorThresholds monitorThresholds = (MonitorThresholds) o;
283337
return Objects.equals(this.critical, monitorThresholds.critical)
338+
&& Objects.equals(this.criticalQuery, monitorThresholds.criticalQuery)
284339
&& Objects.equals(this.criticalRecovery, monitorThresholds.criticalRecovery)
340+
&& Objects.equals(this.criticalRecoveryQuery, monitorThresholds.criticalRecoveryQuery)
285341
&& Objects.equals(this.ok, monitorThresholds.ok)
286342
&& Objects.equals(this.unknown, monitorThresholds.unknown)
287343
&& Objects.equals(this.warning, monitorThresholds.warning)
@@ -292,15 +348,27 @@ public boolean equals(Object o) {
292348
@Override
293349
public int hashCode() {
294350
return Objects.hash(
295-
critical, criticalRecovery, ok, unknown, warning, warningRecovery, additionalProperties);
351+
critical,
352+
criticalQuery,
353+
criticalRecovery,
354+
criticalRecoveryQuery,
355+
ok,
356+
unknown,
357+
warning,
358+
warningRecovery,
359+
additionalProperties);
296360
}
297361

298362
@Override
299363
public String toString() {
300364
StringBuilder sb = new StringBuilder();
301365
sb.append("class MonitorThresholds {\n");
302366
sb.append(" critical: ").append(toIndentedString(critical)).append("\n");
367+
sb.append(" criticalQuery: ").append(toIndentedString(criticalQuery)).append("\n");
303368
sb.append(" criticalRecovery: ").append(toIndentedString(criticalRecovery)).append("\n");
369+
sb.append(" criticalRecoveryQuery: ")
370+
.append(toIndentedString(criticalRecoveryQuery))
371+
.append("\n");
304372
sb.append(" ok: ").append(toIndentedString(ok)).append("\n");
305373
sb.append(" unknown: ").append(toIndentedString(unknown)).append("\n");
306374
sb.append(" warning: ").append(toIndentedString(warning)).append("\n");

src/test/resources/com/datadog/api/client/v1/api/monitors.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Feature: Monitors
219219
Scenario: Edit a monitor returns "Bad Request" response
220220
Given new "UpdateMonitor" request
221221
And request contains "monitor_id" parameter from "REPLACE.ME"
222-
And body with value {"assets": [{"category": "runbook", "name": "Monitor Runbook", "resource_key": "12345", "resource_type": "notebook", "url": "/notebooks/12345"}], "draft_status": "published", "options": {"evaluation_delay": null, "include_tags": true, "min_failure_duration": 0, "min_location_failed": 1, "new_group_delay": null, "new_host_delay": 300, "no_data_timeframe": null, "notification_preset_name": "show_all", "notify_audit": false, "notify_by": [], "on_missing_data": "default", "renotify_interval": null, "renotify_occurrences": null, "renotify_statuses": ["alert"], "scheduling_options": {"custom_schedule": {"recurrences": [{"rrule": "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR", "start": "2023-08-31T16:30:00", "timezone": "Europe/Paris"}]}, "evaluation_window": {"day_starts": "04:00", "hour_starts": 0, "month_starts": 1, "timezone": "Europe/Paris"}}, "synthetics_check_id": null, "threshold_windows": {"recovery_window": null, "trigger_window": null}, "thresholds": {"critical_recovery": null, "ok": null, "unknown": null, "warning": null, "warning_recovery": null}, "timeout_h": null, "variables": [{"compute": {"aggregation": "avg", "interval": 60000, "metric": "@duration", "name": "compute_result", "source": "filter_query"}, "data_source": "rum", "group_by": [{"facet": "status", "limit": 10, "sort": {"aggregation": "avg", "order": "desc"}, "source": "filter_query"}], "indexes": ["days-3", "days-7"], "name": "query_errors", "search": {"query": "service:query"}}]}, "priority": null, "restricted_roles": [], "tags": [], "type": "query alert"}
222+
And body with value {"assets": [{"category": "runbook", "name": "Monitor Runbook", "resource_key": "12345", "resource_type": "notebook", "url": "/notebooks/12345"}], "draft_status": "published", "options": {"evaluation_delay": null, "include_tags": true, "min_failure_duration": 0, "min_location_failed": 1, "new_group_delay": null, "new_host_delay": 300, "no_data_timeframe": null, "notification_preset_name": "show_all", "notify_audit": false, "notify_by": [], "on_missing_data": "default", "renotify_interval": null, "renotify_occurrences": null, "renotify_statuses": ["alert"], "scheduling_options": {"custom_schedule": {"recurrences": [{"rrule": "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR", "start": "2023-08-31T16:30:00", "timezone": "Europe/Paris"}]}, "evaluation_window": {"day_starts": "04:00", "hour_starts": 0, "month_starts": 1, "timezone": "Europe/Paris"}}, "synthetics_check_id": null, "threshold_windows": {"recovery_window": null, "trigger_window": null}, "thresholds": {"critical_query": "formula(\"2 * query1\").rollup(\"avg\").last(\"6mo\")", "critical_recovery": null, "critical_recovery_query": "formula(\"1.5 * query1\").rollup(\"avg\").last(\"3mo\")", "ok": null, "unknown": null, "warning": null, "warning_recovery": null}, "timeout_h": null, "variables": [{"compute": {"aggregation": "avg", "interval": 60000, "metric": "@duration", "name": "compute_result", "source": "filter_query"}, "data_source": "rum", "group_by": [{"facet": "status", "limit": 10, "sort": {"aggregation": "avg", "order": "desc"}, "source": "filter_query"}], "indexes": ["days-3", "days-7"], "name": "query_errors", "search": {"query": "service:query"}}]}, "priority": null, "restricted_roles": [], "tags": [], "type": "query alert"}
223223
When the request is sent
224224
Then the response status is 400 Bad Request
225225

0 commit comments

Comments
 (0)