Skip to content

Commit 2c2e877

Browse files
author
ci.datadog-api-spec
committed
Regenerate client from commit 2aab4b8 of spec repo
1 parent 2a3879e commit 2c2e877

11 files changed

+360
-38
lines changed

.generator/schemas/v1/openapi.yaml

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11409,6 +11409,60 @@ components:
1140911409
example: UTC
1141011410
type: string
1141111411
type: object
11412+
SLOCountCondition:
11413+
description: 'A count-based SLI specification, composed of three parts: the
11414+
good events formula, the total events formula,
11415+
11416+
and the involved queries.'
11417+
example:
11418+
good_events_formula: query1 - query2
11419+
queries:
11420+
- data_source: metrics
11421+
name: query1
11422+
query: sum:trace.servlet.request.success{*} by {env}.as_count()
11423+
- data_source: metrics
11424+
name: query2
11425+
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
11426+
total_events_formula: query2
11427+
properties:
11428+
good_events_formula:
11429+
$ref: '#/components/schemas/SLOFormula'
11430+
queries:
11431+
example:
11432+
- data_source: metrics
11433+
name: query1
11434+
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
11435+
items:
11436+
$ref: '#/components/schemas/SLODataSourceQueryDefinition'
11437+
minItems: 1
11438+
type: array
11439+
total_events_formula:
11440+
$ref: '#/components/schemas/SLOFormula'
11441+
required:
11442+
- good_events_formula
11443+
- total_events_formula
11444+
- queries
11445+
type: object
11446+
SLOCountSpec:
11447+
additionalProperties: false
11448+
description: A count-based SLI specification.
11449+
example:
11450+
count:
11451+
good_events_formula: query1 - query2
11452+
queries:
11453+
- data_source: metrics
11454+
name: query1
11455+
query: sum:trace.servlet.request.success{*} by {env}.as_count()
11456+
- data_source: metrics
11457+
name: query2
11458+
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
11459+
total_events_formula: query2
11460+
properties:
11461+
count:
11462+
$ref: '#/components/schemas/SLOCountCondition'
11463+
required:
11464+
- count
11465+
type: object
1141211466
SLOCreator:
1141311467
description: The creator of the SLO
1141411468
nullable: true
@@ -12295,8 +12349,6 @@ components:
1229512349
type: array
1229612350
timeframe:
1229712351
$ref: '#/components/schemas/SLOTimeframe'
12298-
type:
12299-
$ref: '#/components/schemas/SLOType'
1230012352
warning_threshold:
1230112353
description: 'The optional warning threshold such that when the service
1230212354
level indicator is
@@ -12314,9 +12366,10 @@ components:
1231412366
type: object
1231512367
SLOSliSpec:
1231612368
description: A generic SLI specification. This is currently used for time-slice
12317-
SLOs only.
12369+
and count-based SLOs only.
1231812370
oneOf:
1231912371
- $ref: '#/components/schemas/SLOTimeSliceSpec'
12372+
- $ref: '#/components/schemas/SLOCountSpec'
1232012373
SLOState:
1232112374
description: State of the SLO.
1232212375
enum:
@@ -13468,8 +13521,7 @@ components:
1346813521
- type
1346913522
type: object
1347013523
ServiceLevelObjectiveQuery:
13471-
description: 'A metric-based SLO. **Required if type is `metric`**. Note that
13472-
Datadog only allows the sum by aggregator
13524+
description: 'A metric-based SLO. Note that Datadog only allows the sum by aggregator
1347313525

