Skip to content

Commit 03f61ec

Browse files
author
ci.datadog-api-spec
committed
Regenerate client from commit e162a41 of spec repo
1 parent b0ebff6 commit 03f61ec

13 files changed

Lines changed: 425 additions & 11 deletions

.generator/schemas/v1/openapi.yaml

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11900,6 +11900,60 @@ components:
1190011900
example: UTC
1190111901
type: string
1190211902
type: object
11903+
SLOCountDefinition:
11904+
description: 'A count-based (metric) SLI specification, composed of three parts:
11905+
the good events formula, the total events formula,
11906+
11907+
and the underlying queries.'
11908+
example:
11909+
good_events_formula: query1 - query2
11910+
queries:
11911+
- data_source: metrics
11912+
name: query1
11913+
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
11914+
- data_source: metrics
11915+
name: query2
11916+
query: sum:trace.servlet.request.errors{*} by {env}.as_count()
11917+
total_events_formula: query1
11918+
properties:
11919+
good_events_formula:
11920+
$ref: '#/components/schemas/SLOFormula'
11921+
queries:
11922+
example:
11923+
- data_source: metrics
11924+
name: query1
11925+
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
11926+
items:
11927+
$ref: '#/components/schemas/SLODataSourceQueryDefinition'
11928+
minItems: 1
11929+
type: array
11930+
total_events_formula:
11931+
$ref: '#/components/schemas/SLOFormula'
11932+
required:
11933+
- good_events_formula
11934+
- total_events_formula
11935+
- queries
11936+
type: object
11937+
SLOCountSpec:
11938+
additionalProperties: false
11939+
description: A metric SLI specification.
11940+
example:
11941+
count:
11942+
good_events_formula: query1 - query2
11943+
queries:
11944+
- data_source: metrics
11945+
name: query1
11946+
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
11947+
- data_source: metrics
11948+
name: query2
11949+
query: sum:trace.servlet.request.errors{*} by {env}.as_count()
11950+
total_events_formula: query1
11951+
properties:
11952+
count:
11953+
$ref: '#/components/schemas/SLOCountDefinition'
11954+
required:
11955+
- count
11956+
type: object
1190311957
SLOCreator:
1190411958
description: The creator of the SLO
1190511959
nullable: true
@@ -12747,8 +12801,12 @@ components:
1274712801
type: string
1274812802
query:
1274912803
$ref: '#/components/schemas/ServiceLevelObjectiveQuery'
12804+
description: The metric query used to define a count-based SLO as the ratio
12805+
of good events to total events.
1275012806
sli_specification:
1275112807
$ref: '#/components/schemas/SLOSliSpec'
12808+
description: A generic SLI specification. This is currently used for time-slice
12809+
and count-based (metric) SLOs only.
1275212810
tags:
1275312811
description: 'A list of tags associated with this service level objective.
1275412812

@@ -12804,10 +12862,11 @@ components:
1280412862
type: number
1280512863
type: object
1280612864
SLOSliSpec:
12807-
description: A generic SLI specification. This is currently used for time-slice
12808-
SLOs only.
12865+
description: A generic SLI specification. This is used for time-slice and count-based
12866+
(metric) SLOs only.
1280912867
oneOf:
1281012868
- $ref: '#/components/schemas/SLOTimeSliceSpec'
12869+
- $ref: '#/components/schemas/SLOCountSpec'
1281112870
SLOState:
1281212871
description: State of the SLO.
1281312872
enum:
@@ -13959,7 +14018,8 @@ components:
1395914018
- type
1396014019
type: object
1396114020
ServiceLevelObjectiveQuery:
13962-
description: 'A metric-based SLO. **Required if type is `metric`**. Note that
14021+
description: 'A count-based (metric) SLO query. This field is superseded by
14022+
`sli_specification` but is retained for backwards compatibility. Note that
1396314023
Datadog only allows the sum by aggregator
1396414024

1396514025
to be used because this will sum up all request counts instead of averaging
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::SLOCountDefinition;
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(99.5 as f64)
23+
.warning_display("99.5".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+
SLOCountDefinition::new(
29+
SLOFormula::new("query1 - query2".to_string()),
30+
vec![
31+
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(Box::new(
32+
FormulaAndFunctionMetricQueryDefinition::new(
33+
FormulaAndFunctionMetricDataSource::METRICS,
34+
"query1".to_string(),
35+
"sum:httpservice.hits{*}.as_count()".to_string(),
36+
),
37+
)),
38+
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(Box::new(
39+
FormulaAndFunctionMetricQueryDefinition::new(
40+
FormulaAndFunctionMetricDataSource::METRICS,
41+
"query2".to_string(),
42+
"sum:httpservice.errors{*}.as_count()".to_string(),
43+
),
44+
)),
45+
],
46+
SLOFormula::new("query1".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(99.5 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
@@ -1268,6 +1268,10 @@ pub mod model_slo_data_source_query_definition;
12681268
pub use self::model_slo_data_source_query_definition::SLODataSourceQueryDefinition;
12691269
pub mod model_slo_time_slice_interval;
12701270
pub use self::model_slo_time_slice_interval::SLOTimeSliceInterval;
1271+
pub mod model_slo_count_spec;
1272+
pub use self::model_slo_count_spec::SLOCountSpec;
1273+
pub mod model_slo_count_definition;
1274+
pub use self::model_slo_count_definition::SLOCountDefinition;
12711275
pub mod model_slo_sli_spec;
12721276
pub use self::model_slo_sli_spec::SLOSliSpec;
12731277
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 count-based (metric) SLO query. This field is superseded by `sli_specification` but is retained for backwards compatibility. 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 used for time-slice and count-based (metric) 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 count-based (metric) SLO query. This field is superseded by `sli_specification` but is retained for backwards compatibility. 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 count-based (metric) SLO query. This field is superseded by `sli_specification` but is retained for backwards compatibility. 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 used for time-slice and count-based (metric) 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 (metric) SLI specification, composed of three parts: the good events formula, the total events formula,
10+
/// and the underlying queries.
11+
#[non_exhaustive]
12+
#[skip_serializing_none]
13+
#[derive(Clone, Debug, PartialEq, Serialize)]
14+
pub struct SLOCountDefinition {
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 SLOCountDefinition {
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+
) -> SLOCountDefinition {
36+
SLOCountDefinition {
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 SLOCountDefinition {
55+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
56+
where
57+
D: Deserializer<'de>,
58+
{
59+
struct SLOCountDefinitionVisitor;
60+
impl<'a> Visitor<'a> for SLOCountDefinitionVisitor {
61+
type Value = SLOCountDefinition;
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 = SLOCountDefinition {
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(SLOCountDefinitionVisitor)
121+
}
122+
}

0 commit comments

Comments
 (0)