diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index daa9d89fc3..ea9665ada3 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -12338,33 +12338,73 @@ components: type: object SLOCountDefinition: description: 'A count-based (metric) SLI specification, composed of three parts: - the good events formula, the total events formula, + the good events formula, - and the underlying queries.' + the bad or total events formula, and the underlying queries. + + Exactly one of `total_events_formula` or `bad_events_formula` must be provided.' example: - good_events_formula: query1 - query2 + bad_events_formula: query2 + good_events_formula: query1 queries: - data_source: metrics name: query1 - query: sum:trace.servlet.request.hits{*} by {env}.as_count() + query: sum:trace.servlet.request.hits{!http.status_code:500} by {env}.as_count() - data_source: metrics name: query2 - query: sum:trace.servlet.request.errors{*} by {env}.as_count() - total_events_formula: query1 + query: sum:trace.servlet.request.hits{http.status_code:500} by {env}.as_count() + oneOf: + - $ref: '#/components/schemas/SLOCountDefinitionWithTotalEventsFormula' + - $ref: '#/components/schemas/SLOCountDefinitionWithBadEventsFormula' + SLOCountDefinitionWithBadEventsFormula: + additionalProperties: false properties: + bad_events_formula: + $ref: '#/components/schemas/SLOFormula' + description: The bad events formula (recommended). Total events queries + can be defined using the `total_events_formula` field as an alternative. + Only one of `total_events_formula` or `bad_events_formula` must be provided. good_events_formula: $ref: '#/components/schemas/SLOFormula' queries: example: - data_source: metrics name: query1 - query: sum:trace.servlet.request.hits{*} by {env}.as_count() + query: sum:trace.servlet.request.hits{!http.status_code:500} by {env}.as_count() + - data_source: metrics + name: query2 + query: sum:trace.servlet.request.hits{http.status_code:500} by {env}.as_count() + items: + $ref: '#/components/schemas/SLODataSourceQueryDefinition' + minItems: 1 + type: array + required: + - good_events_formula + - bad_events_formula + - queries + type: object + SLOCountDefinitionWithTotalEventsFormula: + additionalProperties: false + properties: + good_events_formula: + $ref: '#/components/schemas/SLOFormula' + queries: + example: + - data_source: metrics + name: query1 + query: sum:trace.servlet.request.hits{!http.status_code:500} by {env}.as_count() + - data_source: metrics + name: query2 + query: sum:trace.servlet.request.hits{http.status_code:500} by {env}.as_count() items: $ref: '#/components/schemas/SLODataSourceQueryDefinition' minItems: 1 type: array total_events_formula: $ref: '#/components/schemas/SLOFormula' + description: The total events formula. Bad events queries can be defined + using the `bad_events_formula` field as an alternative. Only one of `total_events_formula` + or `bad_events_formula` must be provided. required: - good_events_formula - total_events_formula @@ -12375,15 +12415,15 @@ components: description: A metric SLI specification. example: count: - good_events_formula: query1 - query2 + bad_events_formula: query2 + good_events_formula: query1 queries: - data_source: metrics name: query1 - query: sum:trace.servlet.request.hits{*} by {env}.as_count() + query: sum:trace.servlet.request.hits{!http.status_code:500} by {env}.as_count() - data_source: metrics name: query2 - query: sum:trace.servlet.request.errors{*} by {env}.as_count() - total_events_formula: query1 + query: sum:trace.servlet.request.hits{http.status_code:500} by {env}.as_count() properties: count: $ref: '#/components/schemas/SLOCountDefinition' @@ -13519,7 +13559,7 @@ components: name: query1 query: sum:trace.servlet.request.hits{*} by {env}.as_count() - data_source: metrics - name: query1 + name: query2 query: sum:trace.servlet.request.errors{*} by {env}.as_count() threshold: 5 properties: diff --git a/docs/datadog_api_client.v1.model.rst b/docs/datadog_api_client.v1.model.rst index 707acb5bc9..302fcc242a 100644 --- a/docs/datadog_api_client.v1.model.rst +++ b/docs/datadog_api_client.v1.model.rst @@ -3917,6 +3917,20 @@ datadog\_api\_client.v1.model.slo\_count\_definition module :members: :show-inheritance: +datadog\_api\_client.v1.model.slo\_count\_definition\_with\_bad\_events\_formula module +--------------------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v1.model.slo_count_definition_with_bad_events_formula + :members: + :show-inheritance: + +datadog\_api\_client.v1.model.slo\_count\_definition\_with\_total\_events\_formula module +----------------------------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v1.model.slo_count_definition_with_total_events_formula + :members: + :show-inheritance: + datadog\_api\_client.v1.model.slo\_count\_spec module ----------------------------------------------------- diff --git a/examples/v1/service-level-objectives/CreateSLO_512760759.py b/examples/v1/service-level-objectives/CreateSLO_512760759.py index 6fa6cef618..519b45fbbc 100644 --- a/examples/v1/service-level-objectives/CreateSLO_512760759.py +++ b/examples/v1/service-level-objectives/CreateSLO_512760759.py @@ -9,7 +9,9 @@ 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_definition_with_total_events_formula import ( + SLOCountDefinitionWithTotalEventsFormula, +) 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 @@ -21,7 +23,7 @@ description="Metric SLO using sli_specification", name="Example-Service-Level-Objective", sli_specification=SLOCountSpec( - count=SLOCountDefinition( + count=SLOCountDefinitionWithTotalEventsFormula( good_events_formula=SLOFormula( formula="query1 - query2", ), diff --git a/examples/v1/service-level-objectives/CreateSLO_707861409.py b/examples/v1/service-level-objectives/CreateSLO_707861409.py new file mode 100644 index 0000000000..8bec99a352 --- /dev/null +++ b/examples/v1/service-level-objectives/CreateSLO_707861409.py @@ -0,0 +1,70 @@ +""" +Create a new metric SLO object using bad events formula 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_with_bad_events_formula import ( + SLOCountDefinitionWithBadEventsFormula, +) +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=SLOCountDefinitionWithBadEventsFormula( + good_events_formula=SLOFormula( + formula="query1 - query2", + ), + bad_events_formula=SLOFormula( + formula="query2", + ), + 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/slo_count_definition.py b/src/datadog_api_client/v1/model/slo_count_definition.py index 2011e9bfcd..dbb54040e6 100644 --- a/src/datadog_api_client/v1/model/slo_count_definition.py +++ b/src/datadog_api_client/v1/model/slo_count_definition.py @@ -3,56 +3,19 @@ # Copyright 2019-Present Datadog, Inc. from __future__ import annotations -from typing import List, Union, TYPE_CHECKING from datadog_api_client.model_utils import ( - ModelNormal, + ModelComposed, 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, - ): +class SLOCountDefinition(ModelComposed): + def __init__(self, **kwargs): """ - A count-based (metric) SLI specification, composed of three parts: the good events formula, the total events formula, - and the underlying queries. + A count-based (metric) SLI specification, composed of three parts: the good events formula, + the bad or total events formula, and the underlying queries. + Exactly one of ``total_events_formula`` or ``bad_events_formula`` must be provided. :param good_events_formula: A formula that specifies how to combine the results of multiple queries. :type good_events_formula: SLOFormula @@ -62,9 +25,31 @@ def __init__( :param total_events_formula: A formula that specifies how to combine the results of multiple queries. :type total_events_formula: SLOFormula + + :param bad_events_formula: A formula that specifies how to combine the results of multiple queries. + :type bad_events_formula: SLOFormula """ super().__init__(kwargs) - self_.good_events_formula = good_events_formula - self_.queries = queries - self_.total_events_formula = total_events_formula + @cached_property + def _composed_schemas(_): + # we need this here to make our import statements work + # we must store _composed_schemas in here so the code is only run + # when we invoke this method. If we kept this at the class + # level we would get an error because the class level + # code would be run when this module is imported, and these composed + # classes don't exist yet because their module has not finished + # loading + from datadog_api_client.v1.model.slo_count_definition_with_total_events_formula import ( + SLOCountDefinitionWithTotalEventsFormula, + ) + from datadog_api_client.v1.model.slo_count_definition_with_bad_events_formula import ( + SLOCountDefinitionWithBadEventsFormula, + ) + + return { + "oneOf": [ + SLOCountDefinitionWithTotalEventsFormula, + SLOCountDefinitionWithBadEventsFormula, + ], + } diff --git a/src/datadog_api_client/v1/model/slo_count_definition_with_bad_events_formula.py b/src/datadog_api_client/v1/model/slo_count_definition_with_bad_events_formula.py new file mode 100644 index 0000000000..fc51fb5afc --- /dev/null +++ b/src/datadog_api_client/v1/model/slo_count_definition_with_bad_events_formula.py @@ -0,0 +1,73 @@ +# 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 SLOCountDefinitionWithBadEventsFormula(ModelNormal): + validations = { + "queries": { + "min_items": 1, + }, + } + + @cached_property + def additional_properties_type(_): + return None + + @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 { + "bad_events_formula": (SLOFormula,), + "good_events_formula": (SLOFormula,), + "queries": ([SLODataSourceQueryDefinition],), + } + + attribute_map = { + "bad_events_formula": "bad_events_formula", + "good_events_formula": "good_events_formula", + "queries": "queries", + } + + def __init__( + self_, + bad_events_formula: SLOFormula, + good_events_formula: SLOFormula, + queries: List[Union[SLODataSourceQueryDefinition, FormulaAndFunctionMetricQueryDefinition]], + **kwargs, + ): + """ + + + :param bad_events_formula: A formula that specifies how to combine the results of multiple queries. + :type bad_events_formula: SLOFormula + + :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] + """ + super().__init__(kwargs) + + self_.bad_events_formula = bad_events_formula + self_.good_events_formula = good_events_formula + self_.queries = queries diff --git a/src/datadog_api_client/v1/model/slo_count_definition_with_total_events_formula.py b/src/datadog_api_client/v1/model/slo_count_definition_with_total_events_formula.py new file mode 100644 index 0000000000..5267007847 --- /dev/null +++ b/src/datadog_api_client/v1/model/slo_count_definition_with_total_events_formula.py @@ -0,0 +1,73 @@ +# 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 SLOCountDefinitionWithTotalEventsFormula(ModelNormal): + validations = { + "queries": { + "min_items": 1, + }, + } + + @cached_property + def additional_properties_type(_): + return None + + @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, + ): + """ + + + :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 index 72f4a6aec6..36834e6eeb 100644 --- a/src/datadog_api_client/v1/model/slo_count_spec.py +++ b/src/datadog_api_client/v1/model/slo_count_spec.py @@ -3,7 +3,7 @@ # Copyright 2019-Present Datadog, Inc. from __future__ import annotations -from typing import TYPE_CHECKING +from typing import Union, TYPE_CHECKING from datadog_api_client.model_utils import ( ModelNormal, @@ -13,6 +13,12 @@ if TYPE_CHECKING: from datadog_api_client.v1.model.slo_count_definition import SLOCountDefinition + from datadog_api_client.v1.model.slo_count_definition_with_total_events_formula import ( + SLOCountDefinitionWithTotalEventsFormula, + ) + from datadog_api_client.v1.model.slo_count_definition_with_bad_events_formula import ( + SLOCountDefinitionWithBadEventsFormula, + ) class SLOCountSpec(ModelNormal): @@ -32,12 +38,19 @@ def openapi_types(_): "count": "count", } - def __init__(self_, count: SLOCountDefinition, **kwargs): + def __init__( + self_, + count: Union[ + SLOCountDefinition, SLOCountDefinitionWithTotalEventsFormula, SLOCountDefinitionWithBadEventsFormula + ], + **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. + :param count: A count-based (metric) SLI specification, composed of three parts: the good events formula, + the bad or total events formula, and the underlying queries. + Exactly one of ``total_events_formula`` or ``bad_events_formula`` must be provided. :type count: SLOCountDefinition """ super().__init__(kwargs) 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 671827072d..ca934f8568 100644 --- a/src/datadog_api_client/v1/model/slo_sli_spec.py +++ b/src/datadog_api_client/v1/model/slo_sli_spec.py @@ -19,8 +19,9 @@ def __init__(self, **kwargs): 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. + :param count: A count-based (metric) SLI specification, composed of three parts: the good events formula, + the bad or total events formula, and the underlying queries. + Exactly one of `total_events_formula` or `bad_events_formula` must be provided. :type count: SLOCountDefinition """ super().__init__(kwargs) diff --git a/src/datadog_api_client/v1/models/__init__.py b/src/datadog_api_client/v1/models/__init__.py index 2220d357ae..f0e1e5da75 100644 --- a/src/datadog_api_client/v1/models/__init__.py +++ b/src/datadog_api_client/v1/models/__init__.py @@ -616,6 +616,12 @@ 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_definition_with_bad_events_formula import ( + SLOCountDefinitionWithBadEventsFormula, +) +from datadog_api_client.v1.model.slo_count_definition_with_total_events_formula import ( + SLOCountDefinitionWithTotalEventsFormula, +) 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 @@ -1710,6 +1716,8 @@ "SLOCorrectionUpdateRequest", "SLOCorrectionUpdateRequestAttributes", "SLOCountDefinition", + "SLOCountDefinitionWithBadEventsFormula", + "SLOCountDefinitionWithTotalEventsFormula", "SLOCountSpec", "SLOCreator", "SLODataSourceQueryDefinition", diff --git a/tests/v1/cassettes/test_scenarios/test_create_a_new_metric_slo_object_using_bad_events_formula_returns_ok_response.frozen b/tests/v1/cassettes/test_scenarios/test_create_a_new_metric_slo_object_using_bad_events_formula_returns_ok_response.frozen new file mode 100644 index 0000000000..b1ab9b0945 --- /dev/null +++ b/tests/v1/cassettes/test_scenarios/test_create_a_new_metric_slo_object_using_bad_events_formula_returns_ok_response.frozen @@ -0,0 +1 @@ +2026-02-25T17:45:38.518Z \ No newline at end of file diff --git a/tests/v1/cassettes/test_scenarios/test_create_a_new_metric_slo_object_using_bad_events_formula_returns_ok_response.yaml b/tests/v1/cassettes/test_scenarios/test_create_a_new_metric_slo_object_using_bad_events_formula_returns_ok_response.yaml new file mode 100644 index 0000000000..667940032a --- /dev/null +++ b/tests/v1/cassettes/test_scenarios/test_create_a_new_metric_slo_object_using_bad_events_formula_returns_ok_response.yaml @@ -0,0 +1,46 @@ +interactions: +- request: + body: '{"description":"Metric SLO using sli_specification","name":"Test-Create_a_new_metric_SLO_object_using_bad_events_formula_returns_OK_response-1772041538","sli_specification":{"count":{"bad_events_formula":{"formula":"query2"},"good_events_formula":{"formula":"query1 + - query2"},"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"],"target_threshold":99,"thresholds":[{"target":99,"target_display":"99.0","timeframe":"7d","warning":99.5,"warning_display":"99.5"}],"timeframe":"7d","type":"metric","warning_threshold":99.5}' + headers: + accept: + - application/json + content-type: + - application/json + method: POST + uri: https://api.datadoghq.com/api/v1/slo + response: + body: + string: '{"data":[{"id":"7309ff3752fd519f80f65a2ed3247dbb","name":"Test-Create_a_new_metric_SLO_object_using_bad_events_formula_returns_OK_response-1772041538","tags":["env:prod","type:count"],"monitor_tags":[],"thresholds":[{"timeframe":"7d","target":99.0,"target_display":"99.","warning":99.5,"warning_display":"99.5"}],"type":"metric","type_id":1,"description":"Metric + SLO using sli_specification","timeframe":"7d","warning_threshold":99.5,"target_threshold":99,"query":{"numerator":"sum:httpservice.hits{*}.as_count() + - sum:httpservice.errors{*}.as_count()","denominator":"(sum:httpservice.hits{*}.as_count() + - sum:httpservice.errors{*}.as_count()) + (sum:httpservice.errors{*}.as_count())"},"creator":{"name":"CI + Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","email":"team-intg-tools-libs-spam@datadoghq.com"},"created_at":1772041538,"modified_at":1772041538,"sli_specification":{"count":{"bad_events_formula":{"formula":"query2"},"good_events_formula":{"formula":"query1 + - query2"},"queries":[{"data_source":"metrics","name":"query1","query":"sum:httpservice.hits{*}.as_count()"},{"data_source":"metrics","name":"query2","query":"sum:httpservice.errors{*}.as_count()"}]}}}],"error":null} + + ' + 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/slo/7309ff3752fd519f80f65a2ed3247dbb + response: + body: + string: '{"data":["7309ff3752fd519f80f65a2ed3247dbb"],"error":null} + + ' + headers: + content-type: + - application/json + status: + code: 200 + message: OK +version: 1 diff --git a/tests/v1/features/service_level_objectives.feature b/tests/v1/features/service_level_objectives.feature index 22c9d6cd3f..6e756c5a54 100644 --- a/tests/v1/features/service_level_objectives.feature +++ b/tests/v1/features/service_level_objectives.feature @@ -48,6 +48,19 @@ 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 bad events formula 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"},"bad_events_formula":{"formula":"query2"},"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]" 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 "bad_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 + @team:DataDog/slo-app Scenario: Create a new metric SLO object using sli_specification returns "OK" response Given new "CreateSLO" request @@ -247,7 +260,7 @@ Feature: Service Level Objectives Scenario: Update an SLO returns "Not Found" response Given new "UpdateSLO" request And request contains "slo_id" parameter from "REPLACE.ME" - And body with value {"description": null, "groups": ["env:prod", "role:mysql"], "monitor_ids": [], "monitor_tags": [], "name": "Custom Metric SLO", "query": {"denominator": "sum:my.custom.metric{*}.as_count()", "numerator": "sum:my.custom.metric{type:good}.as_count()"}, "sli_specification": {"time_slice": {"comparator": "<", "query": {"formulas": [{"formula": "query2/query1"}], "queries": [{"data_source": "metrics", "name": "query1", "query": "sum:trace.servlet.request.hits{*} by {env}.as_count()"}, {"data_source": "metrics", "name": "query1", "query": "sum:trace.servlet.request.errors{*} by {env}.as_count()"}]}, "threshold": 5}}, "tags": ["env:prod", "app:core"], "target_threshold": 99.9, "thresholds": [{"target": 95, "timeframe": "7d"}, {"target": 95, "timeframe": "30d", "warning": 97}], "timeframe": "30d", "type": "metric", "warning_threshold": 99.95} + And body with value {"description": null, "groups": ["env:prod", "role:mysql"], "monitor_ids": [], "monitor_tags": [], "name": "Custom Metric SLO", "query": {"denominator": "sum:my.custom.metric{*}.as_count()", "numerator": "sum:my.custom.metric{type:good}.as_count()"}, "sli_specification": {"time_slice": {"comparator": "<", "query": {"formulas": [{"formula": "query2/query1"}], "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()"}]}, "threshold": 5}}, "tags": ["env:prod", "app:core"], "target_threshold": 99.9, "thresholds": [{"target": 95, "timeframe": "7d"}, {"target": 95, "timeframe": "30d", "warning": 97}], "timeframe": "30d", "type": "metric", "warning_threshold": 99.95} When the request is sent Then the response status is 404 Not Found