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
49 changes: 49 additions & 0 deletions examples/v1/service-level-objectives/CreateSLO_512760759.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Create a new metric SLO object using sli_specification returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V1::ServiceLevelObjectivesAPI.new

body = DatadogAPIClient::V1::ServiceLevelObjectiveRequest.new({
type: DatadogAPIClient::V1::SLOType::METRIC,
description: "Metric SLO using sli_specification",
name: "Example-Service-Level-Objective",
sli_specification: DatadogAPIClient::V1::SLOCountSpec.new({
count: DatadogAPIClient::V1::SLOCountCondition.new({
good_events_formula: DatadogAPIClient::V1::SLOFormula.new({
formula: "query1",
}),
total_events_formula: DatadogAPIClient::V1::SLOFormula.new({
formula: "query2",
}),
queries: [
DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({
data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS,
name: "query1",
query: "sum:httpservice.success{*}.as_count()",
}),
DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({
data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS,
name: "query2",
query: "sum:httpservice.hits{*}.as_count()",
}),
],
}),
}),
tags: [
"env:prod",
"type:count",
],
thresholds: [
DatadogAPIClient::V1::SLOThreshold.new({
target: 99.0,
target_display: "99.0",
timeframe: DatadogAPIClient::V1::SLOTimeframe::SEVEN_DAYS,
warning: 98,
warning_display: "98.0",
}),
],
timeframe: DatadogAPIClient::V1::SLOTimeframe::SEVEN_DAYS,
target_threshold: 99.0,
warning_threshold: 98,
})
p api_instance.create_slo(body)
26 changes: 26 additions & 0 deletions features/v1/service_level_objectives.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ Feature: Service Level Objectives
When the request is sent
Then the response status is 200 OK

@team:DataDog/slo-app
Scenario: Create a metric SLO with both sli_specification and query returns "Bad Request" response
Given new "CreateSLO" request
And body with value {"type":"metric","description":"Invalid SLO with both sli_specification and query","name":"{{ unique }}","sli_specification":{"count":{"good_events_formula":{"formula":"query1"},"total_events_formula":{"formula":"query2"},"queries":[{"data_source":"metrics","name":"query1","query":"sum:httpservice.success{*}.as_count()"},{"data_source":"metrics","name":"query2","query":"sum:httpservice.hits{*}.as_count()"}]}},"query":{"numerator":"sum:httpservice.success{*}.as_count()","denominator":"sum:httpservice.hits{*}.as_count()"},"tags":["env:prod"],"thresholds":[{"target":99.0,"target_display":"99.0","timeframe":"7d","warning":98,"warning_display":"98.0"}],"timeframe":"7d","target_threshold":99.0,"warning_threshold":98}
When the request is sent
Then the response status is 400 Bad Request

@team:DataDog/slo-app
Scenario: Create a new metric SLO object using sli_specification 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"},"total_events_formula":{"formula":"query2"},"queries":[{"data_source":"metrics","name":"query1","query":"sum:httpservice.success{*}.as_count()"},{"data_source":"metrics","name":"query2","query":"sum:httpservice.hits{*}.as_count()"}]}},"tags":["env:prod","type:count"],"thresholds":[{"target":99.0,"target_display":"99.0","timeframe":"7d","warning":98,"warning_display":"98.0"}],"timeframe":"7d","target_threshold":99.0,"warning_threshold":98}
When the request is sent
Then the response status is 200 OK
And the response "data[0].timeframe" is equal to "7d"
And the response "data[0].target_threshold" is equal to 99.0
And the response "data[0].warning_threshold" is equal to 98.0
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 "total_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
And the response "data[0]" does not have field "query"

@team:DataDog/slo-app
Scenario: Create a time-slice SLO object returns "OK" response
Given new "CreateSLO" request
Expand All @@ -74,6 +98,8 @@ Feature: Service Level Objectives
And the response "data[0].timeframe" is equal to "7d"
And the response "data[0].target_threshold" is equal to 97.0
And the response "data[0].warning_threshold" is equal to 98.0
And the response "data[0]" has field "query"
And the response "data[0]" does not have field "sli_specification"

@generated @skip @team:DataDog/slo-app
Scenario: Delete an SLO returns "Conflict" response
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog_api_client/inflector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ def overrides
"v1.slo_correction_update_data" => "SLOCorrectionUpdateData",
"v1.slo_correction_update_request" => "SLOCorrectionUpdateRequest",
"v1.slo_correction_update_request_attributes" => "SLOCorrectionUpdateRequestAttributes",
"v1.slo_count_condition" => "SLOCountCondition",
"v1.slo_count_spec" => "SLOCountSpec",
"v1.slo_creator" => "SLOCreator",
"v1.slo_data_source_query_definition" => "SLODataSourceQueryDefinition",
"v1.slo_delete_response" => "SLODeleteResponse",
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog_api_client/v1/models/service_level_objective.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class ServiceLevelObjective
# The name of the service level objective object.
attr_reader :name

# 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.
attr_accessor :query

# A generic SLI specification. This is currently used for time-slice SLOs only.
# A generic SLI specification. This is currently used for time-slice and count-based SLOs only.
attr_accessor :sli_specification

# A list of tags associated with this service level objective.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require 'time'

module DatadogAPIClient::V1
# 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.
class ServiceLevelObjectiveQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class ServiceLevelObjectiveRequest
# The name of the service level objective object.
attr_reader :name

# 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.
attr_accessor :query

# A generic SLI specification. This is currently used for time-slice SLOs only.
# A generic SLI specification. This is currently used for time-slice and count-based SLOs only.
attr_accessor :sli_specification

# A list of tags associated with this service level objective.
Expand Down
Loading
Loading