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
61 changes: 61 additions & 0 deletions examples/v1_service-level-objectives_CreateSLO_512760759.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Create a new metric SLO object using sli_specification returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_service_level_objectives::ServiceLevelObjectivesAPI;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
use datadog_api_client::datadogV1::model::SLOCountCondition;
use datadog_api_client::datadogV1::model::SLOCountSpec;
use datadog_api_client::datadogV1::model::SLODataSourceQueryDefinition;
use datadog_api_client::datadogV1::model::SLOFormula;
use datadog_api_client::datadogV1::model::SLOSliSpec;
use datadog_api_client::datadogV1::model::SLOThreshold;
use datadog_api_client::datadogV1::model::SLOTimeframe;
use datadog_api_client::datadogV1::model::SLOType;
use datadog_api_client::datadogV1::model::ServiceLevelObjectiveRequest;

#[tokio::main]
async fn main() {
let body = ServiceLevelObjectiveRequest::new(
"Example-Service-Level-Objective".to_string(),
vec![SLOThreshold::new(99.0, SLOTimeframe::SEVEN_DAYS)
.target_display("99.0".to_string())
.warning(98.0 as f64)
.warning_display("98.0".to_string())],
SLOType::METRIC,
)
.description(Some("Metric SLO using sli_specification".to_string()))
.sli_specification(SLOSliSpec::SLOCountSpec(Box::new(SLOCountSpec::new(
SLOCountCondition::new(
SLOFormula::new("query1".to_string()),
vec![
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(Box::new(
FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query1".to_string(),
"sum:httpservice.success{*}.as_count()".to_string(),
),
)),
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(Box::new(
FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query2".to_string(),
"sum:httpservice.hits{*}.as_count()".to_string(),
),
)),
],
SLOFormula::new("query2".to_string()),
),
))))
.tags(vec!["env:prod".to_string(), "type:count".to_string()])
.target_threshold(99.0 as f64)
.timeframe(SLOTimeframe::SEVEN_DAYS)
.warning_threshold(98.0 as f64);
let configuration = datadog::Configuration::new();
let api = ServiceLevelObjectivesAPI::with_config(configuration);
let resp = api.create_slo(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
4 changes: 4 additions & 0 deletions src/datadogV1/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,10 @@ pub mod model_slo_data_source_query_definition;
pub use self::model_slo_data_source_query_definition::SLODataSourceQueryDefinition;
pub mod model_slo_time_slice_interval;
pub use self::model_slo_time_slice_interval::SLOTimeSliceInterval;
pub mod model_slo_count_spec;
pub use self::model_slo_count_spec::SLOCountSpec;
pub mod model_slo_count_condition;
pub use self::model_slo_count_condition::SLOCountCondition;
pub mod model_slo_sli_spec;
pub use self::model_slo_sli_spec::SLOSliSpec;
pub mod model_slo_threshold;
Expand Down
4 changes: 2 additions & 2 deletions src/datadogV1/model/model_service_level_objective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ pub struct ServiceLevelObjective {
/// The name of the service level objective object.
#[serde(rename = "name")]
pub name: String,
/// 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.
#[serde(rename = "query")]
pub query: Option<crate::datadogV1::model::ServiceLevelObjectiveQuery>,
/// 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.
#[serde(rename = "sli_specification")]
pub sli_specification: Option<crate::datadogV1::model::SLOSliSpec>,
/// A list of tags associated with this service level objective.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};

/// 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.
#[non_exhaustive]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ pub struct ServiceLevelObjectiveRequest {
/// The name of the service level objective object.
#[serde(rename = "name")]
pub name: String,
/// 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.
#[serde(rename = "query")]
pub query: Option<crate::datadogV1::model::ServiceLevelObjectiveQuery>,
/// 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.
#[serde(rename = "sli_specification")]
pub sli_specification: Option<crate::datadogV1::model::SLOSliSpec>,
/// A list of tags associated with this service level objective.
Expand Down
122 changes: 122 additions & 0 deletions src/datadogV1/model/model_slo_count_condition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// 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};

/// A count-based SLI specification, composed of three parts: the good events formula, the total events formula,
/// and the involved queries.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct SLOCountCondition {
/// A formula that specifies how to combine the results of multiple queries.
#[serde(rename = "good_events_formula")]
pub good_events_formula: crate::datadogV1::model::SLOFormula,
#[serde(rename = "queries")]
pub queries: Vec<crate::datadogV1::model::SLODataSourceQueryDefinition>,
/// A formula that specifies how to combine the results of multiple queries.
#[serde(rename = "total_events_formula")]
pub total_events_formula: crate::datadogV1::model::SLOFormula,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}

impl SLOCountCondition {
pub fn new(
good_events_formula: crate::datadogV1::model::SLOFormula,
queries: Vec<crate::datadogV1::model::SLODataSourceQueryDefinition>,
total_events_formula: crate::datadogV1::model::SLOFormula,
) -> SLOCountCondition {
SLOCountCondition {
good_events_formula,
queries,
total_events_formula,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}

pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}

impl<'de> Deserialize<'de> for SLOCountCondition {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct SLOCountConditionVisitor;
impl<'a> Visitor<'a> for SLOCountConditionVisitor {
type Value = SLOCountCondition;

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 good_events_formula: Option<crate::datadogV1::model::SLOFormula> = None;
let mut queries: Option<
Vec<crate::datadogV1::model::SLODataSourceQueryDefinition>,
> = None;
let mut total_events_formula: Option<crate::datadogV1::model::SLOFormula> = 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() {
"good_events_formula" => {
good_events_formula =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"queries" => {
queries = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"total_events_formula" => {
total_events_formula =
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);
}
}
}
}
let good_events_formula = good_events_formula
.ok_or_else(|| M::Error::missing_field("good_events_formula"))?;
let queries = queries.ok_or_else(|| M::Error::missing_field("queries"))?;
let total_events_formula = total_events_formula
.ok_or_else(|| M::Error::missing_field("total_events_formula"))?;

let content = SLOCountCondition {
good_events_formula,
queries,
total_events_formula,
additional_properties,
_unparsed,
};

Ok(content)
}
}

deserializer.deserialize_any(SLOCountConditionVisitor)
}
}
Loading
Loading