1347413526
to be used because this will sum up all request counts instead of averaging
1347513527
them, or taking the max or
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Create a new metric SLO object using sli_specification returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV1::api_service_level_objectives::ServiceLevelObjectivesAPI;
4+
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
5+
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
6+
use datadog_api_client::datadogV1::model::SLOCountCondition;
7+
use datadog_api_client::datadogV1::model::SLOCountSpec;
8+
use datadog_api_client::datadogV1::model::SLODataSourceQueryDefinition;
9+
use datadog_api_client::datadogV1::model::SLOFormula;
10+
use datadog_api_client::datadogV1::model::SLOSliSpec;
11+
use datadog_api_client::datadogV1::model::SLOThreshold;
12+
use datadog_api_client::datadogV1::model::SLOTimeframe;
13+
use datadog_api_client::datadogV1::model::SLOType;
14+
use datadog_api_client::datadogV1::model::ServiceLevelObjectiveRequest;
15+
16+
#[tokio::main]
17+
async fn main() {
18+
let body = ServiceLevelObjectiveRequest::new(
19+
"Example-Service-Level-Objective".to_string(),
20+
vec![SLOThreshold::new(99.0, SLOTimeframe::SEVEN_DAYS)
21+
.target_display("99.0".to_string())
22+
.warning(98.0 as f64)
23+
.warning_display("98.0".to_string())],
24+
SLOType::METRIC,
25+
)
26+
.description(Some("Metric SLO using sli_specification".to_string()))
27+
.sli_specification(SLOSliSpec::SLOCountSpec(Box::new(SLOCountSpec::new(
28+
SLOCountCondition::new(
29+
SLOFormula::new("query1".to_string()),
30+
vec![
31+
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(Box::new(
32+
FormulaAndFunctionMetricQueryDefinition::new(
33+
FormulaAndFunctionMetricDataSource::METRICS,
34+
"query1".to_string(),
35+
"sum:httpservice.success{*}.as_count()".to_string(),
36+
),
37+
)),
38+
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(Box::new(
39+
FormulaAndFunctionMetricQueryDefinition::new(
40+
FormulaAndFunctionMetricDataSource::METRICS,
41+
"query2".to_string(),
42+
"sum:httpservice.hits{*}.as_count()".to_string(),
43+
),
44+
)),
45+
],
46+
SLOFormula::new("query2".to_string()),
47+
),
48+
))))
49+
.tags(vec!["env:prod".to_string(), "type:count".to_string()])
50+
.target_threshold(99.0 as f64)
51+
.timeframe(SLOTimeframe::SEVEN_DAYS)
52+
.warning_threshold(98.0 as f64);
53+
let configuration = datadog::Configuration::new();
54+
let api = ServiceLevelObjectivesAPI::with_config(configuration);
55+
let resp = api.create_slo(body).await;
56+
if let Ok(value) = resp {
57+
println!("{:#?}", value);
58+
} else {
59+
println!("{:#?}", resp.unwrap_err());
60+
}
61+
}

src/datadogV1/model/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,10 @@ pub mod model_slo_data_source_query_definition;
12241224
pub use self::model_slo_data_source_query_definition::SLODataSourceQueryDefinition;
12251225
pub mod model_slo_time_slice_interval;
12261226
pub use self::model_slo_time_slice_interval::SLOTimeSliceInterval;
1227+
pub mod model_slo_count_spec;
1228+
pub use self::model_slo_count_spec::SLOCountSpec;
1229+
pub mod model_slo_count_condition;
1230+
pub use self::model_slo_count_condition::SLOCountCondition;
12271231
pub mod model_slo_sli_spec;
12281232
pub use self::model_slo_sli_spec::SLOSliSpec;
12291233
pub mod model_slo_threshold;

src/datadogV1/model/model_service_level_objective.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ pub struct ServiceLevelObjective {
6262
/// The name of the service level objective object.
6363
#[serde(rename = "name")]
6464
pub name: String,
65-
/// A metric-based SLO. **Required if type is `metric`**. Note that Datadog only allows the sum by aggregator
65+
/// A metric-based SLO. Note that Datadog only allows the sum by aggregator
6666
/// to be used because this will sum up all request counts instead of averaging them, or taking the max or
6767
/// min of all of those requests.
6868
#[serde(rename = "query")]
6969
pub query: Option<crate::datadogV1::model::ServiceLevelObjectiveQuery>,
70-
/// A generic SLI specification. This is currently used for time-slice SLOs only.
70+
/// A generic SLI specification. This is currently used for time-slice and count-based SLOs only.
7171
#[serde(rename = "sli_specification")]
7272
pub sli_specification: Option<crate::datadogV1::model::SLOSliSpec>,
7373
/// A list of tags associated with this service level objective.

src/datadogV1/model/model_service_level_objective_query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer, Serialize};
66
use serde_with::skip_serializing_none;
77
use std::fmt::{self, Formatter};
88

9-
/// A metric-based SLO. **Required if type is `metric`**. Note that Datadog only allows the sum by aggregator
9+
/// A metric-based SLO. Note that Datadog only allows the sum by aggregator
1010
/// to be used because this will sum up all request counts instead of averaging them, or taking the max or
1111
/// min of all of those requests.
1212
#[non_exhaustive]

