Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public API support for time-slice SLOs #1813

Merged
Merged
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
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-01-04 15:18:08.876360",
"spec_repo_commit": "e7cfa56f"
"regenerated": "2024-01-05 15:09:31.771541",
"spec_repo_commit": "9cbf6566"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-01-04 15:18:08.899971",
"spec_repo_commit": "e7cfa56f"
"regenerated": "2024-01-05 15:09:31.789729",
"spec_repo_commit": "9cbf6566"
}
}
}
136 changes: 136 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10244,6 +10244,13 @@ components:
nullable: true
type: string
type: object
SLODataSourceQueryDefinition:
description: A formula and function query.
example:
data_source: metrics
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
oneOf:
- $ref: '#/components/schemas/FormulaAndFunctionMetricQueryDefinition'
SLODeleteResponse:
description: A response list of all service level objective deleted.
properties:
Expand Down Expand Up @@ -10287,6 +10294,20 @@ components:
- THIRTY_DAYS
- NINETY_DAYS
- ALL
SLOFormula:
description: A formula that specifies how to combine the results of multiple
queries.
example:
formula: query1 - default_zero(query2)
properties:
formula:
description: The formula string, which is an expression involving named
queries.
example: query1 - default_zero(query2)
type: string
required:
- formula
type: object
SLOHistoryMetrics:
description: 'A `metric` based SLO history response.

Expand Down Expand Up @@ -11016,6 +11037,8 @@ components:
type: string
query:
$ref: '#/components/schemas/ServiceLevelObjectiveQuery'
sli_specification:
$ref: '#/components/schemas/SLOSliSpec'
tags:
description: 'A list of tags associated with this service level objective.

Expand Down Expand Up @@ -11070,6 +11093,11 @@ components:
format: double
type: number
type: object
SLOSliSpec:
description: A generic SLI specification. This is currently used for time-slice
SLOs only.
oneOf:
- $ref: '#/components/schemas/SLOTimeSliceSpec'
SLOState:
description: State of the SLO.
enum:
Expand Down Expand Up @@ -11170,6 +11198,106 @@ components:
- timeframe
- target
type: object
SLOTimeSliceComparator:
description: The comparator used to compare the SLI value to the threshold.
enum:
- '>'
- '>='
- <
- <=
example: '>'
type: string
x-enum-varnames:
- GREATER
- GREATER_EQUAL
- LESS
- LESS_EQUAL
SLOTimeSliceCondition:
description: 'The time-slice condition, composed of 3 parts: 1. the metric timeseries
query, 2. the comparator,

