diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index cc175b4553..28a5bdd897 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -28815,12 +28815,12 @@ components: - "department:engineering" - "region:us-east-1" env: "production" - finished_at: 1693491984000000000 + finished_at: "2023-08-31T14:26:24Z" git: commit_sha: "66adc9350f2cc9b250b69abddab733dd55e1a588" repository_id: "github.com/organization/example-repository" service: "shopist" - started_at: 1693491974000000000 + started_at: "2023-08-31T14:26:14Z" team: "backend" version: "v1.12.07" id: "4242fcdd31586083" @@ -28844,10 +28844,10 @@ components: example: production type: string finished_at: - description: Unix timestamp when the deployment finished. - example: 1693491984000000000 - format: int64 - type: integer + description: The time when the deployment finished. + example: "2023-08-31T14:26:24Z" + format: date-time + type: string git: $ref: "#/components/schemas/DORAGitInfoResponse" service: @@ -28855,10 +28855,10 @@ components: example: shopist type: string started_at: - description: Unix timestamp when the deployment started. - example: 1693491974000000000 - format: int64 - type: integer + description: The time when the deployment started. + example: "2023-08-31T14:26:14Z" + format: date-time + type: string team: description: Name of the team owning the deployed service. example: backend @@ -28870,7 +28870,6 @@ components: required: - service - started_at - - finished_at type: object DORADeploymentPatchRemediation: description: Remediation details for the deployment. Optional, but required to calculate failed deployment recovery time. @@ -29048,12 +29047,12 @@ components: - "department:engineering" - "region:us-east-1" env: "production" - finished_at: 1693491984000000000 + finished_at: "2023-08-31T14:26:24Z" git: commit_sha: "66adc9350f2cc9b250b69abddab733dd55e1a588" repository_id: "github.com/organization/example-repository" service: "shopist" - started_at: 1693491974000000000 + started_at: "2023-08-31T14:26:14Z" team: "backend" version: "v1.12.07" id: "4242fcdd31586083" @@ -29063,12 +29062,12 @@ components: - "language:go" - "department:platform" env: "production" - finished_at: 1693492084000000000 + finished_at: "2023-08-31T14:28:04Z" git: commit_sha: "77bdc9350f2cc9b250b69abddab733dd55e1a599" repository_id: "github.com/organization/api-service" service: "api-service" - started_at: 1693492074000000000 + started_at: "2023-08-31T14:27:54Z" team: "backend" version: "v2.1.0" id: "4242fcdd31586084" @@ -29190,12 +29189,12 @@ components: - "incident_type:database" - "department:engineering" env: "production" - finished_at: 1693492274000000000 + finished_at: "2023-08-31T14:31:14Z" name: "Database outage" services: - "shopist" severity: "SEV-1" - started_at: 1693492174000000000 + started_at: "2023-08-31T14:29:34Z" team: "backend" id: "4242fcdd31586085" type: "dora_incident" @@ -29204,13 +29203,13 @@ components: - "incident_type:service_down" - "department:platform" env: "production" - finished_at: 1693492474000000000 + finished_at: "2023-08-31T14:34:34Z" name: "API service outage" services: - "api-service" - "payment-service" severity: "SEV-2" - started_at: 1693492374000000000 + started_at: "2023-08-31T14:32:54Z" team: "backend" id: "4242fcdd31586086" type: "dora_incident" @@ -29251,7 +29250,7 @@ components: - "incident_type:database" - "department:engineering" env: "production" - finished_at: 1693492274000000000 + finished_at: "2023-08-31T14:31:14Z" git: commit_sha: "66adc9350f2cc9b250b69abddab733dd55e1a588" repository_url: "https://github.com/organization/example-repository" @@ -29259,7 +29258,7 @@ components: services: - "shopist" severity: "SEV-1" - started_at: 1693492174000000000 + started_at: "2023-08-31T14:29:34Z" team: "backend" id: "4242fcdd31586085" type: "dora_incident" @@ -29282,10 +29281,10 @@ components: example: production type: string finished_at: - description: Unix timestamp when the incident finished. - example: 1693491984000000000 - format: int64 - type: integer + description: The time when the incident finished. + example: "2023-08-31T14:26:24Z" + format: date-time + type: string git: $ref: "#/components/schemas/DORAGitInfo" name: @@ -29304,10 +29303,10 @@ components: example: SEV-1 type: string started_at: - description: Unix timestamp when the incident started. - example: 1693491974000000000 - format: int64 - type: integer + description: The time when the incident started. + example: "2023-08-31T14:26:14Z" + format: date-time + type: string team: description: Name of the team owning the services impacted. example: backend @@ -29316,8 +29315,6 @@ components: description: Version to correlate with APM Deployment Tracking. example: v1.12.07 type: string - required: - - started_at type: object DORAListDeploymentsRequest: description: Request to get a list of deployments. @@ -132589,9 +132586,9 @@ paths: data: - attributes: env: production - finished_at: 1693491984000000000 + finished_at: "2023-08-31T14:26:24Z" service: test-service - started_at: 1693491974000000000 + started_at: "2023-08-31T14:26:14Z" team: backend id: abc-123 type: dora_deployment @@ -132640,9 +132637,9 @@ paths: data: attributes: env: production - finished_at: 1693491984000000000 + finished_at: "2023-08-31T14:26:24Z" service: test-service - started_at: 1693491974000000000 + started_at: "2023-08-31T14:26:14Z" team: backend id: abc-123 type: dora_deployment @@ -132863,7 +132860,7 @@ paths: services: - test-service severity: SEV-1 - started_at: 1693492174000000000 + started_at: "2023-08-31T14:29:34Z" team: backend id: abc-123 type: dora_failure @@ -132916,7 +132913,7 @@ paths: services: - test-service severity: SEV-1 - started_at: 1693492174000000000 + started_at: "2023-08-31T14:29:34Z" team: backend id: abc-123 type: dora_failure diff --git a/examples/v2/dora-metrics/ListDORADeployments_1654201709.py b/examples/v2/dora-metrics/ListDORADeployments_1654201709.py new file mode 100644 index 0000000000..f722dbbd20 --- /dev/null +++ b/examples/v2/dora-metrics/ListDORADeployments_1654201709.py @@ -0,0 +1,29 @@ +""" +Get a list of deployment events returns deployments with date-time timestamps +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.dora_metrics_api import DORAMetricsApi +from datadog_api_client.v2.model.dora_list_deployments_request import DORAListDeploymentsRequest +from datadog_api_client.v2.model.dora_list_deployments_request_attributes import DORAListDeploymentsRequestAttributes +from datadog_api_client.v2.model.dora_list_deployments_request_data import DORAListDeploymentsRequestData +from datadog_api_client.v2.model.dora_list_deployments_request_data_type import DORAListDeploymentsRequestDataType +from datetime import datetime +from dateutil.tz import tzutc + +body = DORAListDeploymentsRequest( + data=DORAListDeploymentsRequestData( + attributes=DORAListDeploymentsRequestAttributes( + _from=datetime(2023, 8, 31, 0, 0, tzinfo=tzutc()), + to=datetime(2023, 9, 1, 0, 0, tzinfo=tzutc()), + ), + type=DORAListDeploymentsRequestDataType.DORA_DEPLOYMENTS_LIST_REQUEST, + ), +) + +configuration = Configuration() +with ApiClient(configuration) as api_client: + api_instance = DORAMetricsApi(api_client) + response = api_instance.list_dora_deployments(body=body) + + print(response) diff --git a/src/datadog_api_client/v2/model/dora_deployment_object_attributes.py b/src/datadog_api_client/v2/model/dora_deployment_object_attributes.py index a2043532f7..4afe9b1f60 100644 --- a/src/datadog_api_client/v2/model/dora_deployment_object_attributes.py +++ b/src/datadog_api_client/v2/model/dora_deployment_object_attributes.py @@ -8,6 +8,7 @@ from datadog_api_client.model_utils import ( ModelNormal, cached_property, + datetime, none_type, unset, UnsetType, @@ -26,10 +27,10 @@ def openapi_types(_): return { "custom_tags": ([str],), "env": (str,), - "finished_at": (int,), + "finished_at": (datetime,), "git": (DORAGitInfoResponse,), "service": (str,), - "started_at": (int,), + "started_at": (datetime,), "team": (str,), "version": (str,), } @@ -47,11 +48,11 @@ def openapi_types(_): def __init__( self_, - finished_at: int, service: str, - started_at: int, + started_at: datetime, custom_tags: Union[List[str], none_type, UnsetType] = unset, env: Union[str, UnsetType] = unset, + finished_at: Union[datetime, UnsetType] = unset, git: Union[DORAGitInfoResponse, UnsetType] = unset, team: Union[str, UnsetType] = unset, version: Union[str, UnsetType] = unset, @@ -66,8 +67,8 @@ def __init__( :param env: Environment name to where the service was deployed. :type env: str, optional - :param finished_at: Unix timestamp when the deployment finished. - :type finished_at: int + :param finished_at: The time when the deployment finished. + :type finished_at: datetime, optional :param git: Git info returned by DORA Metrics events. :type git: DORAGitInfoResponse, optional @@ -75,8 +76,8 @@ def __init__( :param service: Service name. :type service: str - :param started_at: Unix timestamp when the deployment started. - :type started_at: int + :param started_at: The time when the deployment started. + :type started_at: datetime :param team: Name of the team owning the deployed service. :type team: str, optional @@ -88,6 +89,8 @@ def __init__( kwargs["custom_tags"] = custom_tags if env is not unset: kwargs["env"] = env + if finished_at is not unset: + kwargs["finished_at"] = finished_at if git is not unset: kwargs["git"] = git if team is not unset: @@ -96,6 +99,5 @@ def __init__( kwargs["version"] = version super().__init__(kwargs) - self_.finished_at = finished_at self_.service = service self_.started_at = started_at diff --git a/src/datadog_api_client/v2/model/dora_incident_object_attributes.py b/src/datadog_api_client/v2/model/dora_incident_object_attributes.py index 1e302f6f5e..431f4e31f7 100644 --- a/src/datadog_api_client/v2/model/dora_incident_object_attributes.py +++ b/src/datadog_api_client/v2/model/dora_incident_object_attributes.py @@ -8,6 +8,7 @@ from datadog_api_client.model_utils import ( ModelNormal, cached_property, + datetime, none_type, unset, UnsetType, @@ -26,12 +27,12 @@ def openapi_types(_): return { "custom_tags": ([str],), "env": (str,), - "finished_at": (int,), + "finished_at": (datetime,), "git": (DORAGitInfo,), "name": (str,), "services": ([str],), "severity": (str,), - "started_at": (int,), + "started_at": (datetime,), "team": (str,), "version": (str,), } @@ -51,14 +52,14 @@ def openapi_types(_): def __init__( self_, - started_at: int, custom_tags: Union[List[str], none_type, UnsetType] = unset, env: Union[str, UnsetType] = unset, - finished_at: Union[int, UnsetType] = unset, + finished_at: Union[datetime, UnsetType] = unset, git: Union[DORAGitInfo, UnsetType] = unset, name: Union[str, UnsetType] = unset, services: Union[List[str], UnsetType] = unset, severity: Union[str, UnsetType] = unset, + started_at: Union[datetime, UnsetType] = unset, team: Union[str, UnsetType] = unset, version: Union[str, UnsetType] = unset, **kwargs, @@ -72,8 +73,8 @@ def __init__( :param env: Environment name that was impacted by the incident. :type env: str, optional - :param finished_at: Unix timestamp when the incident finished. - :type finished_at: int, optional + :param finished_at: The time when the incident finished. + :type finished_at: datetime, optional :param git: Git info for DORA Metrics events. :type git: DORAGitInfo, optional @@ -87,8 +88,8 @@ def __init__( :param severity: Incident severity. :type severity: str, optional - :param started_at: Unix timestamp when the incident started. - :type started_at: int + :param started_at: The time when the incident started. + :type started_at: datetime, optional :param team: Name of the team owning the services impacted. :type team: str, optional @@ -110,10 +111,10 @@ def __init__( kwargs["services"] = services if severity is not unset: kwargs["severity"] = severity + if started_at is not unset: + kwargs["started_at"] = started_at if team is not unset: kwargs["team"] = team if version is not unset: kwargs["version"] = version super().__init__(kwargs) - - self_.started_at = started_at diff --git a/tests/conftest.py b/tests/conftest.py index 5a67143b4b..3b2e477dc2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -319,12 +319,27 @@ def pytest_recording_configure(config, vcr): from vcr import matchers from vcr.util import read_body - is_text_json = matchers._header_checker("text/json") - transformer = matchers._transform_json + def is_json(headers): + return matchers._header_checker("text/json")(headers) or matchers._header_checker("application/json")(headers) + + def normalize_utc_offset(value): + # Cassettes record UTC datetimes as "...Z", but the client serializes + # tz-aware datetimes via datetime.isoformat() as "...+00:00". The two + # denote the same instant, so treat them as equal when matching bodies. + if isinstance(value, dict): + return {key: normalize_utc_offset(val) for key, val in value.items()} + if isinstance(value, list): + return [normalize_utc_offset(item) for item in value] + if isinstance(value, str) and value.endswith("+00:00"): + return value[:-6] + "Z" + return value + + def transform(request): + return normalize_utc_offset(matchers._transform_json(read_body(request))) def body(r1, r2): - if is_text_json(r1.headers) and is_text_json(r2.headers): - assert transformer(read_body(r1)) == transformer(read_body(r2)) + if is_json(r1.headers) and is_json(r2.headers): + assert transform(r1) == transform(r2) else: matchers.body(r1, r2) diff --git a/tests/v2/cassettes/test_scenarios/test_get_a_list_of_deployment_events_returns_deployments_with_datetime_timestamps.frozen b/tests/v2/cassettes/test_scenarios/test_get_a_list_of_deployment_events_returns_deployments_with_datetime_timestamps.frozen new file mode 100644 index 0000000000..4f30c83806 --- /dev/null +++ b/tests/v2/cassettes/test_scenarios/test_get_a_list_of_deployment_events_returns_deployments_with_datetime_timestamps.frozen @@ -0,0 +1 @@ +2023-08-31T14:26:14.000Z \ No newline at end of file diff --git a/tests/v2/cassettes/test_scenarios/test_get_a_list_of_deployment_events_returns_deployments_with_datetime_timestamps.yaml b/tests/v2/cassettes/test_scenarios/test_get_a_list_of_deployment_events_returns_deployments_with_datetime_timestamps.yaml new file mode 100644 index 0000000000..809cf501c4 --- /dev/null +++ b/tests/v2/cassettes/test_scenarios/test_get_a_list_of_deployment_events_returns_deployments_with_datetime_timestamps.yaml @@ -0,0 +1,20 @@ +interactions: +- request: + body: '{"data":{"attributes":{"from":"2023-08-31T00:00:00Z","to":"2023-09-01T00:00:00Z"},"type":"dora_deployments_list_request"}}' + headers: + accept: + - application/json + content-type: + - application/json + method: POST + uri: https://api.datadoghq.com/api/v2/dora/deployments + response: + body: + string: '{"data":[{"id":"abc-123","type":"dora_deployment","attributes":{"service":"shopist","started_at":"2023-08-31T14:26:14Z","finished_at":"2023-08-31T14:26:24Z","env":"production","team":"backend","version":"v1.12.07"}}]}' + headers: + content-type: + - application/vnd.api+json + status: + code: 200 + message: OK +version: 1 diff --git a/tests/v2/features/dora_metrics.feature b/tests/v2/features/dora_metrics.feature index 768442f37f..d0dc8943ad 100644 --- a/tests/v2/features/dora_metrics.feature +++ b/tests/v2/features/dora_metrics.feature @@ -88,6 +88,18 @@ Feature: DORA Metrics When the request is sent Then the response status is 200 OK + @replay-only @team:DataDog/ci-app-backend + Scenario: Get a list of deployment events returns deployments with date-time timestamps + Given a valid "appKeyAuth" key in the system + And new "ListDORADeployments" request + And body with value {"data": {"attributes": {"from": "2023-08-31T00:00:00Z", "to": "2023-09-01T00:00:00Z"}, "type": "dora_deployments_list_request"}} + When the request is sent + Then the response status is 200 OK + And the response "data" has length 1 + And the response "data[0].type" is equal to "dora_deployment" + And the response "data[0].attributes" has field "started_at" + And the response "data[0].attributes" has field "finished_at" + @team:DataDog/ci-app-backend Scenario: Get a list of failure events returns "Bad Request" response Given a valid "appKeyAuth" key in the system