diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index de9b3ca4f4..9bdd42fb61 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -346,6 +346,16 @@ components: required: true schema: type: string + DisableCorrections: + description: Whether to exclude correction windows from the SLO status calculation. + Defaults to false. + in: query + name: disable_corrections + required: false + schema: + default: false + example: false + type: boolean EntityID: description: UUID or Entity Ref. in: path @@ -457,6 +467,15 @@ components: required: false schema: $ref: '#/components/schemas/RelationType' + FromTimestamp: + description: The starting timestamp for the SLO status query in epoch seconds. + in: query + name: from_ts + required: true + schema: + example: 1690901870 + format: int64 + type: integer GCPSTSServiceAccountID: description: Your GCP STS enabled service account's unique ID. in: path @@ -1096,6 +1115,14 @@ components: required: false schema: type: boolean + SloID: + description: The ID of the SLO. + in: path + name: slo_id + required: true + schema: + example: 00000000-0000-0000-0000-000000000000 + type: string SpansMetricIDParameter: description: The name of the span-based metric. in: path @@ -1117,6 +1144,15 @@ components: required: true schema: type: string + ToTimestamp: + description: The ending timestamp for the SLO status query in epoch seconds. + in: query + name: to_ts + required: true + schema: + example: 1706803070 + format: int64 + type: integer UserID: description: The ID of the user. in: path @@ -45865,6 +45901,22 @@ components: from the other indexes type: string type: object + RawErrorBudgetRemaining: + description: The raw error budget remaining for the SLO. + properties: + unit: + description: The unit of the error budget (for example, `seconds`, `requests`). + example: seconds + type: string + value: + description: The numeric value of the remaining error budget. + example: 86400.5 + format: double + type: number + required: + - value + - unit + type: object ReadinessGate: description: Used to merge multiple branches into a single branch. properties: @@ -56388,6 +56440,70 @@ components: required: - attributes type: object + SloStatusData: + description: The data portion of the SLO status response. + properties: + attributes: + $ref: '#/components/schemas/SloStatusDataAttributes' + id: + description: The ID of the SLO. + example: 00000000-0000-0000-0000-000000000000 + type: string + type: + $ref: '#/components/schemas/SloStatusType' + required: + - id + - type + - attributes + type: object + SloStatusDataAttributes: + description: The attributes of the SLO status. + properties: + error_budget_remaining: + description: The percentage of error budget remaining. + example: 99.5 + format: double + type: number + raw_error_budget_remaining: + $ref: '#/components/schemas/RawErrorBudgetRemaining' + sli: + description: The current Service Level Indicator (SLI) value as a percentage. + example: 99.95 + format: double + type: number + span_precision: + description: The precision of the time span in seconds. + example: 2 + format: int64 + type: integer + state: + description: The current state of the SLO (for example, `breached`, `warning`, + `ok`). + example: ok + type: string + required: + - sli + - error_budget_remaining + - raw_error_budget_remaining + - state + - span_precision + type: object + SloStatusResponse: + description: The SLO status response. + properties: + data: + $ref: '#/components/schemas/SloStatusData' + required: + - data + type: object + SloStatusType: + description: The type of the SLO status resource. + enum: + - slo_status + example: slo_status + type: string + x-enum-varnames: + - SLO_STATUS SoftwareCatalogTriggerWrapper: description: Schema for a Software Catalog-based trigger. properties: @@ -92268,6 +92384,63 @@ paths: x-unstable: '**Note**: This feature is in private beta. To request access, use the request access form in the [Service Level Objectives](https://docs.datadoghq.com/service_management/service_level_objectives/#slo-csv-export) docs.' + /api/v2/slo/{slo_id}/status: + get: + description: 'Get the status of a Service Level Objective (SLO) for a given + time period. + + + This endpoint returns the current SLI value, error budget remaining, and other + status information for the specified SLO.' + operationId: GetSloStatus + parameters: + - $ref: '#/components/parameters/SloID' + - $ref: '#/components/parameters/FromTimestamp' + - $ref: '#/components/parameters/ToTimestamp' + - $ref: '#/components/parameters/DisableCorrections' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/SloStatusResponse' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Bad Request + '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: + - slos_read + summary: Get SLO status + tags: + - Service Level Objectives + x-permission: + operator: OR + permissions: + - slos_read + x-unstable: '**Note**: This endpoint is in public beta and it''s subject to + change. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' /api/v2/spa/recommendations/{service}: get: description: This endpoint is currently experimental and restricted to Datadog diff --git a/docs/datadog_api_client.v2.model.rst b/docs/datadog_api_client.v2.model.rst index aaf9797538..dde3c2c7ed 100644 --- a/docs/datadog_api_client.v2.model.rst +++ b/docs/datadog_api_client.v2.model.rst @@ -19562,6 +19562,13 @@ datadog\_api\_client.v2.model.query\_users\_request\_data\_type module :members: :show-inheritance: +datadog\_api\_client.v2.model.raw\_error\_budget\_remaining module +------------------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.raw_error_budget_remaining + :members: + :show-inheritance: + datadog\_api\_client.v2.model.readiness\_gate module ---------------------------------------------------- @@ -24602,6 +24609,34 @@ datadog\_api\_client.v2.model.slo\_report\_status\_get\_response\_data module :members: :show-inheritance: +datadog\_api\_client.v2.model.slo\_status\_data module +------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.slo_status_data + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.slo\_status\_data\_attributes module +------------------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.slo_status_data_attributes + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.slo\_status\_response module +---------------------------------------------------------- + +.. automodule:: datadog_api_client.v2.model.slo_status_response + :members: + :show-inheritance: + +datadog\_api\_client.v2.model.slo\_status\_type module +------------------------------------------------------ + +.. automodule:: datadog_api_client.v2.model.slo_status_type + :members: + :show-inheritance: + datadog\_api\_client.v2.model.software\_catalog\_trigger\_wrapper module ------------------------------------------------------------------------ diff --git a/examples/v2/service-level-objectives/GetSloStatus.py b/examples/v2/service-level-objectives/GetSloStatus.py new file mode 100644 index 0000000000..4dcf8078af --- /dev/null +++ b/examples/v2/service-level-objectives/GetSloStatus.py @@ -0,0 +1,18 @@ +""" +Get SLO status returns "OK" response +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.service_level_objectives_api import ServiceLevelObjectivesApi + +configuration = Configuration() +configuration.unstable_operations["get_slo_status"] = True +with ApiClient(configuration) as api_client: + api_instance = ServiceLevelObjectivesApi(api_client) + response = api_instance.get_slo_status( + slo_id="00000000-0000-0000-0000-000000000000", + from_ts=1690901870, + to_ts=1706803070, + ) + + print(response) diff --git a/src/datadog_api_client/configuration.py b/src/datadog_api_client/configuration.py index 9e2b3859d4..38713bb7f6 100644 --- a/src/datadog_api_client/configuration.py +++ b/src/datadog_api_client/configuration.py @@ -398,6 +398,7 @@ def __init__( "v2.create_slo_report_job": False, "v2.get_slo_report": False, "v2.get_slo_report_job_status": False, + "v2.get_slo_status": False, "v2.get_spa_recommendations": False, "v2.get_spa_recommendations_with_shard": False, "v2.create_custom_rule": False, diff --git a/src/datadog_api_client/v2/api/service_level_objectives_api.py b/src/datadog_api_client/v2/api/service_level_objectives_api.py index 37c343e48c..696a1e7aee 100644 --- a/src/datadog_api_client/v2/api/service_level_objectives_api.py +++ b/src/datadog_api_client/v2/api/service_level_objectives_api.py @@ -3,13 +3,18 @@ # Copyright 2019-Present Datadog, Inc. from __future__ import annotations -from typing import Any, Dict +from typing import Any, Dict, Union from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint from datadog_api_client.configuration import Configuration +from datadog_api_client.model_utils import ( + UnsetType, + unset, +) from datadog_api_client.v2.model.slo_report_post_response import SLOReportPostResponse from datadog_api_client.v2.model.slo_report_create_request import SloReportCreateRequest from datadog_api_client.v2.model.slo_report_status_get_response import SLOReportStatusGetResponse +from datadog_api_client.v2.model.slo_status_response import SloStatusResponse class ServiceLevelObjectivesApi: @@ -93,6 +98,46 @@ def __init__(self, api_client=None): api_client=api_client, ) + self._get_slo_status_endpoint = _Endpoint( + settings={ + "response_type": (SloStatusResponse,), + "auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"], + "endpoint_path": "/api/v2/slo/{slo_id}/status", + "operation_id": "get_slo_status", + "http_method": "GET", + "version": "v2", + }, + params_map={ + "slo_id": { + "required": True, + "openapi_types": (str,), + "attribute": "slo_id", + "location": "path", + }, + "from_ts": { + "required": True, + "openapi_types": (int,), + "attribute": "from_ts", + "location": "query", + }, + "to_ts": { + "required": True, + "openapi_types": (int,), + "attribute": "to_ts", + "location": "query", + }, + "disable_corrections": { + "openapi_types": (bool,), + "attribute": "disable_corrections", + "location": "query", + }, + }, + headers_map={ + "accept": ["application/json"], + }, + api_client=api_client, + ) + def create_slo_report_job( self, body: SloReportCreateRequest, @@ -147,3 +192,39 @@ def get_slo_report_job_status( kwargs["report_id"] = report_id return self._get_slo_report_job_status_endpoint.call_with_http_info(**kwargs) + + def get_slo_status( + self, + slo_id: str, + from_ts: int, + to_ts: int, + *, + disable_corrections: Union[bool, UnsetType] = unset, + ) -> SloStatusResponse: + """Get SLO status. + + Get the status of a Service Level Objective (SLO) for a given time period. + + This endpoint returns the current SLI value, error budget remaining, and other status information for the specified SLO. + + :param slo_id: The ID of the SLO. + :type slo_id: str + :param from_ts: The starting timestamp for the SLO status query in epoch seconds. + :type from_ts: int + :param to_ts: The ending timestamp for the SLO status query in epoch seconds. + :type to_ts: int + :param disable_corrections: Whether to exclude correction windows from the SLO status calculation. Defaults to false. + :type disable_corrections: bool, optional + :rtype: SloStatusResponse + """ + kwargs: Dict[str, Any] = {} + kwargs["slo_id"] = slo_id + + kwargs["from_ts"] = from_ts + + kwargs["to_ts"] = to_ts + + if disable_corrections is not unset: + kwargs["disable_corrections"] = disable_corrections + + return self._get_slo_status_endpoint.call_with_http_info(**kwargs) diff --git a/src/datadog_api_client/v2/model/raw_error_budget_remaining.py b/src/datadog_api_client/v2/model/raw_error_budget_remaining.py new file mode 100644 index 0000000000..14e21ea512 --- /dev/null +++ b/src/datadog_api_client/v2/model/raw_error_budget_remaining.py @@ -0,0 +1,39 @@ +# 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 ( + ModelNormal, + cached_property, +) + + +class RawErrorBudgetRemaining(ModelNormal): + @cached_property + def openapi_types(_): + return { + "unit": (str,), + "value": (float,), + } + + attribute_map = { + "unit": "unit", + "value": "value", + } + + def __init__(self_, unit: str, value: float, **kwargs): + """ + The raw error budget remaining for the SLO. + + :param unit: The unit of the error budget (for example, ``seconds`` , ``requests`` ). + :type unit: str + + :param value: The numeric value of the remaining error budget. + :type value: float + """ + super().__init__(kwargs) + + self_.unit = unit + self_.value = value diff --git a/src/datadog_api_client/v2/model/slo_status_data.py b/src/datadog_api_client/v2/model/slo_status_data.py new file mode 100644 index 0000000000..3d9403964f --- /dev/null +++ b/src/datadog_api_client/v2/model/slo_status_data.py @@ -0,0 +1,54 @@ +# 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.slo_status_data_attributes import SloStatusDataAttributes + from datadog_api_client.v2.model.slo_status_type import SloStatusType + + +class SloStatusData(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.slo_status_data_attributes import SloStatusDataAttributes + from datadog_api_client.v2.model.slo_status_type import SloStatusType + + return { + "attributes": (SloStatusDataAttributes,), + "id": (str,), + "type": (SloStatusType,), + } + + attribute_map = { + "attributes": "attributes", + "id": "id", + "type": "type", + } + + def __init__(self_, attributes: SloStatusDataAttributes, id: str, type: SloStatusType, **kwargs): + """ + The data portion of the SLO status response. + + :param attributes: The attributes of the SLO status. + :type attributes: SloStatusDataAttributes + + :param id: The ID of the SLO. + :type id: str + + :param type: The type of the SLO status resource. + :type type: SloStatusType + """ + super().__init__(kwargs) + + self_.attributes = attributes + self_.id = id + self_.type = type diff --git a/src/datadog_api_client/v2/model/slo_status_data_attributes.py b/src/datadog_api_client/v2/model/slo_status_data_attributes.py new file mode 100644 index 0000000000..a13de82b18 --- /dev/null +++ b/src/datadog_api_client/v2/model/slo_status_data_attributes.py @@ -0,0 +1,72 @@ +# 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.raw_error_budget_remaining import RawErrorBudgetRemaining + + +class SloStatusDataAttributes(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.raw_error_budget_remaining import RawErrorBudgetRemaining + + return { + "error_budget_remaining": (float,), + "raw_error_budget_remaining": (RawErrorBudgetRemaining,), + "sli": (float,), + "span_precision": (int,), + "state": (str,), + } + + attribute_map = { + "error_budget_remaining": "error_budget_remaining", + "raw_error_budget_remaining": "raw_error_budget_remaining", + "sli": "sli", + "span_precision": "span_precision", + "state": "state", + } + + def __init__( + self_, + error_budget_remaining: float, + raw_error_budget_remaining: RawErrorBudgetRemaining, + sli: float, + span_precision: int, + state: str, + **kwargs, + ): + """ + The attributes of the SLO status. + + :param error_budget_remaining: The percentage of error budget remaining. + :type error_budget_remaining: float + + :param raw_error_budget_remaining: The raw error budget remaining for the SLO. + :type raw_error_budget_remaining: RawErrorBudgetRemaining + + :param sli: The current Service Level Indicator (SLI) value as a percentage. + :type sli: float + + :param span_precision: The precision of the time span in seconds. + :type span_precision: int + + :param state: The current state of the SLO (for example, ``breached`` , ``warning`` , ``ok`` ). + :type state: str + """ + super().__init__(kwargs) + + self_.error_budget_remaining = error_budget_remaining + self_.raw_error_budget_remaining = raw_error_budget_remaining + self_.sli = sli + self_.span_precision = span_precision + self_.state = state diff --git a/src/datadog_api_client/v2/model/slo_status_response.py b/src/datadog_api_client/v2/model/slo_status_response.py new file mode 100644 index 0000000000..ef4c1ead1a --- /dev/null +++ b/src/datadog_api_client/v2/model/slo_status_response.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.slo_status_data import SloStatusData + + +class SloStatusResponse(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v2.model.slo_status_data import SloStatusData + + return { + "data": (SloStatusData,), + } + + attribute_map = { + "data": "data", + } + + def __init__(self_, data: SloStatusData, **kwargs): + """ + The SLO status response. + + :param data: The data portion of the SLO status response. + :type data: SloStatusData + """ + super().__init__(kwargs) + + self_.data = data diff --git a/src/datadog_api_client/v2/model/slo_status_type.py b/src/datadog_api_client/v2/model/slo_status_type.py new file mode 100644 index 0000000000..3f3953fc0d --- /dev/null +++ b/src/datadog_api_client/v2/model/slo_status_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 SloStatusType(ModelSimple): + """ + The type of the SLO status resource. + + :param value: If omitted defaults to "slo_status". Must be one of ["slo_status"]. + :type value: str + """ + + allowed_values = { + "slo_status", + } + SLO_STATUS: ClassVar["SloStatusType"] + + @cached_property + def openapi_types(_): + return { + "value": (str,), + } + + +SloStatusType.SLO_STATUS = SloStatusType("slo_status") diff --git a/src/datadog_api_client/v2/models/__init__.py b/src/datadog_api_client/v2/models/__init__.py index 26def62074..a87b701b73 100644 --- a/src/datadog_api_client/v2/models/__init__.py +++ b/src/datadog_api_client/v2/models/__init__.py @@ -4060,6 +4060,7 @@ from datadog_api_client.v2.model.rum_sort import RUMSort from datadog_api_client.v2.model.rum_sort_order import RUMSortOrder from datadog_api_client.v2.model.rum_warning import RUMWarning +from datadog_api_client.v2.model.raw_error_budget_remaining import RawErrorBudgetRemaining from datadog_api_client.v2.model.readiness_gate import ReadinessGate from datadog_api_client.v2.model.readiness_gate_threshold_type import ReadinessGateThresholdType from datadog_api_client.v2.model.recommendation_attributes import RecommendationAttributes @@ -5018,6 +5019,10 @@ from datadog_api_client.v2.model.slo_report_create_request import SloReportCreateRequest from datadog_api_client.v2.model.slo_report_create_request_attributes import SloReportCreateRequestAttributes from datadog_api_client.v2.model.slo_report_create_request_data import SloReportCreateRequestData +from datadog_api_client.v2.model.slo_status_data import SloStatusData +from datadog_api_client.v2.model.slo_status_data_attributes import SloStatusDataAttributes +from datadog_api_client.v2.model.slo_status_response import SloStatusResponse +from datadog_api_client.v2.model.slo_status_type import SloStatusType from datadog_api_client.v2.model.software_catalog_trigger_wrapper import SoftwareCatalogTriggerWrapper from datadog_api_client.v2.model.sort_direction import SortDirection from datadog_api_client.v2.model.span import Span @@ -8577,6 +8582,7 @@ "RUMSort", "RUMSortOrder", "RUMWarning", + "RawErrorBudgetRemaining", "ReadinessGate", "ReadinessGateThresholdType", "RecommendationAttributes", @@ -9249,6 +9255,10 @@ "SloReportCreateRequest", "SloReportCreateRequestAttributes", "SloReportCreateRequestData", + "SloStatusData", + "SloStatusDataAttributes", + "SloStatusResponse", + "SloStatusType", "SoftwareCatalogTriggerWrapper", "SortDirection", "Span", diff --git a/tests/v2/features/service_level_objectives.feature b/tests/v2/features/service_level_objectives.feature index a415d16cce..4dc11df9e5 100644 --- a/tests/v2/features/service_level_objectives.feature +++ b/tests/v2/features/service_level_objectives.feature @@ -79,3 +79,33 @@ Feature: Service Level Objectives When the request is sent Then the response status is 200 OK And the response "data.type" is equal to "report_id" + + @generated @skip @team:DataDog/slo-app + Scenario: Get SLO status returns "Bad Request" response + Given operation "GetSloStatus" enabled + And new "GetSloStatus" request + And request contains "slo_id" parameter from "REPLACE.ME" + And request contains "from_ts" parameter from "REPLACE.ME" + And request contains "to_ts" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/slo-app + Scenario: Get SLO status returns "Not Found" response + Given operation "GetSloStatus" enabled + And new "GetSloStatus" request + And request contains "slo_id" parameter from "REPLACE.ME" + And request contains "from_ts" parameter from "REPLACE.ME" + And request contains "to_ts" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/slo-app + Scenario: Get SLO status returns "OK" response + Given operation "GetSloStatus" enabled + And new "GetSloStatus" request + And request contains "slo_id" parameter from "REPLACE.ME" + And request contains "from_ts" parameter from "REPLACE.ME" + And request contains "to_ts" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK diff --git a/tests/v2/features/undo.json b/tests/v2/features/undo.json index 7619933d2f..73cbda7fbc 100644 --- a/tests/v2/features/undo.json +++ b/tests/v2/features/undo.json @@ -4616,6 +4616,12 @@ "type": "safe" } }, + "GetSloStatus": { + "tag": "Service Level Objectives", + "undo": { + "type": "safe" + } + }, "GetSPARecommendations": { "tag": "Spa", "undo": {