and 3. the threshold.'
example:
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
properties:
comparator:
$ref: '#/components/schemas/SLOTimeSliceComparator'
query:
$ref: '#/components/schemas/SLOTimeSliceQuery'
threshold:
description: The threshold value to which each SLI value will be compared.
example: 5
format: double
type: number
required:
- comparator
- threshold
- query
type: object
SLOTimeSliceQuery:
description: The queries and formula used to calculate the SLI value.
example:
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()
properties:
formulas:
description: A list that contains exactly one formula, as only a single
formula may be used in a time-slice SLO.
items:
$ref: '#/components/schemas/SLOFormula'
maxItems: 1
minItems: 1
type: array
queries:
description: A list of queries that are used to calculate the SLI value.
items:
$ref: '#/components/schemas/SLODataSourceQueryDefinition'
type: array
required:
- formulas
- queries
type: object
SLOTimeSliceSpec:
additionalProperties: false
description: A time-slice SLI specification.
example:
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
properties:
time_slice:
$ref: '#/components/schemas/SLOTimeSliceCondition'
required:
- time_slice
type: object
SLOTimeframe:
description: The SLO time window options.
enum:
Expand All @@ -11189,11 +11317,13 @@ components:
enum:
- metric
- monitor
- time_slice
example: metric
type: string
x-enum-varnames:
- METRIC
- MONITOR
- TIME_SLICE
SLOTypeNumeric:
description: 'A numeric representation of the type of the service level objective
(`0` for
Expand All @@ -11204,12 +11334,14 @@ components:
enum:
- 0
- 1
- 2
example: 0
format: int32
type: integer
x-enum-varnames:
- MONITOR
- METRIC
- TIME_SLICE
SLOWidgetDefinition:
description: Use the SLO and uptime widget to track your SLOs (Service Level
Objectives) and uptime on screenboards and timeboards.
Expand Down Expand Up @@ -12019,6 +12151,8 @@ components:
type: string
query:
$ref: '#/components/schemas/ServiceLevelObjectiveQuery'
sli_specification:
$ref: '#/components/schemas/SLOSliSpec'
tags:
description: 'A list of tags associated with this service level objective.

Expand Down Expand Up @@ -12148,6 +12282,8 @@ components:
type: string
query:
$ref: '#/components/schemas/ServiceLevelObjectiveQuery'
sli_specification:
$ref: '#/components/schemas/SLOSliSpec'
tags:
description: 'A list of tags associated with this service level objective.

Expand Down
49 changes: 49 additions & 0 deletions docs/datadog_api_client.v1.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,13 @@ slo\_creator
:members:
:show-inheritance:

slo\_data\_source\_query\_definition
------------------------------------

.. automodule:: datadog_api_client.v1.model.slo_data_source_query_definition
:members:
:show-inheritance:

slo\_delete\_response
---------------------

Expand All @@ -3354,6 +3361,13 @@ slo\_error\_timeframe
:members:
:show-inheritance:

slo\_formula
------------

.. automodule:: datadog_api_client.v1.model.slo_formula
:members:
:show-inheritance:

slo\_history\_metrics
---------------------

Expand Down Expand Up @@ -3508,6 +3522,13 @@ slo\_response\_data
:members:
:show-inheritance:

slo\_sli\_spec
--------------

.. automodule:: datadog_api_client.v1.model.slo_sli_spec
:members:
:show-inheritance:

slo\_state
----------

Expand All @@ -3529,6 +3550,34 @@ slo\_threshold
:members:
:show-inheritance:

slo\_time\_slice\_comparator
----------------------------

.. automodule:: datadog_api_client.v1.model.slo_time_slice_comparator
:members:
:show-inheritance:

slo\_time\_slice\_condition
---------------------------

.. automodule:: datadog_api_client.v1.model.slo_time_slice_condition
:members:
:show-inheritance:

slo\_time\_slice\_query
-----------------------

.. automodule:: datadog_api_client.v1.model.slo_time_slice_query
:members:
:show-inheritance:

slo\_time\_slice\_spec
----------------------

.. automodule:: datadog_api_client.v1.model.slo_time_slice_spec
:members:
:show-inheritance:

slo\_timeframe
--------------

Expand Down
67 changes: 67 additions & 0 deletions examples/v1/service-level-objectives/CreateSLO_3765703239.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Create a time-slice SLO object 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_formula import SLOFormula
from datadog_api_client.v1.model.slo_threshold import SLOThreshold
from datadog_api_client.v1.model.slo_time_slice_comparator import SLOTimeSliceComparator
from datadog_api_client.v1.model.slo_time_slice_condition import SLOTimeSliceCondition
from datadog_api_client.v1.model.slo_time_slice_query import SLOTimeSliceQuery
from datadog_api_client.v1.model.slo_time_slice_spec import SLOTimeSliceSpec
from datadog_api_client.v1.model.slo_timeframe import SLOTimeframe
from datadog_api_client.v1.model.slo_type import SLOType

body = ServiceLevelObjectiveRequest(
type=SLOType.TIME_SLICE,
description="string",
name="Example-Service-Level-Objective",
sli_specification=SLOTimeSliceSpec(
time_slice=SLOTimeSliceCondition(
query=SLOTimeSliceQuery(
formulas=[
SLOFormula(
formula="query1",
),
],
queries=[
FormulaAndFunctionMetricQueryDefinition(
data_source=FormulaAndFunctionMetricDataSource.METRICS,
name="query1",
query="trace.servlet.request{env:prod}",
),
],
),
comparator=SLOTimeSliceComparator.GREATER,
threshold=5.0,
),
),
tags=[
"env:prod",
],
thresholds=[
SLOThreshold(
target=97.0,
target_display="97.0",
timeframe=SLOTimeframe.SEVEN_DAYS,
warning=98.0,
warning_display="98.0",
),
],
timeframe=SLOTimeframe.SEVEN_DAYS,
target_threshold=97.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)
Loading
Loading