Skip to content

Add number_format to each formula in widget #518

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-19 19:09:51.711358",
"spec_repo_commit": "f0e5fdcf"
"regenerated": "2025-02-20 13:35:02.579691",
"spec_repo_commit": "c64543d0"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2025-02-19 19:09:51.727956",
"spec_repo_commit": "f0e5fdcf"
"regenerated": "2025-02-20 13:35:02.595038",
"spec_repo_commit": "c64543d0"
}
}
}
66 changes: 66 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9727,6 +9727,62 @@ components:
items:
$ref: '#/components/schemas/NotifyEndType'
type: array
NumberFormatUnit:
description: Number format unit.
oneOf:
- $ref: '#/components/schemas/NumberFormatUnitCanonical'
- $ref: '#/components/schemas/NumberFormatUnitCustom'
NumberFormatUnitCanonical:
description: Canonical unit.
properties:
per_unit_name:
description: The name of the unit per item.
example: bytes
type: string
type:
$ref: '#/components/schemas/NumberFormatUnitScaleType'
unit_name:
description: The name of the unit.
example: bytes
type: string
type: object
NumberFormatUnitCustom:
description: Custom unit.
properties:
label:
description: The label for the custom unit.
maxLength: 12
minLength: 1
type: string
type:
$ref: '#/components/schemas/NumberFormatUnitCustomType'
type: object
NumberFormatUnitCustomType:
description: The type of custom unit.
enum:
- custom_unit_label
type: string
x-enum-varnames:
- CUSTOM_UNIT_LABEL
NumberFormatUnitScale:
description: The definition of `NumberFormatUnitScale` object.
nullable: true
properties:
type:
$ref: '#/components/schemas/NumberFormatUnitScaleType'
unit_name:
description: The name of the unit.
example: bytes
type: string
type: object
NumberFormatUnitScaleType:
description: The type of unit scale.
enum:
- canonical_unit
example: canonical_unit
type: string
x-enum-varnames:
- CANONICAL_UNIT
OnMissingDataOption:
description: 'Controls how groups or monitors are treated if an evaluation does
not return any data points.
Expand Down Expand Up @@ -23044,6 +23100,8 @@ components:
type: string
limit:
$ref: '#/components/schemas/WidgetFormulaLimit'
number_format:
$ref: '#/components/schemas/WidgetNumberFormat'
style:
$ref: '#/components/schemas/WidgetFormulaStyle'
required:
Expand Down Expand Up @@ -23463,6 +23521,14 @@ components:
x-enum-varnames:
- HOST
- CONTAINER
WidgetNumberFormat:
description: Number format options for the widget.
properties:
unit:
$ref: '#/components/schemas/NumberFormatUnit'
unit_scale:
$ref: '#/components/schemas/NumberFormatUnitScale'
type: object
WidgetOrderBy:
description: What to order by.
enum:
Expand Down
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ writeable,https://github.com/unicode-org/icu4x,Unicode-3.0,The ICU4X Project Dev
yoke,https://github.com/unicode-org/icu4x,Unicode-3.0,Manish Goregaokar <manishsmail@gmail.com>
yoke-derive,https://github.com/unicode-org/icu4x,Unicode-3.0,Manish Goregaokar <manishsmail@gmail.com>
zerocopy,https://github.com/google/zerocopy,BSD-2-Clause OR Apache-2.0 OR MIT,Joshua Liebow-Feeser <joshlf@google.com>
zerocopy,https://github.com/google/zerocopy,BSD-2-Clause OR Apache-2.0 OR MIT,"Joshua Liebow-Feeser <joshlf@google.com>, Jack Wrenn <jswrenn@amazon.com>"
zerofrom,https://github.com/unicode-org/icu4x,Unicode-3.0,Manish Goregaokar <manishsmail@gmail.com>
zerofrom-derive,https://github.com/unicode-org/icu4x,Unicode-3.0,Manish Goregaokar <manishsmail@gmail.com>
zerovec,https://github.com/unicode-org/icu4x,Unicode-3.0,The ICU4X Project Developers
Expand Down
111 changes: 111 additions & 0 deletions examples/v1_dashboards_CreateDashboard_3520534424.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Create a new dashboard with timeseries widget with custom_unit
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::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::NumberFormatUnit;
use datadog_api_client::datadogV1::model::NumberFormatUnitCanonical;
use datadog_api_client::datadogV1::model::NumberFormatUnitScale;
use datadog_api_client::datadogV1::model::NumberFormatUnitScaleType;
use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinition;
use datadog_api_client::datadogV1::model::TimeseriesWidgetDefinitionType;
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::WidgetLayout;
use datadog_api_client::datadogV1::model::WidgetLegacyLiveSpan;
use datadog_api_client::datadogV1::model::WidgetNumberFormat;
use datadog_api_client::datadogV1::model::WidgetTextAlign;
use datadog_api_client::datadogV1::model::WidgetTime;

