v1_dashboards_CreateDashboard_3066042014/
v1_dashboards_CreateDashboard_3066042014.rs1use datadog_api_client::datadog;
3use datadog_api_client::datadogV1::api_dashboards::DashboardsAPI;
4use datadog_api_client::datadogV1::model::Dashboard;
5use datadog_api_client::datadogV1::model::DashboardLayoutType;
6use datadog_api_client::datadogV1::model::DashboardReflowType;
7use datadog_api_client::datadogV1::model::FormulaAndFunctionEventAggregation;
8use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinition;
9use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinitionCompute;
10use datadog_api_client::datadogV1::model::FormulaAndFunctionEventQueryDefinitionSearch;
11use datadog_api_client::datadogV1::model::FormulaAndFunctionEventsDataSource;
12use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition;
13use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat;
14use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinition;
15use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinitionType;
16use datadog_api_client::datadogV1::model::TimeseriesWidgetLegendColumn;
17use datadog_api_client::datadogV1::model::TimeseriesWidgetLegendLayout;
18use datadog_api_client::datadogV1::model::TimeseriesWidgetRequest;
19use datadog_api_client::datadogV1::model::Widget;
20use datadog_api_client::datadogV1::model::WidgetDefinition;
21use datadog_api_client::datadogV1::model::WidgetDisplayType;
22use datadog_api_client::datadogV1::model::WidgetFormula;
23use datadog_api_client::datadogV1::model::WidgetLineType;
24use datadog_api_client::datadogV1::model::WidgetLineWidth;
25use datadog_api_client::datadogV1::model::WidgetLiveSpanUnit;
26use datadog_api_client::datadogV1::model::WidgetNewLiveSpan;
27use datadog_api_client::datadogV1::model::WidgetNewLiveSpanType;
28use datadog_api_client::datadogV1::model::WidgetRequestStyle;
29use datadog_api_client::datadogV1::model::WidgetTime;
30
31#[tokio::main]
32async fn main() {
33 let body =
34 Dashboard::new(
35 DashboardLayoutType::ORDERED,
36 "Example-Dashboard with new live span time".to_string(),
37 vec![
38 Widget::new(
39 WidgetDefinition::TimeseriesWidgetDefinition(
40 Box::new(
41 TimeseriesWidgetDefinition::new(
42 vec![
43 TimeseriesWidgetRequest::new()
44 .display_type(WidgetDisplayType::LINE)
45 .formulas(vec![WidgetFormula::new("query1".to_string())])
46 .queries(
47 vec![
48 FormulaAndFunctionQueryDefinition
49 ::FormulaAndFunctionEventQueryDefinition(
50 Box::new(
51 FormulaAndFunctionEventQueryDefinition::new(
52 FormulaAndFunctionEventQueryDefinitionCompute::new(
53 FormulaAndFunctionEventAggregation::COUNT,
54 ).metric("@ci.queue_time".to_string()),
55 FormulaAndFunctionEventsDataSource::CI_PIPELINES,
56 "query1".to_string(),
57 )
58 .group_by(vec![])
59 .indexes(vec!["*".to_string()])
60 .search(
61 FormulaAndFunctionEventQueryDefinitionSearch::new(
62 "ci_level:job".to_string(),
63 ),
64 ),
65 ),
66 )
67 ],
68 )
69 .response_format(FormulaAndFunctionResponseFormat::TIMESERIES)
70 .style(
71 WidgetRequestStyle::new()
72 .line_type(WidgetLineType::SOLID)
73 .line_width(WidgetLineWidth::NORMAL)
74 .palette("dog_classic".to_string()),
75 )
76 ],
77 TimeseriesWidgetDefinitionType::TIMESERIES,
78 )
79 .legend_columns(
80 vec![
81 TimeseriesWidgetLegendColumn::AVG,
82 TimeseriesWidgetLegendColumn::MIN,
83 TimeseriesWidgetLegendColumn::MAX,
84 TimeseriesWidgetLegendColumn::VALUE,
85 TimeseriesWidgetLegendColumn::SUM
86 ],
87 )
88 .legend_layout(TimeseriesWidgetLegendLayout::AUTO)
89 .show_legend(true)
90 .time(
91 WidgetTime::WidgetNewLiveSpan(
92 Box::new(
93 WidgetNewLiveSpan::new(
94 WidgetNewLiveSpanType::LIVE,
95 WidgetLiveSpanUnit::MINUTE,
96 8,
97 ).hide_incomplete_cost_data(true),
98 ),
99 ),
100 )
101 .title("".to_string()),
102 ),
103 ),
104 )
105 ],
106 ).reflow_type(DashboardReflowType::AUTO);
107 let configuration = datadog::Configuration::new();
108 let api = DashboardsAPI::with_config(configuration);
109 let resp = api.create_dashboard(body).await;
110 if let Ok(value) = resp {
111 println!("{:#?}", value);
112 } else {
113 println!("{:#?}", resp.unwrap_err());
114 }
115}