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
64 changes: 52 additions & 12 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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:
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 @@ -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
-----------------------------------------------------

Expand Down
6 changes: 4 additions & 2 deletions examples/v1/service-level-objectives/CreateSLO_512760759.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
),
Expand Down
70 changes: 70 additions & 0 deletions examples/v1/service-level-objectives/CreateSLO_707861409.py
Original file line number Diff line number Diff line change
@@ -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)
77 changes: 31 additions & 46 deletions src/datadog_api_client/v1/model/slo_count_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
],
}
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading