diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index afb32a4a8..f640568bf 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -11481,6 +11481,60 @@ components: example: UTC type: string type: object + SLOCountCondition: + description: 'A metric 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.hits{*} by {env}.as_count() + - data_source: metrics + name: query2 + query: sum:trace.servlet.request.errors{*} by {env}.as_count() + total_events_formula: query1 + 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 metric SLI specification. + example: + count: + good_events_formula: query1 - query2 + queries: + - data_source: metrics + name: query1 + query: sum:trace.servlet.request.hits{*} by {env}.as_count() + - data_source: metrics + name: query2 + query: sum:trace.servlet.request.errors{*} by {env}.as_count() + total_events_formula: query1 + properties: + count: + $ref: '#/components/schemas/SLOCountCondition' + required: + - count + type: object SLOCreator: description: The creator of the SLO nullable: true @@ -12328,8 +12382,16 @@ components: type: string query: $ref: '#/components/schemas/ServiceLevelObjectiveQuery' + description: 'The metric query of good / total events. This is not allowed + if the `sli_specification` field + + is used in the same request.' sli_specification: $ref: '#/components/schemas/SLOSliSpec' + description: 'A generic SLI specification. This is currently used for time-slice + and metric SLOs only. + + This is not allowed if the `query` field is used in the same request.' tags: description: 'A list of tags associated with this service level objective. @@ -12386,9 +12448,10 @@ components: type: object SLOSliSpec: description: A generic SLI specification. This is currently used for time-slice - SLOs only. + and metric SLOs only. oneOf: - $ref: '#/components/schemas/SLOTimeSliceSpec' + - $ref: '#/components/schemas/SLOCountSpec' SLOState: description: State of the SLO. enum: @@ -13479,8 +13542,16 @@ components: type: string query: $ref: '#/components/schemas/ServiceLevelObjectiveQuery' + description: 'The metric query of good / total events. This is not allowed + if the `sli_specification` field + + is used in the same request.' sli_specification: $ref: '#/components/schemas/SLOSliSpec' + description: 'A generic SLI specification. This is currently used for time-slice + and metric SLOs only. + + This is not allowed if the `query` field is used in the same request.' tags: description: 'A list of tags associated with this service level objective. @@ -13540,8 +13611,8 @@ 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 now deprecated metric 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 @@ -13610,8 +13681,16 @@ components: type: string query: $ref: '#/components/schemas/ServiceLevelObjectiveQuery' + description: 'The metric query of good / total events. This is not allowed + if the `sli_specification` field + + is used in the same request.' sli_specification: $ref: '#/components/schemas/SLOSliSpec' + description: 'A generic SLI specification. This is currently used for time-slice + and metric SLOs only. + + This is not allowed if the `query` field is used in the same request.' tags: description: 'A list of tags associated with this service level objective. diff --git a/src/datadogV1/model/mod.rs b/src/datadogV1/model/mod.rs index 10dc3359a..de5ae52d5 100644 --- a/src/datadogV1/model/mod.rs +++ b/src/datadogV1/model/mod.rs @@ -1232,6 +1232,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; diff --git a/src/datadogV1/model/model_service_level_objective.rs b/src/datadogV1/model/model_service_level_objective.rs index 6f0a90228..2733d53a4 100644 --- a/src/datadogV1/model/model_service_level_objective.rs +++ b/src/datadogV1/model/model_service_level_objective.rs @@ -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 now deprecated metric 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, - /// 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 metric SLOs only. #[serde(rename = "sli_specification")] pub sli_specification: Option, /// A list of tags associated with this service level objective. diff --git a/src/datadogV1/model/model_service_level_objective_query.rs b/src/datadogV1/model/model_service_level_objective_query.rs index ef4e31f8f..46fc23239 100644 --- a/src/datadogV1/model/model_service_level_objective_query.rs +++ b/src/datadogV1/model/model_service_level_objective_query.rs @@ -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 now deprecated metric 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] diff --git a/src/datadogV1/model/model_service_level_objective_request.rs b/src/datadogV1/model/model_service_level_objective_request.rs index 1a673bd88..0c2fbaf92 100644 --- a/src/datadogV1/model/model_service_level_objective_request.rs +++ b/src/datadogV1/model/model_service_level_objective_request.rs @@ -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 now deprecated metric 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, - /// 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 metric SLOs only. #[serde(rename = "sli_specification")] pub sli_specification: Option, /// A list of tags associated with this service level objective. diff --git a/src/datadogV1/model/model_slo_count_condition.rs b/src/datadogV1/model/model_slo_count_condition.rs new file mode 100644 index 000000000..14868a0ef --- /dev/null +++ b/src/datadogV1/model/model_slo_count_condition.rs @@ -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 metric 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, + /// 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, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl SLOCountCondition { + pub fn new( + good_events_formula: crate::datadogV1::model::SLOFormula, + queries: Vec, + 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, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for SLOCountCondition { + fn deserialize(deserializer: D) -> Result + 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(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut good_events_formula: Option = None; + let mut queries: Option< + Vec, + > = None; + let mut total_events_formula: Option = 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::()? { + 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) + } +} diff --git a/src/datadogV1/model/model_slo_count_spec.rs b/src/datadogV1/model/model_slo_count_spec.rs new file mode 100644 index 000000000..f5db2f5cd --- /dev/null +++ b/src/datadogV1/model/model_slo_count_spec.rs @@ -0,0 +1,74 @@ +// 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 metric SLI specification. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct SLOCountSpec { + /// A metric SLI specification, composed of three parts: the good events formula, the total events formula, + /// and the involved queries. + #[serde(rename = "count")] + pub count: crate::datadogV1::model::SLOCountCondition, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl SLOCountSpec { + pub fn new(count: crate::datadogV1::model::SLOCountCondition) -> SLOCountSpec { + SLOCountSpec { + count, + _unparsed: false, + } + } +} + +impl<'de> Deserialize<'de> for SLOCountSpec { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct SLOCountSpecVisitor; + impl<'a> Visitor<'a> for SLOCountSpecVisitor { + type Value = SLOCountSpec; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut count: Option = None; + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "count" => { + count = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + return Err(serde::de::Error::custom( + "Additional properties not allowed", + )); + } + } + } + let count = count.ok_or_else(|| M::Error::missing_field("count"))?; + + let content = SLOCountSpec { count, _unparsed }; + + Ok(content) + } + } + + deserializer.deserialize_any(SLOCountSpecVisitor) + } +} diff --git a/src/datadogV1/model/model_slo_response_data.rs b/src/datadogV1/model/model_slo_response_data.rs index 56b1e9ac5..5bd2cab53 100644 --- a/src/datadogV1/model/model_slo_response_data.rs +++ b/src/datadogV1/model/model_slo_response_data.rs @@ -65,12 +65,12 @@ pub struct SLOResponseData { /// The name of the service level objective object. #[serde(rename = "name")] pub name: Option, - /// A metric-based SLO. **Required if type is `metric`**. Note that Datadog only allows the sum by aggregator + /// A now deprecated metric 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, - /// 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 metric SLOs only. #[serde(rename = "sli_specification")] pub sli_specification: Option, /// A list of tags associated with this service level objective. diff --git a/src/datadogV1/model/model_slo_sli_spec.rs b/src/datadogV1/model/model_slo_sli_spec.rs index 12687266a..5b07b5d1b 100644 --- a/src/datadogV1/model/model_slo_sli_spec.rs +++ b/src/datadogV1/model/model_slo_sli_spec.rs @@ -3,12 +3,13 @@ // Copyright 2019-Present Datadog, Inc. use serde::{Deserialize, Deserializer, Serialize}; -/// 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 metric SLOs only. #[non_exhaustive] #[derive(Clone, Debug, PartialEq, Serialize)] #[serde(untagged)] pub enum SLOSliSpec { SLOTimeSliceSpec(Box), + SLOCountSpec(Box), UnparsedObject(crate::datadog::UnparsedObject), } @@ -25,6 +26,13 @@ impl<'de> Deserialize<'de> for SLOSliSpec { return Ok(SLOSliSpec::SLOTimeSliceSpec(_v)); } } + if let Ok(_v) = + serde_json::from_value::>(value.clone()) + { + if !_v._unparsed { + return Ok(SLOSliSpec::SLOCountSpec(_v)); + } + } return Ok(SLOSliSpec::UnparsedObject(crate::datadog::UnparsedObject { value,