Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9229,11 +9229,19 @@ components:
description: The monitor `CRITICAL` threshold.
format: double
type: number
critical_query:
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.
example: 'formula("2 * query1").rollup("avg").last("6mo")'
type: string
critical_recovery:
description: The monitor `CRITICAL` recovery threshold.
format: double
nullable: true
type: number
critical_recovery_query:
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.
example: 'formula("1.5 * query1").rollup("avg").last("3mo")'
type: string
ok:
description: The monitor `OK` threshold.
format: double
Expand Down Expand Up @@ -33700,6 +33708,10 @@ paths:
- `operator`: <, <=, >, >=, ==, or !=
- `#`: an integer or decimal number used to set the threshold

To use a dynamic threshold on a metric monitor with a formula query, replace `#` with the `threshold` keyword
(for example, `... > threshold`) and provide the threshold as a query via `critical_query` on `options.thresholds`.
This feature is in preview.

If you are using the `_change_` or `_pct_change_` time aggregator, instead use `change_aggr(time_aggr(time_window),
timeshift):space_aggr:metric{tags} [by {key}] operator #` with:

Expand Down
4 changes: 4 additions & 0 deletions src/datadog_api_client/v1/api/monitors_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ def create_monitor(
* ``operator`` : <, <=, >, >=, ==, or !=
* ``#`` : an integer or decimal number used to set the threshold

To use a dynamic threshold on a metric monitor with a formula query, replace ``#`` with the ``threshold`` keyword
(for example, ``... > threshold`` ) and provide the threshold as a query via ``critical_query`` on ``options.thresholds``.
This feature is in preview.

If you are using the ``_change_`` or ``_pct_change_`` time aggregator, instead use ``change_aggr(time_aggr(time_window),
timeshift):space_aggr:metric{tags} [by {key}] operator #`` with:

Expand Down
16 changes: 16 additions & 0 deletions src/datadog_api_client/v1/model/monitor_thresholds.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class MonitorThresholds(ModelNormal):
def openapi_types(_):
return {
"critical": (float,),
"critical_query": (str,),
"critical_recovery": (float, none_type),
"critical_recovery_query": (str,),
"ok": (float, none_type),
"unknown": (float, none_type),
"warning": (float, none_type),
Expand All @@ -28,7 +30,9 @@ def openapi_types(_):

attribute_map = {
"critical": "critical",
"critical_query": "critical_query",
"critical_recovery": "critical_recovery",
"critical_recovery_query": "critical_recovery_query",
"ok": "ok",
"unknown": "unknown",
"warning": "warning",
Expand All @@ -38,7 +42,9 @@ def openapi_types(_):
def __init__(
self_,
critical: Union[float, UnsetType] = unset,
critical_query: Union[str, UnsetType] = unset,
critical_recovery: Union[float, none_type, UnsetType] = unset,
critical_recovery_query: Union[str, UnsetType] = unset,
ok: Union[float, none_type, UnsetType] = unset,
unknown: Union[float, none_type, UnsetType] = unset,
warning: Union[float, none_type, UnsetType] = unset,
Expand All @@ -51,9 +57,15 @@ def __init__(
:param critical: The monitor ``CRITICAL`` threshold.
:type critical: float, optional

:param critical_query: 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.
:type critical_query: str, optional

:param critical_recovery: The monitor ``CRITICAL`` recovery threshold.
:type critical_recovery: float, none_type, optional

:param critical_recovery_query: 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.
:type critical_recovery_query: str, optional

:param ok: The monitor ``OK`` threshold.
:type ok: float, none_type, optional

Expand All @@ -68,8 +80,12 @@ def __init__(
"""
if critical is not unset:
kwargs["critical"] = critical
if critical_query is not unset:
kwargs["critical_query"] = critical_query
if critical_recovery is not unset:
kwargs["critical_recovery"] = critical_recovery
if critical_recovery_query is not unset:
kwargs["critical_recovery_query"] = critical_recovery_query
if ok is not unset:
kwargs["ok"] = ok
if unknown is not unset:
Expand Down
2 changes: 1 addition & 1 deletion tests/v1/features/monitors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Feature: Monitors
Scenario: Edit a monitor returns "Bad Request" response
Given new "UpdateMonitor" request
And request contains "monitor_id" parameter from "REPLACE.ME"
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"}
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"}
When the request is sent
Then the response status is 400 Bad Request

Expand Down
Loading