1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};
/// An object that holds an SLI value and its associated data. It can represent an SLO's overall SLI value.
/// This can also represent the SLI value for a specific monitor in multi-monitor SLOs, or a group in grouped SLOs.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct SLOHistorySLIData {
/// A mapping of threshold `timeframe` to the remaining error budget.
#[serde(rename = "error_budget_remaining")]
pub error_budget_remaining: Option<std::collections::BTreeMap<String, f64>>,
/// An array of error objects returned while querying the history data for the service level objective.
#[serde(rename = "errors")]
pub errors: Option<Vec<crate::datadogV1::model::SLOHistoryResponseErrorWithType>>,
/// For groups in a grouped SLO, this is the group name.
#[serde(rename = "group")]
pub group: Option<String>,
/// The state transition history for `monitor` or `time-slice` SLOs. It is represented as
/// an array of pairs. Each pair is an array containing the timestamp of the transition
/// as an integer in Unix epoch format in the first element, and the state as an integer in the
/// second element. An integer value of `0` for state means uptime, `1` means downtime, and `2` means no data.
/// Periods of no data count as uptime in time-slice SLOs, while for monitor SLOs, no data is counted
/// either as uptime or downtime depending on monitor settings. See
/// [SLO documentation](<https://docs.datadoghq.com/service_management/service_level_objectives/monitor/#missing-data>)
/// for detailed information.
#[serde(rename = "history")]
pub history: Option<Vec<Vec<f64>>>,
/// For `monitor` based SLOs, this is the last modified timestamp in epoch seconds of the monitor.
#[serde(rename = "monitor_modified")]
pub monitor_modified: Option<i64>,
/// For `monitor` based SLOs, this describes the type of monitor.
#[serde(rename = "monitor_type")]
pub monitor_type: Option<String>,
/// For groups in a grouped SLO, this is the group name. For monitors in a multi-monitor SLO, this is the monitor name.
#[serde(rename = "name")]
pub name: Option<String>,
/// A mapping of threshold `timeframe` to number of accurate decimals, regardless of the from && to timestamp.
#[serde(rename = "precision")]
pub precision: Option<std::collections::BTreeMap<String, f64>>,
/// For `monitor` based SLOs, when `true` this indicates that a replay is in progress to give an accurate uptime
/// calculation.
#[serde(rename = "preview")]
pub preview: Option<bool>,
/// The current SLI value of the SLO over the history window.
#[serde(
rename = "sli_value",
default,
with = "::serde_with::rust::double_option"
)]
pub sli_value: Option<Option<f64>>,
/// The amount of decimal places the SLI value is accurate to for the given from `&&` to timestamp.
#[serde(rename = "span_precision")]
pub span_precision: Option<f64>,
/// Use `sli_value` instead.
#[deprecated]
#[serde(rename = "uptime", default, with = "::serde_with::rust::double_option")]
pub uptime: Option<Option<f64>>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl SLOHistorySLIData {
pub fn new() -> SLOHistorySLIData {
#[allow(deprecated)]
SLOHistorySLIData {
error_budget_remaining: None,
errors: None,
group: None,
history: None,
monitor_modified: None,
monitor_type: None,
name: None,
precision: None,
preview: None,
sli_value: None,
span_precision: None,
uptime: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
#[allow(deprecated)]
pub fn error_budget_remaining(
mut self,
value: std::collections::BTreeMap<String, f64>,
) -> Self {
self.error_budget_remaining = Some(value);
self
}
#[allow(deprecated)]
pub fn errors(
mut self,
value: Vec<crate::datadogV1::model::SLOHistoryResponseErrorWithType>,
) -> Self {
self.errors = Some(value);
self
}
#[allow(deprecated)]
pub fn group(mut self, value: String) -> Self {
self.group = Some(value);
self
}
#[allow(deprecated)]
pub fn history(mut self, value: Vec<Vec<f64>>) -> Self {
self.history = Some(value);
self
}
#[allow(deprecated)]
pub fn monitor_modified(mut self, value: i64) -> Self {
self.monitor_modified = Some(value);
self
}
#[allow(deprecated)]
pub fn monitor_type(mut self, value: String) -> Self {
self.monitor_type = Some(value);
self
}
#[allow(deprecated)]
pub fn name(mut self, value: String) -> Self {
self.name = Some(value);
self
}
#[allow(deprecated)]
pub fn precision(mut self, value: std::collections::BTreeMap<String, f64>) -> Self {
self.precision = Some(value);
self
}
#[allow(deprecated)]
pub fn preview(mut self, value: bool) -> Self {
self.preview = Some(value);
self
}
#[allow(deprecated)]
pub fn sli_value(mut self, value: Option<f64>) -> Self {
self.sli_value = Some(value);
self
}
#[allow(deprecated)]
pub fn span_precision(mut self, value: f64) -> Self {
self.span_precision = Some(value);
self
}
#[allow(deprecated)]
pub fn uptime(mut self, value: Option<f64>) -> Self {
self.uptime = Some(value);
self
}
pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}
impl Default for SLOHistorySLIData {
fn default() -> Self {
Self::new()
}
}
impl<'de> Deserialize<'de> for SLOHistorySLIData {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct SLOHistorySLIDataVisitor;
impl<'a> Visitor<'a> for SLOHistorySLIDataVisitor {
type Value = SLOHistorySLIData;
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
}
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'a>,
{
let mut error_budget_remaining: Option<std::collections::BTreeMap<String, f64>> =
None;
let mut errors: Option<
Vec<crate::datadogV1::model::SLOHistoryResponseErrorWithType>,
> = None;
let mut group: Option<String> = None;
let mut history: Option<Vec<Vec<f64>>> = None;
let mut monitor_modified: Option<i64> = None;
let mut monitor_type: Option<String> = None;
let mut name: Option<String> = None;
let mut precision: Option<std::collections::BTreeMap<String, f64>> = None;
let mut preview: Option<bool> = None;
let mut sli_value: Option<Option<f64>> = None;
let mut span_precision: Option<f64> = None;
let mut uptime: Option<Option<f64>> = None;
let mut additional_properties: std::collections::BTreeMap<
String,
serde_json::Value,
> = std::collections::BTreeMap::new();
let mut _unparsed = false;
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"error_budget_remaining" => {
if v.is_null() {
continue;
}
error_budget_remaining =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"errors" => {
if v.is_null() {
continue;
}
errors = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"group" => {
if v.is_null() {
continue;
}
group = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"history" => {
if v.is_null() {
continue;
}
history = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"monitor_modified" => {
if v.is_null() {
continue;
}
monitor_modified =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"monitor_type" => {
if v.is_null() {
continue;
}
monitor_type =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"name" => {
if v.is_null() {
continue;
}
name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"precision" => {
if v.is_null() {
continue;
}
precision = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"preview" => {
if v.is_null() {
continue;
}
preview = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"sli_value" => {
sli_value = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"span_precision" => {
if v.is_null() {
continue;
}
span_precision =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"uptime" => {
uptime = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
&_ => {
if let Ok(value) = serde_json::from_value(v.clone()) {
additional_properties.insert(k, value);
}
}
}
}
#[allow(deprecated)]
let content = SLOHistorySLIData {
error_budget_remaining,
errors,
group,
history,
monitor_modified,
monitor_type,
name,
precision,
preview,
sli_value,
span_precision,
uptime,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(SLOHistorySLIDataVisitor)
}
}