Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11902,10 +11902,10 @@ components:
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.'
the good events formula, the bad or total events formula, and the underlying
queries.'
example:
bad_events_formula: query2
good_events_formula: query1 - query2
queries:
- data_source: metrics
Expand All @@ -11914,8 +11914,11 @@ components:
- data_source: metrics
name: query2
query: sum:trace.servlet.request.errors{*} by {env}.as_count()
total_events_formula: query1
properties:
bad_events_formula:
$ref: '#/components/schemas/SLOFormula'
description: The bad events formula (recommended). Alternatively, total
events can be defined by the `total_events_formula` field instead.
good_events_formula:
$ref: '#/components/schemas/SLOFormula'
queries:
Expand All @@ -11929,16 +11932,18 @@ components:
type: array
total_events_formula:
$ref: '#/components/schemas/SLOFormula'
description: '"The total events formula. Alternatively, bad events can be
defined by the `bad_events_formula` field instead.'
required:
- good_events_formula
- total_events_formula
- queries
type: object
SLOCountSpec:
additionalProperties: false
description: A metric SLI specification.
example:
count:
bad_events_formula: query2
good_events_formula: query1 - query2
queries:
- data_source: metrics
Expand All @@ -11947,7 +11952,6 @@ components:
- 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'
Expand Down
68 changes: 68 additions & 0 deletions examples/v1/service-level-objectives/CreateSLO_707861409.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
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 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",
),
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)
20 changes: 15 additions & 5 deletions src/datadog_api_client/v1/model/slo_count_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


Expand All @@ -32,12 +34,14 @@ def openapi_types(_):
from datadog_api_client.v1.model.slo_data_source_query_definition import SLODataSourceQueryDefinition

return {
"bad_events_formula": (SLOFormula,),
"good_events_formula": (SLOFormula,),
"queries": ([SLODataSourceQueryDefinition],),
"total_events_formula": (SLOFormula,),
}

attribute_map = {
"bad_events_formula": "bad_events_formula",
"good_events_formula": "good_events_formula",
"queries": "queries",
"total_events_formula": "total_events_formula",
Expand All @@ -47,12 +51,15 @@ def __init__(
self_,
good_events_formula: SLOFormula,
queries: List[Union[SLODataSourceQueryDefinition, FormulaAndFunctionMetricQueryDefinition]],
total_events_formula: SLOFormula,
bad_events_formula: Union[SLOFormula, UnsetType] = unset,
total_events_formula: Union[SLOFormula, UnsetType] = unset,
**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.

:param bad_events_formula: A formula that specifies how to combine the results of multiple queries.
:type bad_events_formula: SLOFormula, optional

:param good_events_formula: A formula that specifies how to combine the results of multiple queries.
:type good_events_formula: SLOFormula
Expand All @@ -61,10 +68,13 @@ def __init__(
:type queries: [SLODataSourceQueryDefinition]

:param total_events_formula: A formula that specifies how to combine the results of multiple queries.
:type total_events_formula: SLOFormula
:type total_events_formula: SLOFormula, optional
"""
if bad_events_formula is not unset:
kwargs["bad_events_formula"] = bad_events_formula
if total_events_formula is not unset:
kwargs["total_events_formula"] = total_events_formula
super().__init__(kwargs)

self_.good_events_formula = good_events_formula
self_.queries = queries
self_.total_events_formula = total_events_formula
3 changes: 1 addition & 2 deletions src/datadog_api_client/v1/model/slo_count_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ 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.
: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.
:type count: SLOCountDefinition
"""
super().__init__(kwargs)
Expand Down
3 changes: 1 addition & 2 deletions src/datadog_api_client/v1/model/slo_sli_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ 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.
:type count: SLOCountDefinition
"""
super().__init__(kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2026-02-25T17:45:38.518Z
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/v1/features/service_level_objectives.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2026-02-18T16:57:05.121Z
2026-01-07T12:38:45.716Z
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ interactions:
uri: https://api.datadoghq.com/api/v2/synthetics/suites
response:
body:
string: '{"data":{"type":"suites","attributes":{"type":"suite","monitor_id":259845717,"name":"Example
suite name","options":{},"tests":[],"tags":["env:production"],"public_id":"hik-xp5-9q6","created_at":"2026-02-18T16:57:05.583051+00:00","modified_at":"2026-02-18T16:57:05.583051+00:00","created_by":{"name":"Corentin
Girard","email":"corentin.girard@datadoghq.com","handle":"corentin.girard@datadoghq.com"},"message":"Notification
message","org_id":321813,"modified_by":{"name":"Corentin Girard","email":"corentin.girard@datadoghq.com","handle":"corentin.girard@datadoghq.com"}},"id":"hik-xp5-9q6"}}
string: '{"data":{"type":"suites","id":"36n-bb6-njj","attributes":{"tags":["env:production"],"type":"suite","created_by":{"email":"team-intg-tools-libs-spam@datadoghq.com","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","name":"CI
Account"},"created_at":"2026-01-07T12:38:46.109472+00:00","modified_at":"2026-01-07T12:38:46.109472+00:00","message":"Notification
message","public_id":"36n-bb6-njj","options":{},"modified_by":{"email":"team-intg-tools-libs-spam@datadoghq.com","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","name":"CI
Account"},"tests":[],"name":"Example suite name","org_id":321813,"monitor_id":249141773}}}

'
headers:
Expand All @@ -24,7 +24,7 @@ interactions:
code: 200
message: OK
- request:
body: '{"data":{"attributes":{"public_ids":["hik-xp5-9q6"]},"type":"delete_suites_request"}}'
body: '{"data":{"attributes":{"public_ids":["36n-bb6-njj"]},"type":"delete_suites_request"}}'
headers:
accept:
- application/json
Expand All @@ -34,7 +34,8 @@ interactions:
uri: https://api.datadoghq.com/api/v2/synthetics/suites/bulk-delete
response:
body:
string: '{"data":[{"type":"suites","attributes":{"deleted_at":"2026-02-18 16:57:06.420679","public_id":"hik-xp5-9q6"},"id":"hik-xp5-9q6"}]}
string: '{"data":[{"type":"suites","attributes":{"public_id":"36n-bb6-njj","deleted_at":"2026-01-07
12:38:46.679914"},"id":"36n-bb6-njj"}]}

'
headers:
Expand Down