Skip to content

Add trend support for cell_display_mode #515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2025-02-20 18:33:29.867322",
"spec_repo_commit": "d3fcdb89"
"regenerated": "2025-02-21 08:00:35.115496",
"spec_repo_commit": "8f2d39c3"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2025-02-20 18:33:29.882630",
"spec_repo_commit": "d3fcdb89"
"regenerated": "2025-02-21 08:00:35.131024",
"spec_repo_commit": "8f2d39c3"
}
}
}
35 changes: 35 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17396,11 +17396,13 @@ components:
enum:
- number
- bar
- trend
example: number
type: string
x-enum-varnames:
- NUMBER
- BAR
- TREND
TableWidgetDefinition:
description: The table visualization is available on timeboards and screenboards.
It displays columns of metrics grouped by tag key.
Expand Down Expand Up @@ -23089,6 +23091,8 @@ components:
type: string
cell_display_mode:
$ref: '#/components/schemas/TableWidgetCellDisplayMode'
cell_display_mode_options:
$ref: '#/components/schemas/WidgetFormulaCellDisplayModeOptions'
conditional_formats:
description: List of conditional formats.
items:
Expand All @@ -23107,6 +23111,37 @@ components:
required:
- formula
type: object
WidgetFormulaCellDisplayModeOptions:
description: Cell display mode options for the widget formula. (only if `cell_display_mode`
is set to `trend`).
properties:
trend_type:
$ref: '#/components/schemas/WidgetFormulaCellDisplayModeOptionsTrendType'
y_scale:
$ref: '#/components/schemas/WidgetFormulaCellDisplayModeOptionsYScale'
type: object
WidgetFormulaCellDisplayModeOptionsTrendType:
description: Trend type for the cell display mode options.
enum:
- area
- line
- bars
example: area
type: string
x-enum-varnames:
- AREA
- LINE
- BARS
WidgetFormulaCellDisplayModeOptionsYScale:
description: Y scale for the cell display mode options.
enum:
- shared
- independent
example: shared
type: string
x-enum-varnames:
- SHARED
- INDEPENDENT
WidgetFormulaLimit:
description: Options for limiting results returned.
properties:
Expand Down
117 changes: 117 additions & 0 deletions examples/v1_dashboards_CreateDashboard_1490099434.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Create a new dashboard with query_table widget and cell_display_mode is trend
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::FormulaAndFunctionMetricAggregation;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition;
use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat;
use datadog_api_client::datadogV1::model::FormulaType;
use datadog_api_client::datadogV1::model::TableWidgetCellDisplayMode;
use datadog_api_client::datadogV1::model::TableWidgetDefinition;
use datadog_api_client::datadogV1::model::TableWidgetDefinitionType;
use datadog_api_client::datadogV1::model::TableWidgetHasSearchBar;
use datadog_api_client::datadogV1::model::TableWidgetRequest;
use datadog_api_client::datadogV1::model::Widget;
use datadog_api_client::datadogV1::model::WidgetDefinition;
use datadog_api_client::datadogV1::model::WidgetFormula;
use datadog_api_client::datadogV1::model::WidgetFormulaCellDisplayModeOptions;
use datadog_api_client::datadogV1::model::WidgetFormulaCellDisplayModeOptionsTrendType;
use datadog_api_client::datadogV1::model::WidgetFormulaCellDisplayModeOptionsYScale;
use datadog_api_client::datadogV1::model::WidgetFormulaSort;
use datadog_api_client::datadogV1::model::WidgetLayout;
use datadog_api_client::datadogV1::model::WidgetLegacyLiveSpan;
use datadog_api_client::datadogV1::model::WidgetSort;
use datadog_api_client::datadogV1::model::WidgetSortBy;
use datadog_api_client::datadogV1::model::WidgetSortOrderBy;
use datadog_api_client::datadogV1::model::WidgetTextAlign;
use datadog_api_client::datadogV1::model::WidgetTime;