src/datadogV1/model/model_service_level_objective_request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ pub struct ServiceLevelObjectiveRequest {
3636
/// The name of the service level objective object.
3737
#[serde(rename = "name")]
3838
pub name: String,
39-
/// A metric-based SLO. **Required if type is `metric`**. Note that Datadog only allows the sum by aggregator
39+
/// A metric-based SLO. Note that Datadog only allows the sum by aggregator
4040
/// to be used because this will sum up all request counts instead of averaging them, or taking the max or
4141
/// min of all of those requests.
4242
#[serde(rename = "query")]
4343
pub query: Option<crate::datadogV1::model::ServiceLevelObjectiveQuery>,
44-
/// A generic SLI specification. This is currently used for time-slice SLOs only.
44+
/// A generic SLI specification. This is currently used for time-slice and count-based SLOs only.
4545
#[serde(rename = "sli_specification")]
4646
pub sli_specification: Option<crate::datadogV1::model::SLOSliSpec>,
4747
/// A list of tags associated with this service level objective.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
use serde::de::{Error, MapAccess, Visitor};
5+
use serde::{Deserialize, Deserializer, Serialize};
6+
use serde_with::skip_serializing_none;
7+
use std::fmt::{self, Formatter};
8+
9+
/// A count-based SLI specification, composed of three parts: the good events formula, the total events formula,
10+
/// and the involved queries.
11+
#[non_exhaustive]
12+
#[skip_serializing_none]
13+
#[derive(Clone, Debug, PartialEq, Serialize)]
14+
pub struct SLOCountCondition {
15+
/// A formula that specifies how to combine the results of multiple queries.
16+
#[serde(rename = "good_events_formula")]
17+
pub good_events_formula: crate::datadogV1::model::SLOFormula,
18+
#[serde(rename = "queries")]
19+
pub queries: Vec<crate::datadogV1::model::SLODataSourceQueryDefinition>,
20+
/// A formula that specifies how to combine the results of multiple queries.
21+
#[serde(rename = "total_events_formula")]
22+
pub total_events_formula: crate::datadogV1::model::SLOFormula,
23+
#[serde(flatten)]
24+
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25+
#[serde(skip)]
26+
#[serde(default)]
27+
pub(crate) _unparsed: bool,
28+
}
29+
30+
impl SLOCountCondition {
31+
pub fn new(
32+
good_events_formula: crate::datadogV1::model::SLOFormula,
33+
queries: Vec<crate::datadogV1::model::SLODataSourceQueryDefinition>,
34+
total_events_formula: crate::datadogV1::model::SLOFormula,
35+
) -> SLOCountCondition {
36+
SLOCountCondition {
37+
good_events_formula,
38+
queries,
39+
total_events_formula,
40+
additional_properties: std::collections::BTreeMap::new(),
41+
_unparsed: false,
42+
}
43+
}
44+
45+
pub fn additional_properties(
46+
mut self,
47+
value: std::collections::BTreeMap<String, serde_json::Value>,
48+
) -> Self {
49+
self.additional_properties = value;
50+
self
51+
}
52+
}
53+
54+
impl<'de> Deserialize<'de> for SLOCountCondition {
55+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
56+
where
57+
D: Deserializer<'de>,
58+
{
59+
struct SLOCountConditionVisitor;
60+
impl<'a> Visitor<'a> for SLOCountConditionVisitor {
61+
type Value = SLOCountCondition;
62+
63+
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
64+
f.write_str("a mapping")
65+
}
66+
67+
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
68+
where
69+
M: MapAccess<'a>,
70+
{
71+
let mut good_events_formula: Option<crate::datadogV1::model::SLOFormula> = None;
72+
let mut queries: Option<
73+
Vec<crate::datadogV1::model::SLODataSourceQueryDefinition>,
74+
> = None;
75+
let mut total_events_formula: Option<crate::datadogV1::model::SLOFormula> = None;
76+
let mut additional_properties: std::collections::BTreeMap<
77+
String,
78+
serde_json::Value,
79+
> = std::collections::BTreeMap::new();
80+
let mut _unparsed = false;
81+
82+
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
83+
match k.as_str() {
84+
"good_events_formula" => {
85+
good_events_formula =
86+
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
87+
}
88+
"queries" => {
89+
queries = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
90+
}
91+
"total_events_formula" => {
92+
total_events_formula =
93+
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
94+
}
95+
&_ => {
96+
if let Ok(value) = serde_json::from_value(v.clone()) {
97+
additional_properties.insert(k, value);
98+
}
99+
}
100+
}
101+
}
102+
let good_events_formula = good_events_formula
103+
.ok_or_else(|| M::Error::missing_field("good_events_formula"))?;
104+
let queries = queries.ok_or_else(|| M::Error::missing_field("queries"))?;
105+
let total_events_formula = total_events_formula
106+
.ok_or_else(|| M::Error::missing_field("total_events_formula"))?;
107+
108+
let content = SLOCountCondition {
109+
good_events_formula,
110+
queries,
111+
total_events_formula,
112+
additional_properties,
113+
_unparsed,
114+
};
115+
116+
Ok(content)
117+
}
118+
}
119+
120+
deserializer.deserialize_any(SLOCountConditionVisitor)
121+
}
122+
}

0 commit comments

Comments
 (0)