Skip to content

Commit 35d32d6

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add slo_query to SLO Correction API for global correction support (#1711)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 953e2b2 commit 35d32d6

17 files changed

Lines changed: 406 additions & 25 deletions

.generator/schemas/v1/openapi.yaml

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13177,13 +13177,16 @@ components:
1317713177
type: object
1317813178
SLOCorrectionCreateRequest:
1317913179
description: |-
13180-
An object that defines a correction to be applied to an SLO.
13180+
An object that defines a correction to be applied to one or more SLOs.
1318113181
properties:
1318213182
data:
1318313183
$ref: "#/components/schemas/SLOCorrectionCreateData"
1318413184
type: object
1318513185
SLOCorrectionCreateRequestAttributes:
13186-
description: The attribute object associated with the SLO correction to be created.
13186+
description: |-
13187+
The attribute object associated with the SLO correction to be created.
13188+
13189+
Exactly one of `slo_id` or `slo_query` must be provided.
1318713190
properties:
1318813191
category:
1318913192
$ref: "#/components/schemas/SLOCorrectionCategory"
@@ -13207,9 +13210,16 @@ components:
1320713210
example: FREQ=DAILY;INTERVAL=10;COUNT=5
1320813211
type: string
1320913212
slo_id:
13210-
description: ID of the SLO that this correction applies to.
13213+
description: ID of the single SLO that this correction applies to.
1321113214
example: sloId
1321213215
type: string
13216+
slo_query:
13217+
description: |-
13218+
Query that matches the SLOs this correction applies to.
13219+
The query uses the [Events search syntax](https://docs.datadoghq.com/events/explorer/searching/)
13220+
and can filter SLOs by SLO tags.
13221+
example: "env:prod service:checkout"
13222+
type: string
1321313223
start:
1321413224
description: Starting time of the correction in epoch seconds.
1321513225
example: 1600000000
@@ -13220,7 +13230,6 @@ components:
1322013230
example: UTC
1322113231
type: string
1322213232
required:
13223-
- slo_id
1322413233
- start
1322513234
- category
1322613235
type: object
@@ -13284,7 +13293,12 @@ components:
1328413293
nullable: true
1328513294
type: string
1328613295
slo_id:
13287-
description: ID of the SLO that this correction applies to.
13296+
description: ID of the single SLO that this correction applies to.
13297+
nullable: true
13298+
type: string
13299+
slo_query:
13300+
description: Query that matches the SLOs this correction applies to.
13301+
nullable: true
1328813302
type: string
1328913303
start:
1329013304
description: Starting time of the correction in epoch seconds.
@@ -13356,6 +13370,13 @@ components:
1335613370
are `FREQ`, `INTERVAL`, `COUNT`, `UNTIL` and `BYDAY`.
1335713371
example: FREQ=DAILY;INTERVAL=10;COUNT=5
1335813372
type: string
13373+
slo_query:
13374+
description: |-
13375+
Query that matches the SLOs this correction applies to.
13376+
The query uses the [Events search syntax](https://docs.datadoghq.com/events/explorer/searching/)
13377+
and can filter SLOs by SLO tags.
13378+
example: "env:prod service:checkout"
13379+
type: string
1335913380
start:
1336013381
description: Starting time of the correction in epoch seconds.
1336113382
example: 1600000000
@@ -37493,7 +37514,8 @@ paths:
3749337514
- slos_read
3749437515
post:
3749537516
description: |-
37496-
Create an SLO Correction.
37517+
Create an SLO correction. Use `slo_id` to apply the correction to a single SLO, or `slo_query` to apply the
37518+
correction to SLOs that match a query. Exactly one of `slo_id` or `slo_query` is required.
3749737519
operationId: CreateSLOCorrection
3749837520
requestBody:
3749937521
content:
@@ -37510,6 +37532,17 @@ paths:
3751037532
start: 1600000000
3751137533
timezone: UTC
3751237534
type: correction
37535+
slo_query:
37536+
value:
37537+
data:
37538+
attributes:
37539+
category: "Scheduled Maintenance"
37540+
description: "Planned maintenance window for checkout services."
37541+
end: 1600003600
37542+
slo_query: "env:prod service:checkout"
37543+
start: 1600000000
37544+
timezone: UTC
37545+
type: correction
3751337546
schema:
3751437547
$ref: "#/components/schemas/SLOCorrectionCreateRequest"
3751537548
description: Create an SLO Correction
@@ -37669,6 +37702,17 @@ paths:
3766937702
start: 1600000000
3767037703
timezone: UTC
3767137704
type: correction
37705+
slo_query:
37706+
value:
37707+
data:
37708+
attributes:
37709+
category: "Scheduled Maintenance"
37710+
description: "Updated correction for checkout services."
37711+
end: 1600003600
37712+
slo_query: "env:prod service:checkout"
37713+
start: 1600000000
37714+
timezone: UTC
37715+
type: correction
3767237716
schema:
3767337717
$ref: "#/components/schemas/SLOCorrectionUpdateRequest"
3767437718
description: The edited SLO correction object.

examples/v1_service-level-objective-corrections_CreateSLOCorrection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ async fn main() {
1515
SLOCorrectionCreateData::new(SLOCorrectionType::CORRECTION).attributes(
1616
SLOCorrectionCreateRequestAttributes::new(
1717
SLOCorrectionCategory::SCHEDULED_MAINTENANCE,
18-
slo_data_0_id.clone(),
1918
1636629071,
2019
)
2120
.description("Example-Service-Level-Objective-Correction".to_string())
2221
.end(1636632671)
22+
.slo_id(slo_data_0_id.clone())
2323
.timezone("UTC".to_string()),
2424
),
2525
);

examples/v1_service-level-objective-corrections_CreateSLOCorrection_1326388368.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ async fn main() {
1515
SLOCorrectionCreateData::new(SLOCorrectionType::CORRECTION).attributes(
1616
SLOCorrectionCreateRequestAttributes::new(
1717
SLOCorrectionCategory::SCHEDULED_MAINTENANCE,
18-
slo_data_0_id.clone(),
1918
1636629071,
2019
)
2120
.description("Example-Service-Level-Objective-Correction".to_string())
2221
.duration(3600)
2322
.rrule("FREQ=DAILY;INTERVAL=10;COUNT=5".to_string())
23+
.slo_id(slo_data_0_id.clone())
2424
.timezone("UTC".to_string()),
2525
),
2626
);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Create an SLO correction with slo_query returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV1::api_service_level_objective_corrections::ServiceLevelObjectiveCorrectionsAPI;
4+
use datadog_api_client::datadogV1::model::SLOCorrectionCategory;
5+
use datadog_api_client::datadogV1::model::SLOCorrectionCreateData;
6+
use datadog_api_client::datadogV1::model::SLOCorrectionCreateRequest;
7+
use datadog_api_client::datadogV1::model::SLOCorrectionCreateRequestAttributes;
8+
use datadog_api_client::datadogV1::model::SLOCorrectionType;
9+
10+
#[tokio::main]
11+
async fn main() {
12+
let body = SLOCorrectionCreateRequest::new().data(
13+
SLOCorrectionCreateData::new(SLOCorrectionType::CORRECTION).attributes(
14+
SLOCorrectionCreateRequestAttributes::new(
15+
SLOCorrectionCategory::SCHEDULED_MAINTENANCE,
16+
1636629071,
17+
)
18+
.description("Example-Service-Level-Objective-Correction".to_string())
19+
.end(1636632671)
20+
.slo_query("env:prod service:checkout".to_string())
21+
.timezone("UTC".to_string()),
22+
),
23+
);
24+
let configuration = datadog::Configuration::new();
25+
let api = ServiceLevelObjectiveCorrectionsAPI::with_config(configuration);
26+
let resp = api.create_slo_correction(body).await;
27+
if let Ok(value) = resp {
28+
println!("{:#?}", value);
29+
} else {
30+
println!("{:#?}", resp.unwrap_err());
31+
}
32+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Update an SLO correction with slo_query returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV1::api_service_level_objective_corrections::ServiceLevelObjectiveCorrectionsAPI;
4+
use datadog_api_client::datadogV1::model::SLOCorrectionCategory;
5+
use datadog_api_client::datadogV1::model::SLOCorrectionType;
6+
use datadog_api_client::datadogV1::model::SLOCorrectionUpdateData;
7+
use datadog_api_client::datadogV1::model::SLOCorrectionUpdateRequest;
8+
use datadog_api_client::datadogV1::model::SLOCorrectionUpdateRequestAttributes;
9+
10+
#[tokio::main]
11+
async fn main() {
12+
// there is a valid "correction_with_query" in the system
13+
let correction_with_query_data_id = std::env::var("CORRECTION_WITH_QUERY_DATA_ID").unwrap();
14+
let body = SLOCorrectionUpdateRequest::new().data(
15+
SLOCorrectionUpdateData::new()
16+
.attributes(
17+
SLOCorrectionUpdateRequestAttributes::new()
18+
.category(SLOCorrectionCategory::SCHEDULED_MAINTENANCE)
19+
.description("Example-Service-Level-Objective-Correction".to_string())
20+
.end(1636632671)
21+
.slo_query("env:staging service:checkout".to_string())
22+
.start(1636629071)
23+
.timezone("UTC".to_string()),
24+
)
25+
.type_(SLOCorrectionType::CORRECTION),
26+
);
27+
let configuration = datadog::Configuration::new();
28+
let api = ServiceLevelObjectiveCorrectionsAPI::with_config(configuration);
29+
let resp = api
30+
.update_slo_correction(correction_with_query_data_id.clone(), body)
31+
.await;
32+
if let Ok(value) = resp {
33+
println!("{:#?}", value);
34+
} else {
35+
println!("{:#?}", resp.unwrap_err());
36+
}
37+
}

src/datadogV1/api/api_service_level_objective_corrections.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ impl ServiceLevelObjectiveCorrectionsAPI {
152152
Self { config, client }
153153
}
154154

155-
/// Create an SLO Correction.
155+
/// Create an SLO correction. Use `slo_id` to apply the correction to a single SLO, or `slo_query` to apply the
156+
/// correction to SLOs that match a query. Exactly one of `slo_id` or `slo_query` is required.
156157
pub async fn create_slo_correction(
157158
&self,
158159
body: crate::datadogV1::model::SLOCorrectionCreateRequest,
@@ -174,7 +175,8 @@ impl ServiceLevelObjectiveCorrectionsAPI {
174175
}
175176
}
176177

177-
/// Create an SLO Correction.
178+
/// Create an SLO correction. Use `slo_id` to apply the correction to a single SLO, or `slo_query` to apply the
179+
/// correction to SLOs that match a query. Exactly one of `slo_id` or `slo_query` is required.
178180
pub async fn create_slo_correction_with_http_info(
179181
&self,
180182
body: crate::datadogV1::model::SLOCorrectionCreateRequest,

src/datadogV1/model/model_slo_correction_create_data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use std::fmt::{self, Formatter};
1212
#[derive(Clone, Debug, PartialEq, Serialize)]
1313
pub struct SLOCorrectionCreateData {
1414
/// The attribute object associated with the SLO correction to be created.
15+
///
16+
/// Exactly one of `slo_id` or `slo_query` must be provided.
1517
#[serde(rename = "attributes")]
1618
pub attributes: Option<crate::datadogV1::model::SLOCorrectionCreateRequestAttributes>,
1719
/// SLO correction resource type.

src/datadogV1/model/model_slo_correction_create_request.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-
/// An object that defines a correction to be applied to an SLO.
9+
/// An object that defines a correction to be applied to one or more SLOs.
1010
#[non_exhaustive]
1111
#[skip_serializing_none]
1212
#[derive(Clone, Debug, PartialEq, Serialize)]

src/datadogV1/model/model_slo_correction_create_request_attributes.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use serde_with::skip_serializing_none;
77
use std::fmt::{self, Formatter};
88

99
/// The attribute object associated with the SLO correction to be created.
10+
///
11+
/// Exactly one of `slo_id` or `slo_query` must be provided.
1012
#[non_exhaustive]
1113
#[skip_serializing_none]
1214
#[derive(Clone, Debug, PartialEq, Serialize)]
@@ -27,9 +29,14 @@ pub struct SLOCorrectionCreateRequestAttributes {
2729
/// are `FREQ`, `INTERVAL`, `COUNT`, `UNTIL` and `BYDAY`.
2830
#[serde(rename = "rrule")]
2931
pub rrule: Option<String>,
30-
/// ID of the SLO that this correction applies to.
32+
/// ID of the single SLO that this correction applies to.
3133
#[serde(rename = "slo_id")]
32-
pub slo_id: String,
34+
pub slo_id: Option<String>,
35+
/// Query that matches the SLOs this correction applies to.
36+
/// The query uses the [Events search syntax](<https://docs.datadoghq.com/events/explorer/searching/>)
37+
/// and can filter SLOs by SLO tags.
38+
#[serde(rename = "slo_query")]
39+
pub slo_query: Option<String>,
3340
/// Starting time of the correction in epoch seconds.
3441
#[serde(rename = "start")]
3542
pub start: i64,
@@ -46,7 +53,6 @@ pub struct SLOCorrectionCreateRequestAttributes {
4653
impl SLOCorrectionCreateRequestAttributes {
4754
pub fn new(
4855
category: crate::datadogV1::model::SLOCorrectionCategory,
49-
slo_id: String,
5056
start: i64,
5157
) -> SLOCorrectionCreateRequestAttributes {
5258
SLOCorrectionCreateRequestAttributes {
@@ -55,7 +61,8 @@ impl SLOCorrectionCreateRequestAttributes {
5561
duration: None,
5662
end: None,
5763
rrule: None,
58-
slo_id,
64+
slo_id: None,
65+
slo_query: None,
5966
start,
6067
timezone: None,
6168
additional_properties: std::collections::BTreeMap::new(),
@@ -83,6 +90,16 @@ impl SLOCorrectionCreateRequestAttributes {
8390
self
8491
}
8592

93+
pub fn slo_id(mut self, value: String) -> Self {
94+
self.slo_id = Some(value);
95+
self
96+
}
97+
98+
pub fn slo_query(mut self, value: String) -> Self {
99+
self.slo_query = Some(value);
100+
self
101+
}
102+
86103
pub fn timezone(mut self, value: String) -> Self {
87104
self.timezone = Some(value);
88105
self
@@ -120,6 +137,7 @@ impl<'de> Deserialize<'de> for SLOCorrectionCreateRequestAttributes {
120137
let mut end: Option<i64> = None;
121138
let mut rrule: Option<String> = None;
122139
let mut slo_id: Option<String> = None;
140+
let mut slo_query: Option<String> = None;
123141
let mut start: Option<i64> = None;
124142
let mut timezone: Option<String> = None;
125143
let mut additional_properties: std::collections::BTreeMap<
@@ -167,8 +185,17 @@ impl<'de> Deserialize<'de> for SLOCorrectionCreateRequestAttributes {
167185
rrule = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
168186
}
169187
"slo_id" => {
188+
if v.is_null() {
189+
continue;
190+
}
170191
slo_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
171192
}
193+
"slo_query" => {
194+
if v.is_null() {
195+
continue;
196+
}
197+
slo_query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
198+
}
172199
"start" => {
173200
start = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
174201
}
@@ -186,7 +213,6 @@ impl<'de> Deserialize<'de> for SLOCorrectionCreateRequestAttributes {
186213
}
187214
}
188215
let category = category.ok_or_else(|| M::Error::missing_field("category"))?;
189-
let slo_id = slo_id.ok_or_else(|| M::Error::missing_field("slo_id"))?;
190216
let start = start.ok_or_else(|| M::Error::missing_field("start"))?;
191217

192218
let content = SLOCorrectionCreateRequestAttributes {
@@ -196,6 +222,7 @@ impl<'de> Deserialize<'de> for SLOCorrectionCreateRequestAttributes {
196222
end,
197223
rrule,
198224
slo_id,
225+
slo_query,
199226
start,
200227
timezone,
201228
additional_properties,

0 commit comments

Comments
 (0)