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
2 changes: 2 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,7 @@ components:
- ci_tests
- ci_pipelines
- incident_analytics
- product_analytics
example: logs
type: string
x-enum-varnames:
Expand All @@ -2889,6 +2890,7 @@ components:
- CI_TESTS
- CI_PIPELINES
- INCIDENT_ANALYTICS
- PRODUCT_ANALYTICS
FormulaAndFunctionMetricAggregation:
description: The aggregation methods available for metrics queries.
enum:
Expand Down
103 changes: 103 additions & 0 deletions examples/v1_dashboards_CreateDashboard_607525069.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Create a new timeseries widget with product_analytics data source
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_dashboards::DashboardsAPI;
use datadog_api_client::datadogV1::model::Dashboard;
use datadog_api_client::datadogV1::model::DashboardLayoutType;
use datadog_api_client::datadogV1::model::DashboardReflowType;
use datadog_api_client::datadogV1::model::FormulaAndFunctionEventAggregation;
use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinition;
use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinitionCompute;
use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinitionSearch;
use datadog_api_client::datadogV1::model::FormulaAndFunctionEventsDataSource;
use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition;
use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat;
use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinition;
use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinitionType;
use datadog_api_client::datadogV1::model::TimeseriesWidgetLegendColumn;
use datadog_api_client::datadogV1::model::TimeseriesWidgetLegendLayout;
use datadog_api_client::datadogV1::model::TimeseriesWidgetRequest;
use datadog_api_client::datadogV1::model::Widget;
use datadog_api_client::datadogV1::model::WidgetDefinition;
use datadog_api_client::datadogV1::model::WidgetDisplayType;
use datadog_api_client::datadogV1::model::WidgetFormula;
use datadog_api_client::datadogV1::model::WidgetLegacyLiveSpan;
use datadog_api_client::datadogV1::model::WidgetLineType;
use datadog_api_client::datadogV1::model::WidgetLineWidth;
use datadog_api_client::datadogV1::model::WidgetRequestStyle;
use datadog_api_client::datadogV1::model::WidgetTime;

#[tokio::main]
async fn main() {
let body =
Dashboard::new(
DashboardLayoutType::ORDERED,
"Example-Dashboard with product_analytics datasource".to_string(),
vec![
Widget::new(
WidgetDefinition::TimeseriesWidgetDefinition(
Box::new(
TimeseriesWidgetDefinition::new(
vec![
TimeseriesWidgetRequest::new()
.display_type(WidgetDisplayType::LINE)
.formulas(vec![WidgetFormula::new("query1".to_string())])
.queries(
vec![
FormulaAndFunctionQueryDefinition
::FormulaAndFunctionEventQueryDefinition(
Box::new(
FormulaAndFunctionEventQueryDefinition::new(
FormulaAndFunctionEventQueryDefinitionCompute::new(
FormulaAndFunctionEventAggregation::COUNT,
),
FormulaAndFunctionEventsDataSource::PRODUCT_ANALYTICS,
"query1".to_string(),
)
.group_by(vec![])
.indexes(vec!["*".to_string()])
.search(
FormulaAndFunctionEventQueryDefinitionSearch::new(
"test_level:test".to_string(),
),
),
),
)
],
)
.response_format(FormulaAndFunctionResponseFormat::TIMESERIES)
.style(
WidgetRequestStyle::new()
.line_type(WidgetLineType::SOLID)
.line_width(WidgetLineWidth::NORMAL)
.palette("dog_classic".to_string()),
)
],
TimeseriesWidgetDefinitionType::TIMESERIES,
)
.legend_columns(
vec![
TimeseriesWidgetLegendColumn::AVG,
TimeseriesWidgetLegendColumn::MIN,
TimeseriesWidgetLegendColumn::MAX,
TimeseriesWidgetLegendColumn::VALUE,
TimeseriesWidgetLegendColumn::SUM
],
)
.legend_layout(TimeseriesWidgetLegendLayout::AUTO)
.show_legend(true)
.time(WidgetTime::WidgetLegacyLiveSpan(Box::new(WidgetLegacyLiveSpan::new())))
.title("".to_string()),
),
),
)
],
).reflow_type(DashboardReflowType::AUTO);
let configuration = datadog::Configuration::new();
let api = DashboardsAPI::with_config(configuration);
let resp = api.create_dashboard(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum FormulaAndFunctionEventsDataSource {
CI_TESTS,
CI_PIPELINES,
INCIDENT_ANALYTICS,
PRODUCT_ANALYTICS,
UnparsedObject(crate::datadog::UnparsedObject),
}

Expand All @@ -35,6 +36,7 @@ impl ToString for FormulaAndFunctionEventsDataSource {
Self::CI_TESTS => String::from("ci_tests"),
Self::CI_PIPELINES => String::from("ci_pipelines"),
Self::INCIDENT_ANALYTICS => String::from("incident_analytics"),
Self::PRODUCT_ANALYTICS => String::from("product_analytics"),
Self::UnparsedObject(v) => v.value.to_string(),
}
}
Expand Down Expand Up @@ -70,6 +72,7 @@ impl<'de> Deserialize<'de> for FormulaAndFunctionEventsDataSource {
"ci_tests" => Self::CI_TESTS,
"ci_pipelines" => Self::CI_PIPELINES,
"incident_analytics" => Self::INCIDENT_ANALYTICS,
"product_analytics" => Self::PRODUCT_ANALYTICS,
_ => Self::UnparsedObject(crate::datadog::UnparsedObject {
value: serde_json::Value::String(s.into()),
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2025-09-18T18:51:17.951Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"http_interactions": [
{
"request": {
"body": {
"string": "{\"layout_type\":\"ordered\",\"reflow_type\":\"auto\",\"title\":\"Test-Create_a_new_timeseries_widget_with_product_analytics_data_source-1758221477 with product_analytics datasource\",\"widgets\":[{\"definition\":{\"legend_columns\":[\"avg\",\"min\",\"max\",\"value\",\"sum\"],\"legend_layout\":\"auto\",\"requests\":[{\"display_type\":\"line\",\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"compute\":{\"aggregation\":\"count\"},\"data_source\":\"product_analytics\",\"group_by\":[],\"indexes\":[\"*\"],\"name\":\"query1\",\"search\":{\"query\":\"test_level:test\"}}],\"response_format\":\"timeseries\",\"style\":{\"line_type\":\"solid\",\"line_width\":\"normal\",\"palette\":\"dog_classic\"}}],\"show_legend\":true,\"time\":{},\"title\":\"\",\"type\":\"timeseries\"}}]}",
"encoding": null
},
"headers": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json"
]
},
"method": "post",
"uri": "https://api.datadoghq.com/api/v1/dashboard"
},
"response": {
"body": {
"string": "{\"id\":\"zvr-td5-ppm\",\"title\":\"Test-Create_a_new_timeseries_widget_with_product_analytics_data_source-1758221477 with product_analytics datasource\",\"description\":null,\"author_handle\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"author_name\":\"CI Account\",\"layout_type\":\"ordered\",\"url\":\"/dashboard/zvr-td5-ppm/test-createanewtimeserieswidgetwithproductanalyticsdatasource-1758221477-with-pr\",\"template_variables\":null,\"widgets\":[{\"definition\":{\"legend_columns\":[\"avg\",\"min\",\"max\",\"value\",\"sum\"],\"legend_layout\":\"auto\",\"requests\":[{\"display_type\":\"line\",\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"compute\":{\"aggregation\":\"count\"},\"data_source\":\"product_analytics\",\"group_by\":[],\"indexes\":[\"*\"],\"name\":\"query1\",\"search\":{\"query\":\"test_level:test\"}}],\"response_format\":\"timeseries\",\"style\":{\"line_type\":\"solid\",\"line_width\":\"normal\",\"palette\":\"dog_classic\"}}],\"show_legend\":true,\"time\":{},\"title\":\"\",\"type\":\"timeseries\"},\"id\":6058978575853641}],\"notify_list\":null,\"created_at\":\"2025-09-18T18:51:18.107135+00:00\",\"modified_at\":\"2025-09-18T18:51:18.107135+00:00\",\"reflow_type\":\"auto\",\"restricted_roles\":[]}",
"encoding": null
},
"headers": {
"Content-Type": [
"application/json"
]
},
"status": {
"code": 200,
"message": "OK"
}
},
"recorded_at": "Thu, 18 Sep 2025 18:51:17 GMT"
},
{
"request": {
"body": "",
"headers": {
"Accept": [
"application/json"
]
},
"method": "delete",
"uri": "https://api.datadoghq.com/api/v1/dashboard/zvr-td5-ppm"
},
"response": {
"body": {
"string": "{\"deleted_dashboard_id\":\"zvr-td5-ppm\"}\n",
"encoding": null
},
"headers": {
"Content-Type": [
"application/json"
]
},
"status": {
"code": 200,
"message": "OK"
}
},
"recorded_at": "Thu, 18 Sep 2025 18:51:17 GMT"
}
],
"recorded_with": "VCR 6.0.0"
}
9 changes: 9 additions & 0 deletions tests/scenarios/features/v1/dashboards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,15 @@ Feature: Dashboards
And the response "widgets[0].definition.time.value" is equal to 8
And the response "widgets[0].definition.time.hide_incomplete_cost_data" is equal to true

@team:DataDog/dashboards-backend
Scenario: Create a new timeseries widget with product_analytics data source
Given new "CreateDashboard" request
And body with value {"title":"{{ unique }} with product_analytics datasource","widgets":[{"definition":{"title":"","show_legend":true,"legend_layout":"auto","legend_columns":["avg","min","max","value","sum"],"time":{},"type":"timeseries","requests":[{"formulas":[{"formula":"query1"}],"queries":[{"data_source":"product_analytics","name":"query1","search":{"query":"test_level:test"},"indexes":["*"],"compute":{"aggregation":"count"},"group_by":[]}],"response_format":"timeseries","style":{"palette":"dog_classic","line_type":"solid","line_width":"normal"},"display_type":"line"}]}}],"layout_type":"ordered","reflow_type":"auto"}
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.requests[0].queries[0].data_source" is equal to "product_analytics"
And the response "widgets[0].definition.requests[0].queries[0].search.query" is equal to "test_level:test"

@generated @skip @team:DataDog/reporting-and-sharing
Scenario: Create a shared dashboard returns "Bad Request" response
Given new "CreatePublicDashboard" request
Expand Down
Loading