Skip to content
Merged
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
64 changes: 52 additions & 12 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12338,33 +12338,73 @@ components:
type: object
SLOCountDefinition:
description: 'A count-based (metric) SLI specification, composed of three parts:
the good events formula, the total events formula,
the good events formula,

and the underlying queries.'
the bad or total events formula, and the underlying queries.

Exactly one of `total_events_formula` or `bad_events_formula` must be provided.'
example:
good_events_formula: query1 - query2
bad_events_formula: query2
good_events_formula: query1
queries:
- data_source: metrics
name: query1
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
query: sum:trace.servlet.request.hits{!http.status_code:500} by {env}.as_count()
- data_source: metrics
name: query2
query: sum:trace.servlet.request.errors{*} by {env}.as_count()
total_events_formula: query1
query: sum:trace.servlet.request.hits{http.status_code:500} by {env}.as_count()
oneOf:
- $ref: '#/components/schemas/SLOCountDefinitionWithTotalEventsFormula'
- $ref: '#/components/schemas/SLOCountDefinitionWithBadEventsFormula'
SLOCountDefinitionWithBadEventsFormula:
additionalProperties: false
properties:
bad_events_formula:
$ref: '#/components/schemas/SLOFormula'
description: The bad events formula (recommended). Total events queries
can be defined using the `total_events_formula` field as an alternative.
Only one of `total_events_formula` or `bad_events_formula` must be provided.
good_events_formula:
$ref: '#/components/schemas/SLOFormula'
queries:
example:
- data_source: metrics
name: query1
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
query: sum:trace.servlet.request.hits{!http.status_code:500} by {env}.as_count()
- data_source: metrics
name: query2
query: sum:trace.servlet.request.hits{http.status_code:500} by {env}.as_count()
items:
$ref: '#/components/schemas/SLODataSourceQueryDefinition'
minItems: 1
type: array
required:
- good_events_formula
- bad_events_formula
- queries
type: object
SLOCountDefinitionWithTotalEventsFormula:
additionalProperties: false
properties:
good_events_formula:
$ref: '#/components/schemas/SLOFormula'
queries:
example:
- data_source: metrics
name: query1
query: sum:trace.servlet.request.hits{!http.status_code:500} by {env}.as_count()
- data_source: metrics
name: query2
query: sum:trace.servlet.request.hits{http.status_code:500} by {env}.as_count()
items:
$ref: '#/components/schemas/SLODataSourceQueryDefinition'
minItems: 1
type: array
total_events_formula:
$ref: '#/components/schemas/SLOFormula'
description: The total events formula. Bad events queries can be defined
using the `bad_events_formula` field as an alternative. Only one of `total_events_formula`
or `bad_events_formula` must be provided.
required:
- good_events_formula
- total_events_formula
Expand All @@ -12375,15 +12415,15 @@ components:
description: A metric SLI specification.
example:
count:
good_events_formula: query1 - query2
bad_events_formula: query2
good_events_formula: query1
queries:
- data_source: metrics
name: query1
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
query: sum:trace.servlet.request.hits{!http.status_code:500} by {env}.as_count()
- data_source: metrics
name: query2
query: sum:trace.servlet.request.errors{*} by {env}.as_count()
total_events_formula: query1
query: sum:trace.servlet.request.hits{http.status_code:500} by {env}.as_count()
properties:
count:
$ref: '#/components/schemas/SLOCountDefinition'
Expand Down Expand Up @@ -13519,7 +13559,7 @@ components:
name: query1
query: sum:trace.servlet.request.hits{*} by {env}.as_count()
- data_source: metrics
name: query1
name: query2
query: sum:trace.servlet.request.errors{*} by {env}.as_count()
threshold: 5
properties:
Expand Down
39 changes: 21 additions & 18 deletions examples/v1_service-level-objectives_CreateSLO_512760759.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use datadog_api_client::datadogV1::api_service_level_objectives::ServiceLevelObj
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
use datadog_api_client::datadogV1::model::SLOCountDefinition;
use datadog_api_client::datadogV1::model::SLOCountDefinitionWithTotalEventsFormula;
use datadog_api_client::datadogV1::model::SLOCountSpec;
use datadog_api_client::datadogV1::model::SLODataSourceQueryDefinition;
use datadog_api_client::datadogV1::model::SLOFormula;
Expand All @@ -25,26 +26,28 @@ async fn main() {
)
.description(Some("Metric SLO using sli_specification".to_string()))
.sli_specification(SLOSliSpec::SLOCountSpec(Box::new(SLOCountSpec::new(
SLOCountDefinition::new(
SLOFormula::new("query1 - query2".to_string()),
vec![
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(Box::new(
FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query1".to_string(),
"sum:httpservice.hits{*}.as_count()".to_string(),
SLOCountDefinition::SLOCountDefinitionWithTotalEventsFormula(Box::new(
SLOCountDefinitionWithTotalEventsFormula::new(
SLOFormula::new("query1 - query2".to_string()),
vec![
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
Box::new(FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query1".to_string(),
"sum:httpservice.hits{*}.as_count()".to_string(),
)),
),
)),
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(Box::new(
FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query2".to_string(),
"sum:httpservice.errors{*}.as_count()".to_string(),
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
Box::new(FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query2".to_string(),
"sum:httpservice.errors{*}.as_count()".to_string(),
)),
),
)),
],
SLOFormula::new("query1".to_string()),
),
],
SLOFormula::new("query1".to_string()),
),
)),
))))
.tags(vec!["env:prod".to_string(), "type:count".to_string()])
.target_threshold(99.0 as f64)
Expand Down
64 changes: 64 additions & 0 deletions examples/v1_service-level-objectives_CreateSLO_707861409.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Create a new metric SLO object using bad events formula 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::SLOCountDefinition;
use datadog_api_client::datadogV1::model::SLOCountDefinitionWithBadEventsFormula;
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(99.5 as f64)
.warning_display("99.5".to_string())],
SLOType::METRIC,
)
.description(Some("Metric SLO using sli_specification".to_string()))
.sli_specification(SLOSliSpec::SLOCountSpec(Box::new(SLOCountSpec::new(
SLOCountDefinition::SLOCountDefinitionWithBadEventsFormula(Box::new(
SLOCountDefinitionWithBadEventsFormula::new(
SLOFormula::new("query2".to_string()),
SLOFormula::new("query1 - query2".to_string()),
vec![
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
Box::new(FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query1".to_string(),
"sum:httpservice.hits{*}.as_count()".to_string(),
)),
),
SLODataSourceQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
Box::new(FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query2".to_string(),
"sum:httpservice.errors{*}.as_count()".to_string(),
)),
),
],
),
)),
))))
.tags(vec!["env:prod".to_string(), "type:count".to_string()])
.target_threshold(99.0 as f64)
.timeframe(SLOTimeframe::SEVEN_DAYS)
.warning_threshold(99.5 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 @@ -1308,6 +1308,10 @@ 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_definition_with_total_events_formula;
pub use self::model_slo_count_definition_with_total_events_formula::SLOCountDefinitionWithTotalEventsFormula;
pub mod model_slo_count_definition_with_bad_events_formula;
pub use self::model_slo_count_definition_with_bad_events_formula::SLOCountDefinitionWithBadEventsFormula;
pub mod model_slo_count_definition;
pub use self::model_slo_count_definition::SLOCountDefinition;
pub mod model_slo_sli_spec;
Expand Down
133 changes: 31 additions & 102 deletions src/datadogV1/model/model_slo_count_definition.rs
Original file line number Diff line number Diff line change
@@ -1,122 +1,51 @@
// 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 (metric) SLI specification, composed of three parts: the good events formula, the total events formula,
/// and the underlying queries.
/// A count-based (metric) SLI specification, composed of three parts: the good events formula,
/// the bad or total events formula, and the underlying queries.
/// Exactly one of `total_events_formula` or `bad_events_formula` must be provided.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct SLOCountDefinition {
/// 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 SLOCountDefinition {
pub fn new(
good_events_formula: crate::datadogV1::model::SLOFormula,
queries: Vec<crate::datadogV1::model::SLODataSourceQueryDefinition>,
total_events_formula: crate::datadogV1::model::SLOFormula,
) -> SLOCountDefinition {
SLOCountDefinition {
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
}
#[serde(untagged)]
pub enum SLOCountDefinition {
SLOCountDefinitionWithTotalEventsFormula(
Box<crate::datadogV1::model::SLOCountDefinitionWithTotalEventsFormula>,
),
SLOCountDefinitionWithBadEventsFormula(
Box<crate::datadogV1::model::SLOCountDefinitionWithBadEventsFormula>,
),
UnparsedObject(crate::datadog::UnparsedObject),
}

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

fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
let value: serde_json::Value = Deserialize::deserialize(deserializer)?;
if let Ok(_v) = serde_json::from_value::<
Box<crate::datadogV1::model::SLOCountDefinitionWithTotalEventsFormula>,
>(value.clone())
{
if !_v._unparsed {
return Ok(SLOCountDefinition::SLOCountDefinitionWithTotalEventsFormula(_v));
}

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 = SLOCountDefinition {
good_events_formula,
queries,
total_events_formula,
additional_properties,
_unparsed,
};

Ok(content)
}
if let Ok(_v) = serde_json::from_value::<
Box<crate::datadogV1::model::SLOCountDefinitionWithBadEventsFormula>,
>(value.clone())
{
if !_v._unparsed {
return Ok(SLOCountDefinition::SLOCountDefinitionWithBadEventsFormula(
_v,
));
}
}

deserializer.deserialize_any(SLOCountDefinitionVisitor)
return Ok(SLOCountDefinition::UnparsedObject(
crate::datadog::UnparsedObject { value },
));
}
}
Loading
Loading