v1_dashboards_CreateDashboard_4262729673/
v1_dashboards_CreateDashboard_4262729673.rs

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