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
72 changes: 69 additions & 3 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions docs/datadog_api_client.v1.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------------------

Expand Down
68 changes: 68 additions & 0 deletions examples/v1/service-level-objectives/CreateSLO_512760759.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 5 additions & 4 deletions src/datadog_api_client/v1/model/service_level_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
70 changes: 70 additions & 0 deletions src/datadog_api_client/v1/model/slo_count_definition.py
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions src/datadog_api_client/v1/model/slo_count_spec.py
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading