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
62 changes: 57 additions & 5 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11409,6 +11409,60 @@ components:
example: UTC
type: string
type: object
SLOCountCondition:
description: 'A count-based SLI specification, composed of three parts: the
good events formula, the total events formula,

and the involved queries.'
example:
good_events_formula: query1 - query2
queries:
- data_source: metrics
name: query1
query: sum:trace.servlet.request.success{*} by {env}.as_count()
- data_source: metrics
name: query2
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
total_events_formula: query2
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 count-based SLI specification.
example:
count:
good_events_formula: query1 - query2
queries:
- data_source: metrics
name: query1
query: sum:trace.servlet.request.success{*} by {env}.as_count()
- data_source: metrics
name: query2
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
total_events_formula: query2
properties:
count:
$ref: '#/components/schemas/SLOCountCondition'
required:
- count
type: object
SLOCreator:
description: The creator of the SLO
nullable: true
Expand Down Expand Up @@ -12295,8 +12349,6 @@ components:
type: array
timeframe:
$ref: '#/components/schemas/SLOTimeframe'
type:
$ref: '#/components/schemas/SLOType'
warning_threshold:
description: 'The optional warning threshold such that when the service
level indicator is
Expand All @@ -12314,9 +12366,10 @@ components:
type: object
SLOSliSpec:
description: A generic SLI specification. This is currently used for time-slice
SLOs only.
and count-based SLOs only.
oneOf:
- $ref: '#/components/schemas/SLOTimeSliceSpec'
- $ref: '#/components/schemas/SLOCountSpec'
SLOState:
description: State of the SLO.
enum:
Expand Down Expand Up @@ -13468,8 +13521,7 @@ components:
- type
type: object
ServiceLevelObjectiveQuery:
description: 'A metric-based SLO. **Required if type is `metric`**. Note that
Datadog only allows the sum by aggregator
description: 'A metric-based SLO. 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
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 @@ -3644,6 +3644,20 @@ datadog\_api\_client.v1.model.slo\_correction\_update\_request\_attributes modul
:members:
:show-inheritance:

datadog\_api\_client.v1.model.slo\_count\_condition module
----------------------------------------------------------

.. automodule:: datadog_api_client.v1.model.slo_count_condition
: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_condition import SLOCountCondition
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=SLOCountCondition(
good_events_formula=SLOFormula(
formula="query1",
),
total_events_formula=SLOFormula(
formula="query2",
),
queries=[
FormulaAndFunctionMetricQueryDefinition(
data_source=FormulaAndFunctionMetricDataSource.METRICS,
name="query1",
query="sum:httpservice.success{*}.as_count()",
),
FormulaAndFunctionMetricQueryDefinition(
data_source=FormulaAndFunctionMetricDataSource.METRICS,
name="query2",
query="sum:httpservice.hits{*}.as_count()",
),
],
),
),
tags=[
"env:prod",
"type:count",
],
thresholds=[
SLOThreshold(
target=99.0,
target_display="99.0",
timeframe=SLOTimeframe.SEVEN_DAYS,
warning=98.0,
warning_display="98.0",
),
],
timeframe=SLOTimeframe.SEVEN_DAYS,
target_threshold=99.0,
warning_threshold=98.0,
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = ServiceLevelObjectivesApi(api_client)
response = api_instance.create_slo(body=body)

print(response)
7 changes: 4 additions & 3 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 metric-based SLO. 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.
: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 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,7 +25,7 @@ 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 metric-based SLO. 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.

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 metric-based SLO. 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.
: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 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_condition.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 SLOCountCondition(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 SLI specification, composed of three parts: the good events formula, the total events formula,
and the involved queries.

: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_condition import SLOCountCondition


class SLOCountSpec(ModelNormal):
@cached_property
def additional_properties_type(_):
return None

@cached_property
def openapi_types(_):
from datadog_api_client.v1.model.slo_count_condition import SLOCountCondition

return {
"count": (SLOCountCondition,),
}

attribute_map = {
"count": "count",
}

def __init__(self_, count: SLOCountCondition, **kwargs):
"""
A count-based SLI specification.

:param count: A count-based SLI specification, composed of three parts: the good events formula, the total events formula,
and the involved queries.
:type count: SLOCountCondition
"""
super().__init__(kwargs)

self_.count = count
Loading
Loading