Skip to content

Commit beba5f3

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Dashboards - Add semantic_mode support to FormulaAndFunctionMetricQueryDefinition (#1066)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 8b6e2d5 commit beba5f3

11 files changed

+367
-0
lines changed

.generator/schemas/v1/openapi.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,11 +2952,24 @@ components:
29522952
description: Metrics query definition.
29532953
example: avg:system.cpu.user{*}
29542954
type: string
2955+
semantic_mode:
2956+
$ref: '#/components/schemas/FormulaAndFunctionMetricSemanticMode'
29552957
required:
29562958
- data_source
29572959
- query
29582960
- name
29592961
type: object
2962+
FormulaAndFunctionMetricSemanticMode:
2963+
description: Semantic mode for metrics queries. This determines how metrics
2964+
from different sources are combined or displayed.
2965+
enum:
2966+
- combined
2967+
- native
2968+
example: combined
2969+
type: string
2970+
x-enum-varnames:
2971+
- COMBINED
2972+
- NATIVE
29602973
FormulaAndFunctionProcessQueryDataSource:
29612974
description: Data sources that rely on the process backend.
29622975
enum:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Create a new dashboard with a timeseries widget using formulas and functions
2+
// metrics query with native semantic_mode
3+
use datadog_api_client::datadog;
4+
use datadog_api_client::datadogV1::api_dashboards::DashboardsAPI;
5+
use datadog_api_client::datadogV1::model::Dashboard;
6+
use datadog_api_client::datadogV1::model::DashboardLayoutType;
7+
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
8+
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
9+
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricSemanticMode;
10+
use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition;
11+
use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat;
12+
use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinition;
13+
use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinitionType;
14+
use datadog_api_client::datadogV1::model::TimeseriesWidgetRequest;
15+
use datadog_api_client::datadogV1::model::Widget;
16+
use datadog_api_client::datadogV1::model::WidgetDefinition;
17+
use datadog_api_client::datadogV1::model::WidgetDisplayType;
18+
use datadog_api_client::datadogV1::model::WidgetFormula;
19+
20+
#[tokio::main]
21+
async fn main() {
22+
let body = Dashboard::new(
23+
DashboardLayoutType::ORDERED,
24+
"Example-Dashboard with native semantic_mode".to_string(),
25+
vec![Widget::new(WidgetDefinition::TimeseriesWidgetDefinition(
26+
Box::new(TimeseriesWidgetDefinition::new(
27+
vec![TimeseriesWidgetRequest::new()
28+
.display_type(WidgetDisplayType::LINE)
29+
.formulas(vec![WidgetFormula::new("query1".to_string())])
30+
.queries(vec![
31+
FormulaAndFunctionQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
32+
Box::new(
33+
FormulaAndFunctionMetricQueryDefinition::new(
34+
FormulaAndFunctionMetricDataSource::METRICS,
35+
"query1".to_string(),
36+
"avg:system.cpu.user{*}".to_string(),
37+
)
38+
.semantic_mode(FormulaAndFunctionMetricSemanticMode::NATIVE),
39+
),
40+
),
41+
])
42+
.response_format(FormulaAndFunctionResponseFormat::TIMESERIES)],
43+
TimeseriesWidgetDefinitionType::TIMESERIES,
44+
)),
45+
))],
46+
);
47+
let configuration = datadog::Configuration::new();
48+
let api = DashboardsAPI::with_config(configuration);
49+
let resp = api.create_dashboard(body).await;
50+
if let Ok(value) = resp {
51+
println!("{:#?}", value);
52+
} else {
53+
println!("{:#?}", resp.unwrap_err());
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Create a new dashboard with a timeseries widget using formulas and functions
2+
// metrics query with combined semantic_mode
3+
use datadog_api_client::datadog;
4+
use datadog_api_client::datadogV1::api_dashboards::DashboardsAPI;
5+
use datadog_api_client::datadogV1::model::Dashboard;
6+
use datadog_api_client::datadogV1::model::DashboardLayoutType;
7+
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
8+
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
9+
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricSemanticMode;
10+
use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition;
11+
use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat;
12+
use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinition;
13+
use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinitionType;
14+
use datadog_api_client::datadogV1::model::TimeseriesWidgetRequest;
15+
use datadog_api_client::datadogV1::model::Widget;
16+
use datadog_api_client::datadogV1::model::WidgetDefinition;
17+
use datadog_api_client::datadogV1::model::WidgetDisplayType;
18+
use datadog_api_client::datadogV1::model::WidgetFormula;
19+
20+
#[tokio::main]
21+
async fn main() {
22+
let body = Dashboard::new(
23+
DashboardLayoutType::ORDERED,
24+
"Example-Dashboard with combined semantic_mode".to_string(),
25+
vec![Widget::new(WidgetDefinition::TimeseriesWidgetDefinition(
26+
Box::new(TimeseriesWidgetDefinition::new(
27+
vec![TimeseriesWidgetRequest::new()
28+
.display_type(WidgetDisplayType::LINE)
29+
.formulas(vec![WidgetFormula::new("query1".to_string())])
30+
.queries(vec![
31+
FormulaAndFunctionQueryDefinition::FormulaAndFunctionMetricQueryDefinition(
32+
Box::new(
33+
FormulaAndFunctionMetricQueryDefinition::new(
34+
FormulaAndFunctionMetricDataSource::METRICS,
35+
"query1".to_string(),
36+
"avg:system.cpu.user{*}".to_string(),
37+
)
38+
.semantic_mode(FormulaAndFunctionMetricSemanticMode::COMBINED),
39+
),
40+
),
41+
])
42+
.response_format(FormulaAndFunctionResponseFormat::TIMESERIES)],
43+
TimeseriesWidgetDefinitionType::TIMESERIES,
44+
)),
45+
))],
46+
);
47+
let configuration = datadog::Configuration::new();
48+
let api = DashboardsAPI::with_config(configuration);
49+
let resp = api.create_dashboard(body).await;
50+
if let Ok(value) = resp {
51+
println!("{:#?}", value);
52+
} else {
53+
println!("{:#?}", resp.unwrap_err());
54+
}
55+
}

src/datadogV1/model/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ pub mod model_formula_and_function_metric_aggregation;
194194
pub use self::model_formula_and_function_metric_aggregation::FormulaAndFunctionMetricAggregation;
195195
pub mod model_formula_and_function_metric_data_source;
196196
pub use self::model_formula_and_function_metric_data_source::FormulaAndFunctionMetricDataSource;
197+
pub mod model_formula_and_function_metric_semantic_mode;
198+
pub use self::model_formula_and_function_metric_semantic_mode::FormulaAndFunctionMetricSemanticMode;
197199
pub mod model_formula_and_function_event_query_definition;
198200
pub use self::model_formula_and_function_event_query_definition::FormulaAndFunctionEventQueryDefinition;
199201
pub mod model_formula_and_function_event_query_definition_compute;

src/datadogV1/model/model_formula_and_function_metric_query_definition.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub struct FormulaAndFunctionMetricQueryDefinition {
2626
/// Metrics query definition.
2727
#[serde(rename = "query")]
2828
pub query: String,
29+
/// Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed.
30+
#[serde(rename = "semantic_mode")]
31+
pub semantic_mode: Option<crate::datadogV1::model::FormulaAndFunctionMetricSemanticMode>,
2932
#[serde(flatten)]
3033
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
3134
#[serde(skip)]
@@ -45,6 +48,7 @@ impl FormulaAndFunctionMetricQueryDefinition {
4548
data_source,
4649
name,
4750
query,
51+
semantic_mode: None,
4852
additional_properties: std::collections::BTreeMap::new(),
4953
_unparsed: false,
5054
}
@@ -63,6 +67,14 @@ impl FormulaAndFunctionMetricQueryDefinition {
6367
self
6468
}
6569

70+
pub fn semantic_mode(
71+
mut self,
72+
value: crate::datadogV1::model::FormulaAndFunctionMetricSemanticMode,
73+
) -> Self {
74+
self.semantic_mode = Some(value);
75+
self
76+
}
77+
6678
pub fn additional_properties(
6779
mut self,
6880
value: std::collections::BTreeMap<String, serde_json::Value>,
@@ -98,6 +110,9 @@ impl<'de> Deserialize<'de> for FormulaAndFunctionMetricQueryDefinition {
98110
> = None;
99111
let mut name: Option<String> = None;
100112
let mut query: Option<String> = None;
113+
let mut semantic_mode: Option<
114+
crate::datadogV1::model::FormulaAndFunctionMetricSemanticMode,
115+
> = None;
101116
let mut additional_properties: std::collections::BTreeMap<
102117
String,
103118
serde_json::Value,
@@ -145,6 +160,21 @@ impl<'de> Deserialize<'de> for FormulaAndFunctionMetricQueryDefinition {
145160
"query" => {
146161
query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
147162
}
163+
"semantic_mode" => {
164+
if v.is_null() {
165+
continue;
166+
}
167+
semantic_mode =
168+
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
169+
if let Some(ref _semantic_mode) = semantic_mode {
170+
match _semantic_mode {
171+
crate::datadogV1::model::FormulaAndFunctionMetricSemanticMode::UnparsedObject(_semantic_mode) => {
172+
_unparsed = true;
173+
},
174+
_ => {}
175+
}
176+
}
177+
}
148178
&_ => {
149179
if let Ok(value) = serde_json::from_value(v.clone()) {
150180
additional_properties.insert(k, value);
@@ -163,6 +193,7 @@ impl<'de> Deserialize<'de> for FormulaAndFunctionMetricQueryDefinition {
163193
data_source,
164194
name,
165195
query,
196+
semantic_mode,
166197
additional_properties,
167198
_unparsed,
168199
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
6+
7+
#[non_exhaustive]
8+
#[derive(Clone, Debug, Eq, PartialEq)]
9+
pub enum FormulaAndFunctionMetricSemanticMode {
10+
COMBINED,
11+
NATIVE,
12+
UnparsedObject(crate::datadog::UnparsedObject),
13+
}
14+
15+
impl ToString for FormulaAndFunctionMetricSemanticMode {
16+
fn to_string(&self) -> String {
17+
match self {
18+
Self::COMBINED => String::from("combined"),
19+
Self::NATIVE => String::from("native"),
20+
Self::UnparsedObject(v) => v.value.to_string(),
21+
}
22+
}
23+
}
24+
25+
impl Serialize for FormulaAndFunctionMetricSemanticMode {
26+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
27+
where
28+
S: Serializer,
29+
{
30+
match self {
31+
Self::UnparsedObject(v) => v.serialize(serializer),
32+
_ => serializer.serialize_str(self.to_string().as_str()),
33+
}
34+
}
35+
}
36+
37+
impl<'de> Deserialize<'de> for FormulaAndFunctionMetricSemanticMode {
38+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
39+
where
40+
D: Deserializer<'de>,
41+
{
42+
let s: String = String::deserialize(deserializer)?;
43+
Ok(match s.as_str() {
44+
"combined" => Self::COMBINED,
45+
"native" => Self::NATIVE,
46+
_ => Self::UnparsedObject(crate::datadog::UnparsedObject {
47+
value: serde_json::Value::String(s.into()),
48+
}),
49+
})
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-12-08T18:40:10.047Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"http_interactions": [
3+
{
4+
"request": {
5+
"body": {
6+
"string": "{\"layout_type\":\"ordered\",\"title\":\"Test-Create_a_new_dashboard_with_a_timeseries_widget_using_formulas_and_functions_metrics_query_with_comb-1765219210 with combined semantic_mode\",\"widgets\":[{\"definition\":{\"requests\":[{\"display_type\":\"line\",\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"avg:system.cpu.user{*}\",\"semantic_mode\":\"combined\"}],\"response_format\":\"timeseries\"}],\"type\":\"timeseries\"}}]}",
7+
"encoding": null
8+
},
9+
"headers": {
10+
"Accept": [
11+
"application/json"
12+
],
13+
"Content-Type": [
14+
"application/json"
15+
]
16+
},
17+
"method": "post",
18+
"uri": "https://api.datadoghq.com/api/v1/dashboard"
19+
},
20+
"response": {
21+
"body": {
22+
"string": "{\"id\":\"bpt-wdw-b9x\",\"title\":\"Test-Create_a_new_dashboard_with_a_timeseries_widget_using_formulas_and_functions_metrics_query_with_comb-1765219210 with combined semantic_mode\",\"description\":null,\"author_handle\":\"[email protected]\",\"author_name\":\"frog\",\"layout_type\":\"ordered\",\"url\":\"/dashboard/bpt-wdw-b9x/test-createanewdashboardwithatimeserieswidgetusingformulasandfunctionsmetricsque\",\"template_variables\":null,\"widgets\":[{\"definition\":{\"requests\":[{\"display_type\":\"line\",\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"avg:system.cpu.user{*}\",\"semantic_mode\":\"combined\"}],\"response_format\":\"timeseries\"}],\"type\":\"timeseries\"},\"id\":7196642548461969}],\"notify_list\":null,\"created_at\":\"2025-12-08T18:40:10.214467+00:00\",\"modified_at\":\"2025-12-08T18:40:10.214467+00:00\",\"restricted_roles\":[]}",
23+
"encoding": null
24+
},
25+
"headers": {
26+
"Content-Type": [
27+
"application/json"
28+
]
29+
},
30+
"status": {
31+
"code": 200,
32+
"message": "OK"
33+
}
34+
},
35+
"recorded_at": "Mon, 08 Dec 2025 18:40:10 GMT"
36+
},
37+
{
38+
"request": {
39+
"body": "",
40+
"headers": {
41+
"Accept": [
42+
"application/json"
43+
]
44+
},
45+
"method": "delete",
46+
"uri": "https://api.datadoghq.com/api/v1/dashboard/bpt-wdw-b9x"
47+
},
48+
"response": {
49+
"body": {
50+
"string": "{\"deleted_dashboard_id\":\"bpt-wdw-b9x\"}",
51+
"encoding": null
52+
},
53+
"headers": {
54+
"Content-Type": [
55+
"application/json"
56+
]
57+
},
58+
"status": {
59+
"code": 200,
60+
"message": "OK"
61+
}
62+
},
63+
"recorded_at": "Mon, 08 Dec 2025 18:40:10 GMT"
64+
}
65+
],
66+
"recorded_with": "VCR 6.0.0"
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-12-08T18:32:38.191Z

0 commit comments

Comments
 (0)