#[tokio::main]
async fn main() {
let body =
Dashboard::new(
DashboardLayoutType::ORDERED,
"Example-Dashboard".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(),
).number_format(
WidgetNumberFormat::new()
.unit(
NumberFormatUnit::NumberFormatUnitCanonical(
Box::new(
NumberFormatUnitCanonical::new()
.type_(
NumberFormatUnitScaleType::CANONICAL_UNIT,
)
.unit_name("fraction".to_string()),
),
),
)
.unit_scale(
Some(
NumberFormatUnitScale::new()
.type_(NumberFormatUnitScaleType::CANONICAL_UNIT)
.unit_name("apdex".to_string()),
),
),
)
],
)
.queries(
vec![
FormulaAndFunctionQueryDefinition
::FormulaAndFunctionMetricQueryDefinition(
Box::new(
FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query1".to_string(),
"avg:system.cpu.user{*}".to_string(),
),
),
)
],
)
.response_format(FormulaAndFunctionResponseFormat::TIMESERIES)
],
TimeseriesWidgetDefinitionType::TIMESERIES,
)
.legend_layout(TimeseriesWidgetLegendLayout::AUTO)
.show_legend(true)
.time(WidgetTime::WidgetLegacyLiveSpan(Box::new(WidgetLegacyLiveSpan::new())))
.title("".to_string())
.title_align(WidgetTextAlign::LEFT)
.title_size("16".to_string()),
),
),
).layout(WidgetLayout::new(5, 12, 0, 0))
],
)
.description(Some("".to_string()))
.notify_list(Some(vec![]))
.reflow_type(DashboardReflowType::FIXED)
.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());
}
}
14 changes: 14 additions & 0 deletions src/datadogV1/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ pub mod model_widget_formula_limit;
pub use self::model_widget_formula_limit::WidgetFormulaLimit;
pub mod model_query_sort_order;
pub use self::model_query_sort_order::QuerySortOrder;
pub mod model_widget_number_format;
pub use self::model_widget_number_format::WidgetNumberFormat;
pub mod model_number_format_unit_canonical;
pub use self::model_number_format_unit_canonical::NumberFormatUnitCanonical;
pub mod model_number_format_unit_scale_type;
pub use self::model_number_format_unit_scale_type::NumberFormatUnitScaleType;
pub mod model_number_format_unit_custom;
pub use self::model_number_format_unit_custom::NumberFormatUnitCustom;
pub mod model_number_format_unit_custom_type;
pub use self::model_number_format_unit_custom_type::NumberFormatUnitCustomType;
pub mod model_number_format_unit;
pub use self::model_number_format_unit::NumberFormatUnit;
pub mod model_number_format_unit_scale;
pub use self::model_number_format_unit_scale::NumberFormatUnitScale;
pub mod model_widget_formula_style;
pub use self::model_widget_formula_style::WidgetFormulaStyle;
pub mod model_widget_order_by;
Expand Down
42 changes: 42 additions & 0 deletions src/datadogV1/model/model_number_format_unit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use serde::{Deserialize, Deserializer, Serialize};

/// Number format unit.
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(untagged)]
pub enum NumberFormatUnit {
NumberFormatUnitCanonical(Box<crate::datadogV1::model::NumberFormatUnitCanonical>),
NumberFormatUnitCustom(Box<crate::datadogV1::model::NumberFormatUnitCustom>),
UnparsedObject(crate::datadog::UnparsedObject),
}

impl<'de> Deserialize<'de> for NumberFormatUnit {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let value: serde_json::Value = Deserialize::deserialize(deserializer)?;
if let Ok(_v) = serde_json::from_value::<
Box<crate::datadogV1::model::NumberFormatUnitCanonical>,
>(value.clone())
{
if !_v._unparsed {
return Ok(NumberFormatUnit::NumberFormatUnitCanonical(_v));
}
}
if let Ok(_v) = serde_json::from_value::<Box<crate::datadogV1::model::NumberFormatUnitCustom>>(
value.clone(),
) {
if !_v._unparsed {
return Ok(NumberFormatUnit::NumberFormatUnitCustom(_v));
}
}

return Ok(NumberFormatUnit::UnparsedObject(
crate::datadog::UnparsedObject { value },
));
}
}
Loading
Loading