Skip to content

Commit

Permalink
Add custom schedule to monitor scheduling options (#1681)
Browse files Browse the repository at this point in the history
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored Oct 5, 2023
1 parent f74ac02 commit f079744
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 6 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2023-10-04 20:38:45.655558",
"spec_repo_commit": "79ab1c3c"
"regenerated": "2023-10-05 15:54:41.516135",
"spec_repo_commit": "432a5a71"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2023-10-04 20:38:45.670703",
"spec_repo_commit": "79ab1c3c"
"regenerated": "2023-10-05 15:54:41.542763",
"spec_repo_commit": "432a5a71"
}
}
}
29 changes: 29 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6839,6 +6839,33 @@ components:
type: string
readOnly: true
type: object
MonitorOptionsCustomSchedule:
description: Configuration options for the custom schedule. **This feature is
in private beta.**
properties:
recurrences:
description: Array of custom schedule recurrences.
items:
$ref: '#/components/schemas/MonitorOptionsCustomScheduleRecurrence'
type: array
type: object
MonitorOptionsCustomScheduleRecurrence:
description: Configuration for a recurrence set on the monitor options for custom
schedule.
properties:
rrule:
description: Defines the recurrence rule (RRULE) for a given schedule.
example: FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR
type: string
start:
description: Defines the start date and time of the recurring schedule.
example: '2023-08-31T16:30:00'
type: string
timezone:
description: Defines the timezone the schedule runs on.
example: Europe/Paris
type: string
type: object
MonitorOptionsNotificationPresets:
default: show_all
description: Toggles the display of additional content sent in the monitor notification.
Expand All @@ -6856,6 +6883,8 @@ components:
MonitorOptionsSchedulingOptions:
description: Configuration options for scheduling.
properties:
custom_schedule:
$ref: '#/components/schemas/MonitorOptionsCustomSchedule'
evaluation_window:
$ref: '#/components/schemas/MonitorOptionsSchedulingOptionsEvaluationWindow'
type: object
Expand Down
14 changes: 14 additions & 0 deletions docs/datadog_api_client.v1.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,20 @@ monitor\_options\_aggregation
:members:
:show-inheritance:

monitor\_options\_custom\_schedule
----------------------------------

.. automodule:: datadog_api_client.v1.model.monitor_options_custom_schedule
:members:
:show-inheritance:

monitor\_options\_custom\_schedule\_recurrence
----------------------------------------------

.. automodule:: datadog_api_client.v1.model.monitor_options_custom_schedule_recurrence
:members:
:show-inheritance:

monitor\_options\_notification\_presets
---------------------------------------

Expand Down
57 changes: 57 additions & 0 deletions examples/v1/monitors/CreateMonitor_1539578087.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Create a metric monitor with a custom schedule returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v1.api.monitors_api import MonitorsApi
from datadog_api_client.v1.model.monitor import Monitor
from datadog_api_client.v1.model.monitor_options import MonitorOptions
from datadog_api_client.v1.model.monitor_options_custom_schedule import MonitorOptionsCustomSchedule
from datadog_api_client.v1.model.monitor_options_custom_schedule_recurrence import (
MonitorOptionsCustomScheduleRecurrence,
)
from datadog_api_client.v1.model.monitor_options_scheduling_options import MonitorOptionsSchedulingOptions
from datadog_api_client.v1.model.monitor_options_scheduling_options_evaluation_window import (
MonitorOptionsSchedulingOptionsEvaluationWindow,
)
from datadog_api_client.v1.model.monitor_thresholds import MonitorThresholds
from datadog_api_client.v1.model.monitor_type import MonitorType
from datadog_api_client.v1.model.on_missing_data_option import OnMissingDataOption