#[tokio::main]
async fn main() {
let body =
Dashboard::new(
DashboardLayoutType::FREE,
"Example-Dashboard".to_string(),
vec![
Widget::new(
WidgetDefinition::TableWidgetDefinition(
Box::new(
TableWidgetDefinition::new(
vec![
TableWidgetRequest::new()
.formulas(
vec![
WidgetFormula::new("query1".to_string())
.cell_display_mode(TableWidgetCellDisplayMode::TREND)
.cell_display_mode_options(
WidgetFormulaCellDisplayModeOptions::new()
.trend_type(
WidgetFormulaCellDisplayModeOptionsTrendType::LINE,
)
.y_scale(
WidgetFormulaCellDisplayModeOptionsYScale::SHARED,
),
)
.conditional_formats(vec![])
],
)
.queries(
vec![
FormulaAndFunctionQueryDefinition
::FormulaAndFunctionMetricQueryDefinition(
Box::new(
FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query1".to_string(),
"avg:system.cpu.user{*} by {host}".to_string(),
).aggregator(FormulaAndFunctionMetricAggregation::AVG),
),
)
],
)
.response_format(FormulaAndFunctionResponseFormat::SCALAR)
.sort(
WidgetSortBy::new()
.count(500)
.order_by(
vec![
WidgetSortOrderBy::WidgetFormulaSort(
Box::new(
WidgetFormulaSort::new(
0,
WidgetSort::DESCENDING,
FormulaType::FORMULA,
),
),
)
],
),
)
],
TableWidgetDefinitionType::QUERY_TABLE,
)
.has_search_bar(TableWidgetHasSearchBar::AUTO)
.time(WidgetTime::WidgetLegacyLiveSpan(Box::new(WidgetLegacyLiveSpan::new())))
.title("".to_string())
.title_align(WidgetTextAlign::LEFT)
.title_size("16".to_string()),
),
),
).layout(WidgetLayout::new(32, 54, 0, 0))
],
)
.description(Some("".to_string()))
.notify_list(Some(vec![]))
.template_variables(Some(vec![]));
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());
}
}
6 changes: 6 additions & 0 deletions src/datadogV1/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ pub mod model_widget_formula;
pub use self::model_widget_formula::WidgetFormula;
pub mod model_table_widget_cell_display_mode;
pub use self::model_table_widget_cell_display_mode::TableWidgetCellDisplayMode;
pub mod model_widget_formula_cell_display_mode_options;
pub use self::model_widget_formula_cell_display_mode_options::WidgetFormulaCellDisplayModeOptions;
pub mod model_widget_formula_cell_display_mode_options_trend_type;
pub use self::model_widget_formula_cell_display_mode_options_trend_type::WidgetFormulaCellDisplayModeOptionsTrendType;
pub mod model_widget_formula_cell_display_mode_options_y_scale;
pub use self::model_widget_formula_cell_display_mode_options_y_scale::WidgetFormulaCellDisplayModeOptionsYScale;
pub mod model_widget_conditional_format;
pub use self::model_widget_conditional_format::WidgetConditionalFormat;
pub mod model_widget_comparator;
Expand Down
3 changes: 3 additions & 0 deletions src/datadogV1/model/model_table_widget_cell_display_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
pub enum TableWidgetCellDisplayMode {
NUMBER,
BAR,
TREND,
UnparsedObject(crate::datadog::UnparsedObject),
}

Expand All @@ -17,6 +18,7 @@ impl ToString for TableWidgetCellDisplayMode {
match self {
Self::NUMBER => String::from("number"),
Self::BAR => String::from("bar"),
Self::TREND => String::from("trend"),
Self::UnparsedObject(v) => v.value.to_string(),
}
}
Expand All @@ -43,6 +45,7 @@ impl<'de> Deserialize<'de> for TableWidgetCellDisplayMode {
Ok(match s.as_str() {
"number" => Self::NUMBER,
"bar" => Self::BAR,
"trend" => Self::TREND,
_ => Self::UnparsedObject(crate::datadog::UnparsedObject {
value: serde_json::Value::String(s.into()),
}),
Expand Down
24 changes: 24 additions & 0 deletions src/datadogV1/model/model_widget_formula.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub struct WidgetFormula {
/// Define a display mode for the table cell.
#[serde(rename = "cell_display_mode")]
pub cell_display_mode: Option<crate::datadogV1::model::TableWidgetCellDisplayMode>,
/// Cell display mode options for the widget formula. (only if `cell_display_mode` is set to `trend`).
#[serde(rename = "cell_display_mode_options")]
pub cell_display_mode_options:
Option<crate::datadogV1::model::WidgetFormulaCellDisplayModeOptions>,
/// List of conditional formats.
#[serde(rename = "conditional_formats")]
pub conditional_formats: Option<Vec<crate::datadogV1::model::WidgetConditionalFormat>>,
Expand Down Expand Up @@ -44,6 +48,7 @@ impl WidgetFormula {
WidgetFormula {
alias: None,
cell_display_mode: None,
cell_display_mode_options: None,
conditional_formats: None,
formula,
limit: None,
Expand All @@ -67,6 +72,14 @@ impl WidgetFormula {
self
}

pub fn cell_display_mode_options(
mut self,
value: crate::datadogV1::model::WidgetFormulaCellDisplayModeOptions,
) -> Self {
self.cell_display_mode_options = Some(value);
self
}

pub fn conditional_formats(
mut self,
value: Vec<crate::datadogV1::model::WidgetConditionalFormat>,
Expand Down Expand Up @@ -120,6 +133,9 @@ impl<'de> Deserialize<'de> for WidgetFormula {
let mut cell_display_mode: Option<
crate::datadogV1::model::TableWidgetCellDisplayMode,
> = None;
let mut cell_display_mode_options: Option<
crate::datadogV1::model::WidgetFormulaCellDisplayModeOptions,
> = None;
let mut conditional_formats: Option<
Vec<crate::datadogV1::model::WidgetConditionalFormat>,
> = None;
Expand Down Expand Up @@ -156,6 +172,13 @@ impl<'de> Deserialize<'de> for WidgetFormula {
}
}
}
"cell_display_mode_options" => {
if v.is_null() {
continue;
}
cell_display_mode_options =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"conditional_formats" => {
if v.is_null() {
continue;
Expand Down Expand Up @@ -197,6 +220,7 @@ impl<'de> Deserialize<'de> for WidgetFormula {
let content = WidgetFormula {
alias,
cell_display_mode,
cell_display_mode_options,
conditional_formats,
formula,
limit,
Expand Down
Loading
Loading