diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 51fe22bcea..b14fc3ed63 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -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. 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. 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 @@ -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: diff --git a/src/datadog_api_client/v1/api/monitors_api.py b/src/datadog_api_client/v1/api/monitors_api.py index 13c824ff80..2c266cd440 100644 --- a/src/datadog_api_client/v1/api/monitors_api.py +++ b/src/datadog_api_client/v1/api/monitors_api.py @@ -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: diff --git a/src/datadog_api_client/v1/model/monitor_thresholds.py b/src/datadog_api_client/v1/model/monitor_thresholds.py index c114304c71..e914812185 100644 --- a/src/datadog_api_client/v1/model/monitor_thresholds.py +++ b/src/datadog_api_client/v1/model/monitor_thresholds.py @@ -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), @@ -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", @@ -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, @@ -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. 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. 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 @@ -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: diff --git a/tests/v1/features/monitors.feature b/tests/v1/features/monitors.feature index 73ed30421f..e3e5ca6c41 100644 --- a/tests/v1/features/monitors.feature +++ b/tests/v1/features/monitors.feature @@ -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