diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 809d974e93..18e4572760 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -76024,6 +76024,45 @@ components: required: - data type: object + IssueSnoozeRequest: + description: Snooze issue request payload. + properties: + data: + $ref: "#/components/schemas/IssueSnoozeRequestData" + required: + - data + type: object + IssueSnoozeRequestData: + description: Snooze issue request. + properties: + attributes: + $ref: "#/components/schemas/IssueSnoozeRequestDataAttributes" + id: + description: Issue identifier. + example: "c1726a66-1f64-11ee-b338-da7ad0900002" + type: string + type: + $ref: "#/components/schemas/IssueSnoozeRequestDataType" + required: + - id + - type + - attributes + type: object + IssueSnoozeRequestDataAttributes: + description: Object describing an issue snooze request. + properties: + condition: + $ref: "#/components/schemas/IssueWatchCondition" + required: + - condition + type: object + IssueSnoozeRequestDataType: + description: Type of the object. + enum: ["error_tracking_issue"] + example: "error_tracking_issue" + type: string + x-enum-varnames: + - ERROR_TRACKING_ISSUE IssueState: description: State of the issue enum: @@ -76288,18 +76327,29 @@ components: `ELAPSED_TIME` uses `duration`, and `ANY` and `ALL` use `operands`. properties: duration: - description: Time that must elapse before the condition is met, as a Go duration string. + description: |- + Time that must elapse from when the watch started, as a Go duration string, such as `24h`, or `168h` for a + week. example: "168h0m0s" type: string kind: $ref: "#/components/schemas/IssueWatchConditionKind" operands: description: Nested conditions combined by `ANY` or `ALL`. + example: + - duration: 168h + kind: ELAPSED_TIME + - kind: OCCURRENCES + threshold: 100 items: $ref: "#/components/schemas/IssueWatchCondition" type: array projection: - description: Attributes whose distinct values are counted for `CARDINALITY`. + description: |- + Attributes whose distinct values `CARDINALITY` counts, in search syntax: `@` for attributes, such as + `@usr.id` or `@account.id`, and no prefix for tags and reserved fields, such as `org_id` or `service`. + Only use attributes that the issue's errors carry: a condition on an attribute they don't carry is never + met. example: ["@usr.id"] items: description: Attribute path. @@ -76307,7 +76357,9 @@ components: type: string type: array threshold: - description: Number of occurrences, or of distinct values for `CARDINALITY`, that triggers the condition. + description: |- + Number of new occurrences, or of distinct values for `CARDINALITY`, that meets the condition, counted from + when the watch started. example: 100 format: int64 type: integer @@ -182656,6 +182708,112 @@ paths: - Error Tracking x-unstable: |- **Note**: This endpoint is in preview and is subject to change. + /api/v2/error-tracking/issues/{issue_id}/snooze: + post: + description: |- + Snooze an issue by `issue_id`: move it to `IGNORED` until a condition is met, then back to `OPEN`. + The condition can be a number of occurrences, a number of distinct values of an attribute such as `@usr.id`, + an elapsed time, or any or all of several conditions. + Snoozing an issue that is already snoozed replaces its snooze. Updating the state of the issue with + `UpdateIssueState` cancels the snooze. + The response includes the watch that reopens the issue. + operationId: SnoozeIssue + parameters: + - $ref: "#/components/parameters/IssueIDPathParameter" + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + condition: + kind: ANY + operands: + - duration: 168h + kind: ELAPSED_TIME + - kind: OCCURRENCES + threshold: 100 + id: c1726a66-1f64-11ee-b338-da7ad0900002 + type: error_tracking_issue + schema: + $ref: "#/components/schemas/IssueSnoozeRequest" + description: Snooze issue request payload. + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + error_message: "object of type 'NoneType' has no len()" + error_type: builtins.TypeError + service: test-service + state: IGNORED + id: c1726a66-1f64-11ee-b338-da7ad0900002 + relationships: + watches: + data: + - id: e7a1c3b5-2d4f-4a6b-8c9d-0e1f2a3b4c5d + type: error_tracking_issue_watch + type: issue + included: + - attributes: + action: + from: IGNORED + kind: CHANGE_ISSUE_STATE + to: OPEN + condition: + kind: ANY + operands: + - duration: 168h0m0s + kind: ELAPSED_TIME + - kind: OCCURRENCES + threshold: 100 + started_at: "2025-01-01T00:00:00Z" + status: ACTIVE + id: e7a1c3b5-2d4f-4a6b-8c9d-0e1f2a3b4c5d + type: error_tracking_issue_watch + schema: + $ref: "#/components/schemas/IssueResponse" + description: OK + "400": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Bad Request + "401": + $ref: "#/components/responses/UnauthorizedResponse" + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Forbidden + "404": + content: + application/json: + schema: + $ref: "#/components/schemas/JSONAPIErrorResponse" + description: Not Found + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - error_tracking_read + - error_tracking_write + summary: Snooze an issue + tags: + - Error Tracking + x-unstable: |- + **Note**: This endpoint is in preview and is subject to change. /api/v2/error-tracking/issues/{issue_id}/state: put: description: Update the state of an issue by `issue_id`. Use this endpoint to move an issue between states such as `OPEN`, `RESOLVED`, or `IGNORED`. diff --git a/examples/v2/error-tracking/SnoozeIssue.py b/examples/v2/error-tracking/SnoozeIssue.py new file mode 100644 index 0000000000..6a2aeb1dc9 --- /dev/null +++ b/examples/v2/error-tracking/SnoozeIssue.py @@ -0,0 +1,38 @@ +""" +Snooze an issue returns "OK" response +""" + +from os import environ +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.error_tracking_api import ErrorTrackingApi +from datadog_api_client.v2.model.issue_snooze_request import IssueSnoozeRequest +from datadog_api_client.v2.model.issue_snooze_request_data import IssueSnoozeRequestData +from datadog_api_client.v2.model.issue_snooze_request_data_attributes import IssueSnoozeRequestDataAttributes +from datadog_api_client.v2.model.issue_snooze_request_data_type import IssueSnoozeRequestDataType +from datadog_api_client.v2.model.issue_watch_condition import IssueWatchCondition +from datadog_api_client.v2.model.issue_watch_condition_kind import IssueWatchConditionKind + +# there is a valid "issue" in the system +ISSUE_ID = environ["ISSUE_ID"] + +body = IssueSnoozeRequest( + data=IssueSnoozeRequestData( + attributes=IssueSnoozeRequestDataAttributes( + condition=IssueWatchCondition( + kind=IssueWatchConditionKind.ELAPSED_TIME, + duration="168h", + ), + ), + id=ISSUE_ID, + type=IssueSnoozeRequestDataType.ERROR_TRACKING_ISSUE, + ), +) + +configuration = Configuration() +configuration.access_token = environ["DD_BEARER_TOKEN"] +configuration.unstable_operations["snooze_issue"] = True +with ApiClient(configuration) as api_client: + api_instance = ErrorTrackingApi(api_client) + response = api_instance.snooze_issue(issue_id=ISSUE_ID, body=body) + + print(response) diff --git a/src/datadog_api_client/configuration.py b/src/datadog_api_client/configuration.py index 0c981e0f68..7d8f36b32b 100644 --- a/src/datadog_api_client/configuration.py +++ b/src/datadog_api_client/configuration.py @@ -606,6 +606,7 @@ def __init__( "v2.update_deployment_gate": False, "v2.update_deployment_rule": False, "v2.get_issue_impact": False, + "v2.snooze_issue": False, "v2.get_eudm_device": False, "v2.get_eudm_devices": False, "v2.clone_form": False, diff --git a/src/datadog_api_client/v2/api/error_tracking_api.py b/src/datadog_api_client/v2/api/error_tracking_api.py index 85c5e84b02..f631e17b53 100644 --- a/src/datadog_api_client/v2/api/error_tracking_api.py +++ b/src/datadog_api_client/v2/api/error_tracking_api.py @@ -19,6 +19,7 @@ from datadog_api_client.v2.model.issue_sample_bias import IssueSampleBias from datadog_api_client.v2.model.issue_update_assignee_request import IssueUpdateAssigneeRequest from datadog_api_client.v2.model.issue_impact_response import IssueImpactResponse +from datadog_api_client.v2.model.issue_snooze_request import IssueSnoozeRequest from datadog_api_client.v2.model.issue_update_state_request import IssueUpdateStateRequest @@ -151,6 +152,32 @@ def __init__(self, api_client=None): api_client=api_client, ) + self._snooze_issue_endpoint = _Endpoint( + settings={ + "response_type": (IssueResponse,), + "auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"], + "endpoint_path": "/api/v2/error-tracking/issues/{issue_id}/snooze", + "operation_id": "snooze_issue", + "http_method": "POST", + "version": "v2", + }, + params_map={ + "issue_id": { + "required": True, + "openapi_types": (str,), + "attribute": "issue_id", + "location": "path", + }, + "body": { + "required": True, + "openapi_types": (IssueSnoozeRequest,), + "location": "body", + }, + }, + headers_map={"accept": ["application/json"], "content_type": ["application/json"]}, + api_client=api_client, + ) + self._update_issue_assignee_endpoint = _Endpoint( settings={ "response_type": (IssueResponse,), @@ -309,6 +336,33 @@ def search_issues( return self._search_issues_endpoint.call_with_http_info(**kwargs) + def snooze_issue( + self, + issue_id: str, + body: IssueSnoozeRequest, + ) -> IssueResponse: + """Snooze an issue. + + Snooze an issue by ``issue_id`` : move it to ``IGNORED`` until a condition is met, then back to ``OPEN``. + The condition can be a number of occurrences, a number of distinct values of an attribute such as ``@usr.id`` , + an elapsed time, or any or all of several conditions. + Snoozing an issue that is already snoozed replaces its snooze. Updating the state of the issue with + ``UpdateIssueState`` cancels the snooze. + The response includes the watch that reopens the issue. + + :param issue_id: The identifier of the issue. + :type issue_id: str + :param body: Snooze issue request payload. + :type body: IssueSnoozeRequest + :rtype: IssueResponse + """ + kwargs: Dict[str, Any] = {} + kwargs["issue_id"] = issue_id + + kwargs["body"] = body + + return self._snooze_issue_endpoint.call_with_http_info(**kwargs) + def update_issue_assignee( self, issue_id: str, diff --git a/src/datadog_api_client/v2/model/issue_snooze_request.py b/src/datadog_api_client/v2/model/issue_snooze_request.py new file mode 100644 index 0000000000..715bbf977c --- /dev/null +++ b/src/datadog_api_client/v2/model/issue_snooze_request.py @@ -0,0 +1,40 @@ +# 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 TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.issue_snooze_request_data import IssueSnoozeRequestData + + +class IssueSnoozeRequest(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.issue_snooze_request_data import IssueSnoozeRequestData + + return { + "data": (IssueSnoozeRequestData,), + } + + attribute_map = { + "data": "data", + } + + def __init__(self_, data: IssueSnoozeRequestData, **kwargs): + """ + Snooze issue request payload. + + :param data: Snooze issue request. + :type data: IssueSnoozeRequestData + """ + super().__init__(kwargs) + + self_.data = data diff --git a/src/datadog_api_client/v2/model/issue_snooze_request_data.py b/src/datadog_api_client/v2/model/issue_snooze_request_data.py new file mode 100644 index 0000000000..301f273fd1 --- /dev/null +++ b/src/datadog_api_client/v2/model/issue_snooze_request_data.py @@ -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 TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.issue_snooze_request_data_attributes import IssueSnoozeRequestDataAttributes + from datadog_api_client.v2.model.issue_snooze_request_data_type import IssueSnoozeRequestDataType + + +class IssueSnoozeRequestData(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.issue_snooze_request_data_attributes import IssueSnoozeRequestDataAttributes + from datadog_api_client.v2.model.issue_snooze_request_data_type import IssueSnoozeRequestDataType + + return { + "attributes": (IssueSnoozeRequestDataAttributes,), + "id": (str,), + "type": (IssueSnoozeRequestDataType,), + } + + attribute_map = { + "attributes": "attributes", + "id": "id", + "type": "type", + } + + def __init__( + self_, attributes: IssueSnoozeRequestDataAttributes, id: str, type: IssueSnoozeRequestDataType, **kwargs + ): + """ + Snooze issue request. + + :param attributes: Object describing an issue snooze request. + :type attributes: IssueSnoozeRequestDataAttributes + + :param id: Issue identifier. + :type id: str + + :param type: Type of the object. + :type type: IssueSnoozeRequestDataType + """ + super().__init__(kwargs) + + self_.attributes = attributes + self_.id = id + self_.type = type diff --git a/src/datadog_api_client/v2/model/issue_snooze_request_data_attributes.py b/src/datadog_api_client/v2/model/issue_snooze_request_data_attributes.py new file mode 100644 index 0000000000..88c7011d3f --- /dev/null +++ b/src/datadog_api_client/v2/model/issue_snooze_request_data_attributes.py @@ -0,0 +1,42 @@ +# 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 TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, +) + + +if TYPE_CHECKING: + from datadog_api_client.v2.model.issue_watch_condition import IssueWatchCondition + + +class IssueSnoozeRequestDataAttributes(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.issue_watch_condition import IssueWatchCondition + + return { + "condition": (IssueWatchCondition,), + } + + attribute_map = { + "condition": "condition", + } + + def __init__(self_, condition: IssueWatchCondition, **kwargs): + """ + Object describing an issue snooze request. + + :param condition: Condition that triggers the watch action. The fields that are set depend on ``kind`` : + ``OCCURRENCES`` uses ``threshold`` , ``CARDINALITY`` uses ``threshold`` and ``projection`` , + ``ELAPSED_TIME`` uses ``duration`` , and ``ANY`` and ``ALL`` use ``operands``. + :type condition: IssueWatchCondition + """ + super().__init__(kwargs) + + self_.condition = condition diff --git a/src/datadog_api_client/v2/model/issue_snooze_request_data_type.py b/src/datadog_api_client/v2/model/issue_snooze_request_data_type.py new file mode 100644 index 0000000000..7cd85ec865 --- /dev/null +++ b/src/datadog_api_client/v2/model/issue_snooze_request_data_type.py @@ -0,0 +1,35 @@ +# 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 datadog_api_client.model_utils import ( + ModelSimple, + cached_property, +) + +from typing import ClassVar + + +class IssueSnoozeRequestDataType(ModelSimple): + """ + Type of the object. + + :param value: If omitted defaults to "error_tracking_issue". Must be one of ["error_tracking_issue"]. + :type value: str + """ + + allowed_values = { + "error_tracking_issue", + } + ERROR_TRACKING_ISSUE: ClassVar["IssueSnoozeRequestDataType"] + + @cached_property + def openapi_types(_): + return { + "value": (str,), + } + + +IssueSnoozeRequestDataType.ERROR_TRACKING_ISSUE = IssueSnoozeRequestDataType("error_tracking_issue") diff --git a/src/datadog_api_client/v2/model/issue_watch_condition.py b/src/datadog_api_client/v2/model/issue_watch_condition.py index eae67dc2b9..21a372172e 100644 --- a/src/datadog_api_client/v2/model/issue_watch_condition.py +++ b/src/datadog_api_client/v2/model/issue_watch_condition.py @@ -52,7 +52,8 @@ def __init__( ``OCCURRENCES`` uses ``threshold`` , ``CARDINALITY`` uses ``threshold`` and ``projection`` , ``ELAPSED_TIME`` uses ``duration`` , and ``ANY`` and ``ALL`` use ``operands``. - :param duration: Time that must elapse before the condition is met, as a Go duration string. + :param duration: Time that must elapse from when the watch started, as a Go duration string, such as ``24h`` , or ``168h`` for a + week. :type duration: str, optional :param kind: Kind of watch condition. @@ -61,10 +62,14 @@ def __init__( :param operands: Nested conditions combined by ``ANY`` or ``ALL``. :type operands: [IssueWatchCondition], optional - :param projection: Attributes whose distinct values are counted for ``CARDINALITY``. + :param projection: Attributes whose distinct values ``CARDINALITY`` counts, in search syntax: ``@`` for attributes, such as + ``@usr.id`` or ``@account.id`` , and no prefix for tags and reserved fields, such as ``org_id`` or ``service``. + Only use attributes that the issue's errors carry: a condition on an attribute they don't carry is never + met. :type projection: [str], optional - :param threshold: Number of occurrences, or of distinct values for ``CARDINALITY`` , that triggers the condition. + :param threshold: Number of new occurrences, or of distinct values for ``CARDINALITY`` , that meets the condition, counted from + when the watch started. :type threshold: int, optional """ if duration is not unset: diff --git a/src/datadog_api_client/v2/models/__init__.py b/src/datadog_api_client/v2/models/__init__.py index 8b3adfdfbc..f64e232c78 100644 --- a/src/datadog_api_client/v2/models/__init__.py +++ b/src/datadog_api_client/v2/models/__init__.py @@ -5964,6 +5964,10 @@ from datadog_api_client.v2.model.issue_sample_stack_frame import IssueSampleStackFrame from datadog_api_client.v2.model.issue_sample_type import IssueSampleType from datadog_api_client.v2.model.issue_samples_relationship import IssueSamplesRelationship +from datadog_api_client.v2.model.issue_snooze_request import IssueSnoozeRequest +from datadog_api_client.v2.model.issue_snooze_request_data import IssueSnoozeRequestData +from datadog_api_client.v2.model.issue_snooze_request_data_attributes import IssueSnoozeRequestDataAttributes +from datadog_api_client.v2.model.issue_snooze_request_data_type import IssueSnoozeRequestDataType from datadog_api_client.v2.model.issue_state import IssueState from datadog_api_client.v2.model.issue_team import IssueTeam from datadog_api_client.v2.model.issue_team_attributes import IssueTeamAttributes @@ -18194,6 +18198,10 @@ "IssueSampleStackFrame", "IssueSampleType", "IssueSamplesRelationship", + "IssueSnoozeRequest", + "IssueSnoozeRequestData", + "IssueSnoozeRequestDataAttributes", + "IssueSnoozeRequestDataType", "IssueState", "IssueTeam", "IssueTeamAttributes", diff --git a/tests/v2/features/error_tracking.feature b/tests/v2/features/error_tracking.feature index 468c9b4d8e..7722f8e84c 100644 --- a/tests/v2/features/error_tracking.feature +++ b/tests/v2/features/error_tracking.feature @@ -124,6 +124,38 @@ Feature: Error Tracking When the request is sent Then the response status is 200 OK + @skip @team:ddoghq/error-tracking + Scenario: Snooze an issue returns "Bad Request" response + Given operation "SnoozeIssue" enabled + And new "SnoozeIssue" request + And there is a valid "issue" in the system + And request contains "issue_id" parameter from "issue.id" + And body with value {"data": {"attributes": {"condition": {"kind": "OCCURRENCES"}}, "id": "{{ issue.id }}", "type": "error_tracking_issue"}} + When the request is sent + Then the response status is 400 Bad Request + + @skip @team:ddoghq/error-tracking + Scenario: Snooze an issue returns "Not Found" response + Given operation "SnoozeIssue" enabled + And new "SnoozeIssue" request + And request contains "issue_id" parameter with value "67d80aa3-36ff-44b9-a694-c501a7591737" + And body with value {"data": {"attributes": {"condition": {"kind": "ELAPSED_TIME", "duration": "168h"}}, "id": "67d80aa3-36ff-44b9-a694-c501a7591737", "type": "error_tracking_issue"}} + When the request is sent + Then the response status is 404 Not Found + + @skip @team:ddoghq/error-tracking + Scenario: Snooze an issue returns "OK" response + Given operation "SnoozeIssue" enabled + And new "SnoozeIssue" request + And there is a valid "issue" in the system + And request contains "issue_id" parameter from "issue.id" + And body with value {"data": {"attributes": {"condition": {"kind": "ELAPSED_TIME", "duration": "168h"}}, "id": "{{ issue.id }}", "type": "error_tracking_issue"}} + When the request is sent + Then the response status is 200 OK + And the response "data.id" is equal to "{{ issue.id }}" + And the response "data.attributes.state" is equal to "IGNORED" + And the response "data.relationships" has field "watches" + @team:ddoghq/error-tracking Scenario: Update the assignee of an issue returns "Bad Request" response Given new "UpdateIssueAssignee" request diff --git a/tests/v2/features/undo.json b/tests/v2/features/undo.json index 735b21bfcc..0d9b33aa46 100644 --- a/tests/v2/features/undo.json +++ b/tests/v2/features/undo.json @@ -2789,6 +2789,23 @@ "type": "safe" } }, + "SnoozeIssue": { + "tag": "Error Tracking", + "undo": { + "operationId": "UpdateIssueState", + "parameters": [ + { + "name": "issue_id", + "source": "data.id" + }, + { + "name": "body", + "template": "{\"data\": {\"type\": \"error_tracking_issue\", \"id\": \"{{ data.id }}\", \"attributes\": {\"state\": \"OPEN\"}}}" + } + ], + "type": "unsafe" + } + }, "UpdateIssueState": { "tag": "Error Tracking", "undo": {