From 3e041d0948d844f72d2ef5e531cc772afbc18ee1 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Fri, 9 Jan 2026 19:59:10 +0000 Subject: [PATCH] Regenerate client from commit 2ce6d32 of spec repo --- .generator/schemas/v1/openapi.yaml | 72 ++++++++++++++++++- docs/datadog_api_client.v1.model.rst | 14 ++++ .../CreateSLO_512760759.py | 68 ++++++++++++++++++ .../v1/model/service_level_objective.py | 9 +-- .../v1/model/service_level_objective_query.py | 4 +- .../model/service_level_objective_request.py | 9 +-- .../v1/model/slo_count_definition.py | 70 ++++++++++++++++++ .../v1/model/slo_count_spec.py | 45 ++++++++++++ .../v1/model/slo_response_data.py | 9 +-- .../v1/model/slo_sli_spec.py | 8 ++- src/datadog_api_client/v1/models/__init__.py | 4 ++ .../features/service_level_objectives.feature | 17 +++++ 12 files changed, 311 insertions(+), 18 deletions(-) create mode 100644 examples/v1/service-level-objectives/CreateSLO_512760759.py create mode 100644 src/datadog_api_client/v1/model/slo_count_definition.py create mode 100644 src/datadog_api_client/v1/model/slo_count_spec.py diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 8c4bbdb218..0a81cad415 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -11548,6 +11548,61 @@ components: example: UTC type: string type: object + SLOCountDefinition: + description: 'A count-based (metric) SLI specification, composed of three parts: + the good events formula, the total events formula, + + and the underlying queries. Usage is not permitted when request payload contains + `query` field.' + example: + good_events_formula: query1 - query2 + queries: + - data_source: metrics + name: query1 + query: sum:trace.servlet.request.hits{*} by {env}.as_count() + - data_source: metrics + name: query2 + query: sum:trace.servlet.request.errors{*} by {env}.as_count() + total_events_formula: query1 + properties: + good_events_formula: + $ref: '#/components/schemas/SLOFormula' + queries: + example: + - data_source: metrics + name: query1 + query: sum:trace.servlet.request.hits{*} by {env}.as_count() + items: + $ref: '#/components/schemas/SLODataSourceQueryDefinition' + minItems: 1 + type: array + total_events_formula: + $ref: '#/components/schemas/SLOFormula' + required: + - good_events_formula + - total_events_formula + - queries + type: object + SLOCountSpec: + additionalProperties: false + description: A metric SLI specification. + example: + count: + good_events_formula: query1 - query2 + queries: + - data_source: metrics + name: query1 + query: sum:trace.servlet.request.hits{*} by {env}.as_count() + - data_source: metrics + name: query2 + query: sum:trace.servlet.request.errors{*} by {env}.as_count() + total_events_formula: query1 + properties: + count: + $ref: '#/components/schemas/SLOCountDefinition' + required: + - count + type: object SLOCreator: description: The creator of the SLO nullable: true @@ -12395,8 +12450,16 @@ components: type: string query: $ref: '#/components/schemas/ServiceLevelObjectiveQuery' + description: 'The metric query of good / total events. This is not allowed + if the `sli_specification` field + + is used in the same request.' sli_specification: $ref: '#/components/schemas/SLOSliSpec' + description: 'A generic SLI specification. This is currently used for time-slice + and count-based (metric) SLOs only. + + This is not allowed if the `query` field is used in the same request.' tags: description: 'A list of tags associated with this service level objective. @@ -12453,9 +12516,10 @@ components: type: object SLOSliSpec: description: A generic SLI specification. This is currently used for time-slice - SLOs only. + and count-based (metric) SLOs only. oneOf: - $ref: '#/components/schemas/SLOTimeSliceSpec' + - $ref: '#/components/schemas/SLOCountSpec' SLOState: description: State of the SLO. enum: @@ -13607,13 +13671,15 @@ components: - type type: object ServiceLevelObjectiveQuery: - description: 'A metric-based SLO. **Required if type is `metric`**. Note that + description: 'A count-based (metric) SLO query. This field has been superseded + by `sli_specification` but is retained for backwards compatibility. Note that Datadog only allows the sum by aggregator to be used because this will sum up all request counts instead of averaging them, or taking the max or - min of all of those requests.' + min of all of those requests. Usage is not permitted when request payload + contains `sli_specification` field.' properties: denominator: description: A Datadog metric query for total (valid) events. diff --git a/docs/datadog_api_client.v1.model.rst b/docs/datadog_api_client.v1.model.rst index 551a66106e..8c36f40fca 100644 --- a/docs/datadog_api_client.v1.model.rst +++ b/docs/datadog_api_client.v1.model.rst @@ -3679,6 +3679,20 @@ datadog\_api\_client.v1.model.slo\_correction\_update\_request\_attributes modul :members: :show-inheritance: +datadog\_api\_client.v1.model.slo\_count\_definition module +----------------------------------------------------------- + +.. automodule:: datadog_api_client.v1.model.slo_count_definition + :members: + :show-inheritance: + +datadog\_api\_client.v1.model.slo\_count\_spec module +----------------------------------------------------- + +.. automodule:: datadog_api_client.v1.model.slo_count_spec + :members: + :show-inheritance: + datadog\_api\_client.v1.model.slo\_creator module ------------------------------------------------- diff --git a/examples/v1/service-level-objectives/CreateSLO_512760759.py b/examples/v1/service-level-objectives/CreateSLO_512760759.py new file mode 100644 index 0000000000..6fa6cef618 --- /dev/null +++ b/examples/v1/service-level-objectives/CreateSLO_512760759.py @@ -0,0 +1,68 @@ +""" +Create a new metric SLO object using sli_specification returns "OK" response +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v1.api.service_level_objectives_api import ServiceLevelObjectivesApi +from datadog_api_client.v1.model.formula_and_function_metric_data_source import FormulaAndFunctionMetricDataSource +from datadog_api_client.v1.model.formula_and_function_metric_query_definition import ( + FormulaAndFunctionMetricQueryDefinition, +) +from datadog_api_client.v1.model.service_level_objective_request import ServiceLevelObjectiveRequest +from datadog_api_client.v1.model.slo_count_definition import SLOCountDefinition +from datadog_api_client.v1.model.slo_count_spec import SLOCountSpec +from datadog_api_client.v1.model.slo_formula import SLOFormula +from datadog_api_client.v1.model.slo_threshold import SLOThreshold +from datadog_api_client.v1.model.slo_timeframe import SLOTimeframe +from datadog_api_client.v1.model.slo_type import SLOType + +body = ServiceLevelObjectiveRequest( + type=SLOType.METRIC, + description="Metric SLO using sli_specification", + name="Example-Service-Level-Objective", + sli_specification=SLOCountSpec( + count=SLOCountDefinition( + good_events_formula=SLOFormula( + formula="query1 - query2", + ), + total_events_formula=SLOFormula( + formula="query1", + ), + queries=[ + FormulaAndFunctionMetricQueryDefinition( + data_source=FormulaAndFunctionMetricDataSource.METRICS, + name="query1", + query="sum:httpservice.hits{*}.as_count()", + ), + FormulaAndFunctionMetricQueryDefinition( + data_source=FormulaAndFunctionMetricDataSource.METRICS, + name="query2", + query="sum:httpservice.errors{*}.as_count()", + ), + ], + ), + ), + tags=[ + "env:prod", + "type:count", + ], + thresholds=[ + SLOThreshold( + target=99.0, + target_display="99.0", + timeframe=SLOTimeframe.SEVEN_DAYS, + warning=99.5, + warning_display="99.5", + ), + ], + timeframe=SLOTimeframe.SEVEN_DAYS, + target_threshold=99.0, + warning_threshold=99.5, +) + +configuration = Configuration() +with ApiClient(configuration) as api_client: + api_instance = ServiceLevelObjectivesApi(api_client) + response = api_instance.create_slo(body=body) + + print(response) diff --git a/src/datadog_api_client/v1/model/service_level_objective.py b/src/datadog_api_client/v1/model/service_level_objective.py index a95b993513..0a8332fb9b 100644 --- a/src/datadog_api_client/v1/model/service_level_objective.py +++ b/src/datadog_api_client/v1/model/service_level_objective.py @@ -22,6 +22,7 @@ from datadog_api_client.v1.model.slo_timeframe import SLOTimeframe from datadog_api_client.v1.model.slo_type import SLOType from datadog_api_client.v1.model.slo_time_slice_spec import SLOTimeSliceSpec + from datadog_api_client.v1.model.slo_count_spec import SLOCountSpec class ServiceLevelObjective(ModelNormal): @@ -94,7 +95,7 @@ def __init__( monitor_ids: Union[List[int], UnsetType] = unset, monitor_tags: Union[List[str], UnsetType] = unset, query: Union[ServiceLevelObjectiveQuery, UnsetType] = unset, - sli_specification: Union[SLOSliSpec, SLOTimeSliceSpec, UnsetType] = unset, + sli_specification: Union[SLOSliSpec, SLOTimeSliceSpec, SLOCountSpec, UnsetType] = unset, tags: Union[List[str], UnsetType] = unset, target_threshold: Union[float, UnsetType] = unset, timeframe: Union[SLOTimeframe, UnsetType] = unset, @@ -151,12 +152,12 @@ def __init__( :param name: The name of the service level objective object. :type name: str - :param query: A metric-based SLO. **Required if type is metric**. Note that Datadog only allows the sum by aggregator + :param query: A count-based (metric) SLO query. This field has been superseded by ``sli_specification`` but is retained for backwards compatibility. Note that Datadog only allows the sum by aggregator to be used because this will sum up all request counts instead of averaging them, or taking the max or - min of all of those requests. + min of all of those requests. Usage is not permitted when request payload contains ``sli_specification`` field. :type query: ServiceLevelObjectiveQuery, optional - :param sli_specification: A generic SLI specification. This is currently used for time-slice SLOs only. + :param sli_specification: A generic SLI specification. This is currently used for time-slice and count-based (metric) SLOs only. :type sli_specification: SLOSliSpec, optional :param tags: A list of tags associated with this service level objective. diff --git a/src/datadog_api_client/v1/model/service_level_objective_query.py b/src/datadog_api_client/v1/model/service_level_objective_query.py index ee11656739..d0cefffaa7 100644 --- a/src/datadog_api_client/v1/model/service_level_objective_query.py +++ b/src/datadog_api_client/v1/model/service_level_objective_query.py @@ -25,9 +25,9 @@ def openapi_types(_): def __init__(self_, denominator: str, numerator: str, **kwargs): """ - A metric-based SLO. **Required if type is metric**. Note that Datadog only allows the sum by aggregator + A count-based (metric) SLO query. This field has been superseded by ``sli_specification`` but is retained for backwards compatibility. Note that Datadog only allows the sum by aggregator to be used because this will sum up all request counts instead of averaging them, or taking the max or - min of all of those requests. + min of all of those requests. Usage is not permitted when request payload contains ``sli_specification`` field. :param denominator: A Datadog metric query for total (valid) events. :type denominator: str diff --git a/src/datadog_api_client/v1/model/service_level_objective_request.py b/src/datadog_api_client/v1/model/service_level_objective_request.py index dbeb4bd0d9..547d7e48f3 100644 --- a/src/datadog_api_client/v1/model/service_level_objective_request.py +++ b/src/datadog_api_client/v1/model/service_level_objective_request.py @@ -21,6 +21,7 @@ from datadog_api_client.v1.model.slo_timeframe import SLOTimeframe from datadog_api_client.v1.model.slo_type import SLOType from datadog_api_client.v1.model.slo_time_slice_spec import SLOTimeSliceSpec + from datadog_api_client.v1.model.slo_count_spec import SLOCountSpec class ServiceLevelObjectiveRequest(ModelNormal): @@ -71,7 +72,7 @@ def __init__( groups: Union[List[str], UnsetType] = unset, monitor_ids: Union[List[int], UnsetType] = unset, query: Union[ServiceLevelObjectiveQuery, UnsetType] = unset, - sli_specification: Union[SLOSliSpec, SLOTimeSliceSpec, UnsetType] = unset, + sli_specification: Union[SLOSliSpec, SLOTimeSliceSpec, SLOCountSpec, UnsetType] = unset, tags: Union[List[str], UnsetType] = unset, target_threshold: Union[float, UnsetType] = unset, timeframe: Union[SLOTimeframe, UnsetType] = unset, @@ -102,12 +103,12 @@ def __init__( :param name: The name of the service level objective object. :type name: str - :param query: A metric-based SLO. **Required if type is metric**. Note that Datadog only allows the sum by aggregator + :param query: A count-based (metric) SLO query. This field has been superseded by ``sli_specification`` but is retained for backwards compatibility. Note that Datadog only allows the sum by aggregator to be used because this will sum up all request counts instead of averaging them, or taking the max or - min of all of those requests. + min of all of those requests. Usage is not permitted when request payload contains ``sli_specification`` field. :type query: ServiceLevelObjectiveQuery, optional - :param sli_specification: A generic SLI specification. This is currently used for time-slice SLOs only. + :param sli_specification: A generic SLI specification. This is currently used for time-slice and count-based (metric) SLOs only. :type sli_specification: SLOSliSpec, optional :param tags: A list of tags associated with this service level objective. diff --git a/src/datadog_api_client/v1/model/slo_count_definition.py b/src/datadog_api_client/v1/model/slo_count_definition.py new file mode 100644 index 0000000000..c2f9ac7161 --- /dev/null +++ b/src/datadog_api_client/v1/model/slo_count_definition.py @@ -0,0 +1,70 @@ +# 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, +) + + +if TYPE_CHECKING: + from datadog_api_client.v1.model.slo_formula import SLOFormula + from datadog_api_client.v1.model.slo_data_source_query_definition import SLODataSourceQueryDefinition + from datadog_api_client.v1.model.formula_and_function_metric_query_definition import ( + FormulaAndFunctionMetricQueryDefinition, + ) + + +class SLOCountDefinition(ModelNormal): + validations = { + "queries": { + "min_items": 1, + }, + } + + @cached_property + def openapi_types(_): + from datadog_api_client.v1.model.slo_formula import SLOFormula + from datadog_api_client.v1.model.slo_data_source_query_definition import SLODataSourceQueryDefinition + + return { + "good_events_formula": (SLOFormula,), + "queries": ([SLODataSourceQueryDefinition],), + "total_events_formula": (SLOFormula,), + } + + attribute_map = { + "good_events_formula": "good_events_formula", + "queries": "queries", + "total_events_formula": "total_events_formula", + } + + def __init__( + self_, + good_events_formula: SLOFormula, + queries: List[Union[SLODataSourceQueryDefinition, FormulaAndFunctionMetricQueryDefinition]], + total_events_formula: SLOFormula, + **kwargs, + ): + """ + A count-based (metric) SLI specification, composed of three parts: the good events formula, the total events formula, + and the underlying queries. Usage is not permitted when request payload contains ``query`` field. + + :param good_events_formula: A formula that specifies how to combine the results of multiple queries. + :type good_events_formula: SLOFormula + + :param queries: + :type queries: [SLODataSourceQueryDefinition] + + :param total_events_formula: A formula that specifies how to combine the results of multiple queries. + :type total_events_formula: SLOFormula + """ + super().__init__(kwargs) + + self_.good_events_formula = good_events_formula + self_.queries = queries + self_.total_events_formula = total_events_formula diff --git a/src/datadog_api_client/v1/model/slo_count_spec.py b/src/datadog_api_client/v1/model/slo_count_spec.py new file mode 100644 index 0000000000..e88171cf1e --- /dev/null +++ b/src/datadog_api_client/v1/model/slo_count_spec.py @@ -0,0 +1,45 @@ +# 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.v1.model.slo_count_definition import SLOCountDefinition + + +class SLOCountSpec(ModelNormal): + @cached_property + def additional_properties_type(_): + return None + + @cached_property + def openapi_types(_): + from datadog_api_client.v1.model.slo_count_definition import SLOCountDefinition + + return { + "count": (SLOCountDefinition,), + } + + attribute_map = { + "count": "count", + } + + def __init__(self_, count: SLOCountDefinition, **kwargs): + """ + A metric SLI specification. + + :param count: A count-based (metric) SLI specification, composed of three parts: the good events formula, the total events formula, + and the underlying queries. Usage is not permitted when request payload contains ``query`` field. + :type count: SLOCountDefinition + """ + super().__init__(kwargs) + + self_.count = count diff --git a/src/datadog_api_client/v1/model/slo_response_data.py b/src/datadog_api_client/v1/model/slo_response_data.py index 275644beb1..f5948eb5f7 100644 --- a/src/datadog_api_client/v1/model/slo_response_data.py +++ b/src/datadog_api_client/v1/model/slo_response_data.py @@ -22,6 +22,7 @@ from datadog_api_client.v1.model.slo_timeframe import SLOTimeframe from datadog_api_client.v1.model.slo_type import SLOType from datadog_api_client.v1.model.slo_time_slice_spec import SLOTimeSliceSpec + from datadog_api_client.v1.model.slo_count_spec import SLOCountSpec class SLOResponseData(ModelNormal): @@ -95,7 +96,7 @@ def __init__( monitor_tags: Union[List[str], UnsetType] = unset, name: Union[str, UnsetType] = unset, query: Union[ServiceLevelObjectiveQuery, UnsetType] = unset, - sli_specification: Union[SLOSliSpec, SLOTimeSliceSpec, UnsetType] = unset, + sli_specification: Union[SLOSliSpec, SLOTimeSliceSpec, SLOCountSpec, UnsetType] = unset, tags: Union[List[str], UnsetType] = unset, target_threshold: Union[float, UnsetType] = unset, thresholds: Union[List[SLOThreshold], UnsetType] = unset, @@ -157,12 +158,12 @@ def __init__( :param name: The name of the service level objective object. :type name: str, optional - :param query: A metric-based SLO. **Required if type is metric**. Note that Datadog only allows the sum by aggregator + :param query: A count-based (metric) SLO query. This field has been superseded by ``sli_specification`` but is retained for backwards compatibility. Note that Datadog only allows the sum by aggregator to be used because this will sum up all request counts instead of averaging them, or taking the max or - min of all of those requests. + min of all of those requests. Usage is not permitted when request payload contains ``sli_specification`` field. :type query: ServiceLevelObjectiveQuery, optional - :param sli_specification: A generic SLI specification. This is currently used for time-slice SLOs only. + :param sli_specification: A generic SLI specification. This is currently used for time-slice and count-based (metric) SLOs only. :type sli_specification: SLOSliSpec, optional :param tags: A list of tags associated with this service level objective. diff --git a/src/datadog_api_client/v1/model/slo_sli_spec.py b/src/datadog_api_client/v1/model/slo_sli_spec.py index 69f9e701d5..e3291652f0 100644 --- a/src/datadog_api_client/v1/model/slo_sli_spec.py +++ b/src/datadog_api_client/v1/model/slo_sli_spec.py @@ -13,11 +13,15 @@ class SLOSliSpec(ModelComposed): def __init__(self, **kwargs): """ - A generic SLI specification. This is currently used for time-slice SLOs only. + A generic SLI specification. This is currently used for time-slice and count-based (metric) SLOs only. :param time_slice: The time-slice condition, composed of 3 parts: 1. the metric timeseries query, 2. the comparator, and 3. the threshold. Optionally, a fourth part, the query interval, can be provided. :type time_slice: SLOTimeSliceCondition + + :param count: A count-based (metric) SLI specification, composed of three parts: the good events formula, the total events formula, + and the underlying queries. Usage is not permitted when request payload contains `query` field. + :type count: SLOCountDefinition """ super().__init__(kwargs) @@ -31,9 +35,11 @@ def _composed_schemas(_): # classes don't exist yet because their module has not finished # loading from datadog_api_client.v1.model.slo_time_slice_spec import SLOTimeSliceSpec + from datadog_api_client.v1.model.slo_count_spec import SLOCountSpec return { "oneOf": [ SLOTimeSliceSpec, + SLOCountSpec, ], } diff --git a/src/datadog_api_client/v1/models/__init__.py b/src/datadog_api_client/v1/models/__init__.py index 7dda7f9989..cbaa35517d 100644 --- a/src/datadog_api_client/v1/models/__init__.py +++ b/src/datadog_api_client/v1/models/__init__.py @@ -540,6 +540,8 @@ from datadog_api_client.v1.model.slo_correction_update_data import SLOCorrectionUpdateData from datadog_api_client.v1.model.slo_correction_update_request import SLOCorrectionUpdateRequest from datadog_api_client.v1.model.slo_correction_update_request_attributes import SLOCorrectionUpdateRequestAttributes +from datadog_api_client.v1.model.slo_count_definition import SLOCountDefinition +from datadog_api_client.v1.model.slo_count_spec import SLOCountSpec from datadog_api_client.v1.model.slo_creator import SLOCreator from datadog_api_client.v1.model.slo_data_source_query_definition import SLODataSourceQueryDefinition from datadog_api_client.v1.model.slo_delete_response import SLODeleteResponse @@ -1594,6 +1596,8 @@ "SLOCorrectionUpdateData", "SLOCorrectionUpdateRequest", "SLOCorrectionUpdateRequestAttributes", + "SLOCountDefinition", + "SLOCountSpec", "SLOCreator", "SLODataSourceQueryDefinition", "SLODeleteResponse", diff --git a/tests/v1/features/service_level_objectives.feature b/tests/v1/features/service_level_objectives.feature index c5534618a7..22c9d6cd3f 100644 --- a/tests/v1/features/service_level_objectives.feature +++ b/tests/v1/features/service_level_objectives.feature @@ -48,6 +48,23 @@ Feature: Service Level Objectives When the request is sent Then the response status is 200 OK + @team:DataDog/slo-app + Scenario: Create a new metric SLO object using sli_specification returns "OK" response + Given new "CreateSLO" request + And body with value {"type":"metric","description":"Metric SLO using sli_specification","name":"{{ unique }}","sli_specification":{"count":{"good_events_formula":{"formula":"query1 - query2"},"total_events_formula":{"formula":"query1"},"queries":[{"data_source":"metrics","name":"query1","query":"sum:httpservice.hits{*}.as_count()"},{"data_source":"metrics","name":"query2","query":"sum:httpservice.errors{*}.as_count()"}]}},"tags":["env:prod","type:count"],"thresholds":[{"target":99.0,"target_display":"99.0","timeframe":"7d","warning":99.5,"warning_display":"99.5"}],"timeframe":"7d","target_threshold":99.0,"warning_threshold":99.5} + When the request is sent + Then the response status is 200 OK + And the response "data[0].timeframe" is equal to "7d" + And the response "data[0].target_threshold" is equal to 99.0 + And the response "data[0].warning_threshold" is equal to 99.5 + And the response "data[0]" has field "sli_specification" + And the response "data[0].sli_specification" has field "count" + And the response "data[0].sli_specification.count" has field "good_events_formula" + And the response "data[0].sli_specification.count" has field "total_events_formula" + And the response "data[0].sli_specification.count" has field "queries" + And the response "data[0].sli_specification.count.queries" has length 2 + And the response "data[0]" has field "query" + @team:DataDog/slo-app Scenario: Create a time-slice SLO object returns "OK" response Given new "CreateSLO" request