body = Monitor(
message="some message Notify: @hipchat-channel",
name="Example-Monitor",
query="avg(current_1mo):avg:system.load.5{*} > 0.5",
tags=[],
options=MonitorOptions(
thresholds=MonitorThresholds(
critical=0.5,
),
notify_audit=False,
on_missing_data=OnMissingDataOption.DEFAULT,
include_tags=False,
scheduling_options=MonitorOptionsSchedulingOptions(
evaluation_window=MonitorOptionsSchedulingOptionsEvaluationWindow(
day_starts="04:00",
month_starts=1,
),
custom_schedule=MonitorOptionsCustomSchedule(
recurrences=[
MonitorOptionsCustomScheduleRecurrence(
rrule="FREQ=DAILY;INTERVAL=1",
timezone="America/Los_Angeles",
start="2024-10-26T09:13:00",
),
],
),
),
),
type=MonitorType.QUERY_ALERT,
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = MonitorsApi(api_client)
response = api_instance.create_monitor(body=body)

print(response)
46 changes: 46 additions & 0 deletions src/datadog_api_client/v1/model/monitor_options_custom_schedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import List, Union, TYPE_CHECKING

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


if TYPE_CHECKING:
from datadog_api_client.v1.model.monitor_options_custom_schedule_recurrence import (
MonitorOptionsCustomScheduleRecurrence,
)


class MonitorOptionsCustomSchedule(ModelNormal):
@cached_property
def openapi_types(_):
from datadog_api_client.v1.model.monitor_options_custom_schedule_recurrence import (
MonitorOptionsCustomScheduleRecurrence,
)

return {
"recurrences": ([MonitorOptionsCustomScheduleRecurrence],),
}

attribute_map = {
"recurrences": "recurrences",
}

def __init__(self_, recurrences: Union[List[MonitorOptionsCustomScheduleRecurrence], UnsetType] = unset, **kwargs):
"""
Configuration options for the custom schedule. **This feature is in private beta.**
:param recurrences: Array of custom schedule recurrences.
:type recurrences: [MonitorOptionsCustomScheduleRecurrence], optional
"""
if recurrences is not unset:
kwargs["recurrences"] = recurrences
super().__init__(kwargs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import Union

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


class MonitorOptionsCustomScheduleRecurrence(ModelNormal):
@cached_property
def openapi_types(_):
return {
"rrule": (str,),
"start": (str,),
"timezone": (str,),
}

attribute_map = {
"rrule": "rrule",
"start": "start",
"timezone": "timezone",
}

def __init__(
self_,
rrule: Union[str, UnsetType] = unset,
start: Union[str, UnsetType] = unset,
timezone: Union[str, UnsetType] = unset,
**kwargs,
):
"""
Configuration for a recurrence set on the monitor options for custom schedule.
:param rrule: Defines the recurrence rule (RRULE) for a given schedule.
:type rrule: str, optional
:param start: Defines the start date and time of the recurring schedule.
:type start: str, optional
:param timezone: Defines the timezone the schedule runs on.
:type timezone: str, optional
"""
if rrule is not unset:
kwargs["rrule"] = rrule
if start is not unset:
kwargs["start"] = start
if timezone is not unset:
kwargs["timezone"] = timezone
super().__init__(kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


if TYPE_CHECKING:
from datadog_api_client.v1.model.monitor_options_custom_schedule import MonitorOptionsCustomSchedule
from datadog_api_client.v1.model.monitor_options_scheduling_options_evaluation_window import (
MonitorOptionsSchedulingOptionsEvaluationWindow,
)
Expand All @@ -22,27 +23,38 @@
class MonitorOptionsSchedulingOptions(ModelNormal):
@cached_property
def openapi_types(_):
from datadog_api_client.v1.model.monitor_options_custom_schedule import MonitorOptionsCustomSchedule
from datadog_api_client.v1.model.monitor_options_scheduling_options_evaluation_window import (
MonitorOptionsSchedulingOptionsEvaluationWindow,
)

return {
"custom_schedule": (MonitorOptionsCustomSchedule,),
"evaluation_window": (MonitorOptionsSchedulingOptionsEvaluationWindow,),
}

attribute_map = {
"custom_schedule": "custom_schedule",
"evaluation_window": "evaluation_window",
}

def __init__(
self_, evaluation_window: Union[MonitorOptionsSchedulingOptionsEvaluationWindow, UnsetType] = unset, **kwargs
self_,
custom_schedule: Union[MonitorOptionsCustomSchedule, UnsetType] = unset,
evaluation_window: Union[MonitorOptionsSchedulingOptionsEvaluationWindow, UnsetType] = unset,
**kwargs,
):
"""
Configuration options for scheduling.
:param custom_schedule: Configuration options for the custom schedule. **This feature is in private beta.**
:type custom_schedule: MonitorOptionsCustomSchedule, optional
:param evaluation_window: Configuration options for the evaluation window. If ``hour_starts`` is set, no other fields may be set. Otherwise, ``day_starts`` and ``month_starts`` must be set together.
:type evaluation_window: MonitorOptionsSchedulingOptionsEvaluationWindow, optional
"""
if custom_schedule is not unset:
kwargs["custom_schedule"] = custom_schedule
if evaluation_window is not unset:
kwargs["evaluation_window"] = evaluation_window
super().__init__(kwargs)
6 changes: 6 additions & 0 deletions src/datadog_api_client/v1/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@
from datadog_api_client.v1.model.monitor_group_search_result import MonitorGroupSearchResult
from datadog_api_client.v1.model.monitor_options import MonitorOptions
from datadog_api_client.v1.model.monitor_options_aggregation import MonitorOptionsAggregation
from datadog_api_client.v1.model.monitor_options_custom_schedule import MonitorOptionsCustomSchedule
from datadog_api_client.v1.model.monitor_options_custom_schedule_recurrence import (
MonitorOptionsCustomScheduleRecurrence,
)
from datadog_api_client.v1.model.monitor_options_notification_presets import MonitorOptionsNotificationPresets
from datadog_api_client.v1.model.monitor_options_scheduling_options import MonitorOptionsSchedulingOptions
from datadog_api_client.v1.model.monitor_options_scheduling_options_evaluation_window import (
Expand Down Expand Up @@ -1222,6 +1226,8 @@
"MonitorGroupSearchResult",
"MonitorOptions",
"MonitorOptionsAggregation",
"MonitorOptionsCustomSchedule",
"MonitorOptionsCustomScheduleRecurrence",
"MonitorOptionsNotificationPresets",
"MonitorOptionsSchedulingOptions",
"MonitorOptionsSchedulingOptionsEvaluationWindow",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-10-04T18:33:20.272Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
interactions:
- request:
body: '{"message":"some message Notify: @hipchat-channel","name":"Test-Create_a_metric_monitor_with_a_custom_schedule_returns_OK_response-1696444400","options":{"include_tags":false,"notify_audit":false,"on_missing_data":"default","scheduling_options":{"custom_schedule":{"recurrences":[{"rrule":"FREQ=DAILY;INTERVAL=1","start":"2024-10-26T09:13:00","timezone":"America/Los_Angeles"}]},"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"query":"avg(current_1mo):avg:system.load.5{*}
> 0.5","tags":[],"type":"query alert"}'
headers:
accept:
- application/json
content-type:
- application/json
method: POST
uri: https://api.datadoghq.com/api/v1/monitor
response:
body:
string: '{"id":132537965,"org_id":321813,"type":"query alert","name":"Test-Create_a_metric_monitor_with_a_custom_schedule_returns_OK_response-1696444400","message":"some
message Notify: @hipchat-channel","tags":[],"query":"avg(current_1mo):avg:system.load.5{*}
> 0.5","options":{"include_tags":false,"notify_audit":false,"on_missing_data":"default","scheduling_options":{"custom_schedule":{"recurrences":[{"rrule":"FREQ=DAILY;INTERVAL=1","start":"2024-10-26T09:13:00","timezone":"America/Los_Angeles"}]},"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5},"new_host_delay":300,"silenced":{}},"multi":false,"created_at":1696444400000,"created":"2023-10-04T18:33:20.388003+00:00","modified":"2023-10-04T18:33:20.388003+00:00","deleted":null,"restricted_roles":null,"priority":null,"overall_state_modified":null,"overall_state":"No
Data","creator":{"name":"CI Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","email":"team-intg-tools-libs-spam@datadoghq.com","id":2320499}}
'
headers:
content-type:
- application/json
status:
code: 200
message: OK
- request:
body: null
headers:
accept:
- application/json
method: DELETE
uri: https://api.datadoghq.com/api/v1/monitor/132537965
response:
body:
string: '{"deleted_monitor_id":132537965}
'
headers:
content-type:
- application/json
status:
code: 200
message: OK
version: 1
13 changes: 12 additions & 1 deletion tests/v1/features/monitors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ Feature: Monitors
And the response "name" is equal to "{{ unique }}"
And the response "query" is equal to "avg(current_1mo):avg:system.load.5{*} > 0.5"

@team:DataDog/monitor-app
Scenario: Create a metric monitor with a custom schedule returns "OK" response
Given new "CreateMonitor" request
And body with value {"message":"some message Notify: @hipchat-channel","name":"{{ unique }}","query":"avg(current_1mo):avg:system.load.5{*} > 0.5","tags":[],"options":{"thresholds":{"critical":0.5},"notify_audit":false,"on_missing_data":"default","include_tags":false,"scheduling_options":{"evaluation_window":{"day_starts":"04:00", "month_starts":1},"custom_schedule":{"recurrences":[{"rrule":"FREQ=DAILY;INTERVAL=1","timezone":"America/Los_Angeles","start":"2024-10-26T09:13:00"}]}}},"type":"query alert"}
When the request is sent
Then the response status is 200 OK
And the response "name" is equal to "{{ unique }}"
And the response "options.scheduling_options.custom_schedule.recurrences[0].rrule" is equal to "FREQ=DAILY;INTERVAL=1"
And the response "options.scheduling_options.custom_schedule.recurrences[0].start" is equal to "2024-10-26T09:13:00"
And the response "options.scheduling_options.custom_schedule.recurrences[0].timezone" is equal to "America/Los_Angeles"

@team:DataDog/monitor-app
Scenario: Create a monitor returns "Bad Request" response
Given new "CreateMonitor" request
Expand Down Expand Up @@ -146,7 +157,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 {"options": {"escalation_message": "none", "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": [], "notify_no_data": false, "on_missing_data": "default", "renotify_interval": null, "renotify_occurrences": null, "renotify_statuses": ["alert"], "scheduling_options": {"evaluation_window": {"day_starts": "04:00", "hour_starts": 0, "month_starts": 1}}, "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"}, "data_source": "rum", "group_by": [{"facet": "status", "limit": 10, "sort": {"aggregation": "avg", "order": "desc"}}], "indexes": ["days-3", "days-7"], "name": "query_errors", "search": {"query": "service:query"}}]}, "restricted_roles": [], "tags": [], "type": "query alert"}
And body with value {"options": {"escalation_message": "none", "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": [], "notify_no_data": false, "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}}, "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"}, "data_source": "rum", "group_by": [{"facet": "status", "limit": 10, "sort": {"aggregation": "avg", "order": "desc"}}], "indexes": ["days-3", "days-7"], "name": "query_errors", "search": {"query": "service:query"}}]}, "restricted_roles": [], "tags": [], "type": "query alert"}
When the request is sent
Then the response status is 400 Bad Request

Expand Down

0 comments on commit f079744

Please sign in to comment.