Skip to content
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

Add number_format to each formula in widget #2413

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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-14 15:03:51.274934",
"spec_repo_commit": "a739b49f"
"regenerated": "2025-02-17 17:00:55.820121",
"spec_repo_commit": "0e00b9fc"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2025-02-14 15:03:51.291086",
"spec_repo_commit": "a739b49f"
"regenerated": "2025-02-17 17:00:55.834673",
"spec_repo_commit": "0e00b9fc"
}
}
}
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
49 changes: 49 additions & 0 deletions docs/datadog_api_client.v1.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,48 @@ datadog\_api\_client.v1.model.notify\_end\_type module
:members:
:show-inheritance:

datadog\_api\_client.v1.model.number\_format\_unit module
---------------------------------------------------------

.. automodule:: datadog_api_client.v1.model.number_format_unit
:members:
:show-inheritance:

datadog\_api\_client.v1.model.number\_format\_unit\_canonical module
--------------------------------------------------------------------

.. automodule:: datadog_api_client.v1.model.number_format_unit_canonical
:members:
:show-inheritance:

datadog\_api\_client.v1.model.number\_format\_unit\_custom module
-----------------------------------------------------------------

.. automodule:: datadog_api_client.v1.model.number_format_unit_custom
:members:
:show-inheritance:

datadog\_api\_client.v1.model.number\_format\_unit\_custom\_type module
-----------------------------------------------------------------------

.. automodule:: datadog_api_client.v1.model.number_format_unit_custom_type
:members:
:show-inheritance:

datadog\_api\_client.v1.model.number\_format\_unit\_scale module
----------------------------------------------------------------

.. automodule:: datadog_api_client.v1.model.number_format_unit_scale
:members:
:show-inheritance:

datadog\_api\_client.v1.model.number\_format\_unit\_scale\_type module
----------------------------------------------------------------------

.. automodule:: datadog_api_client.v1.model.number_format_unit_scale_type
:members:
:show-inheritance:

datadog\_api\_client.v1.model.on\_missing\_data\_option module
--------------------------------------------------------------

Expand Down Expand Up @@ -6304,6 +6346,13 @@ datadog\_api\_client.v1.model.widget\_node\_type module
:members:
:show-inheritance:

datadog\_api\_client.v1.model.widget\_number\_format module
-----------------------------------------------------------

.. automodule:: datadog_api_client.v1.model.widget_number_format
:members:
:show-inheritance:

datadog\_api\_client.v1.model.widget\_order\_by module
------------------------------------------------------

Expand Down
91 changes: 91 additions & 0 deletions examples/v1/dashboards/CreateDashboard_3520534424.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
Create a new dashboard with timeseries widget with custom_unit
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
from datadog_api_client.v1.model.dashboard import Dashboard
from datadog_api_client.v1.model.dashboard_layout_type import DashboardLayoutType
from datadog_api_client.v1.model.dashboard_reflow_type import DashboardReflowType
from datadog_api_client.v1.model.formula_and_function_metric_data_source import FormulaAndFunctionMetricDataSource
from datadog_api_client.v1.model.formula_and_function_metric_query_definition import (
FormulaAndFunctionMetricQueryDefinition,
)
from datadog_api_client.v1.model.formula_and_function_response_format import FormulaAndFunctionResponseFormat
from datadog_api_client.v1.model.number_format_unit_canonical import NumberFormatUnitCanonical
from datadog_api_client.v1.model.number_format_unit_scale import NumberFormatUnitScale
from datadog_api_client.v1.model.number_format_unit_scale_type import NumberFormatUnitScaleType
from datadog_api_client.v1.model.timeseries_widget_definition import TimeseriesWidgetDefinition
from datadog_api_client.v1.model.timeseries_widget_definition_type import TimeseriesWidgetDefinitionType
from datadog_api_client.v1.model.timeseries_widget_legend_layout import TimeseriesWidgetLegendLayout
from datadog_api_client.v1.model.timeseries_widget_request import TimeseriesWidgetRequest
from datadog_api_client.v1.model.widget import Widget
from datadog_api_client.v1.model.widget_display_type import WidgetDisplayType
from datadog_api_client.v1.model.widget_formula import WidgetFormula
from datadog_api_client.v1.model.widget_layout import WidgetLayout
from datadog_api_client.v1.model.widget_legacy_live_span import WidgetLegacyLiveSpan
from datadog_api_client.v1.model.widget_number_format import WidgetNumberFormat
from datadog_api_client.v1.model.widget_text_align import WidgetTextAlign

body = Dashboard(
title="Example-Dashboard",
description="",
widgets=[
Widget(
definition=TimeseriesWidgetDefinition(
title="",
title_size="16",
title_align=WidgetTextAlign.LEFT,
show_legend=True,
legend_layout=TimeseriesWidgetLegendLayout.AUTO,
time=WidgetLegacyLiveSpan(),
type=TimeseriesWidgetDefinitionType.TIMESERIES,
requests=[
TimeseriesWidgetRequest(
formulas=[
WidgetFormula(
formula="query1",
number_format=WidgetNumberFormat(
unit_scale=NumberFormatUnitScale(
type=NumberFormatUnitScaleType.CANONICAL_UNIT,
unit_name="apdex",
),
unit=NumberFormatUnitCanonical(
type=NumberFormatUnitScaleType.CANONICAL_UNIT,
unit_name="fraction",
),
),
),
],
queries=[
FormulaAndFunctionMetricQueryDefinition(
data_source=FormulaAndFunctionMetricDataSource.METRICS,
name="query1",
query="avg:system.cpu.user{*}",
),
],
response_format=FormulaAndFunctionResponseFormat.TIMESERIES,
display_type=WidgetDisplayType.LINE,
),
],
),
layout=WidgetLayout(
x=0,
y=0,
width=12,
height=5,
),
),
],
template_variables=[],
layout_type=DashboardLayoutType.ORDERED,
notify_list=[],
reflow_type=DashboardReflowType.FIXED,
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = DashboardsApi(api_client)
response = api_instance.create_dashboard(body=body)

print(response)
49 changes: 49 additions & 0 deletions src/datadog_api_client/v1/model/number_format_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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.
from __future__ import annotations


from datadog_api_client.model_utils import (
ModelComposed,
cached_property,
)


class NumberFormatUnit(ModelComposed):
def __init__(self, **kwargs):
"""
Number format unit.

:param per_unit_name: The name of the unit per item.
:type per_unit_name: str, optional

:param type: The type of unit scale.
:type type: NumberFormatUnitScaleType, optional

:param unit_name: The name of the unit.
:type unit_name: str, optional

:param label: The label for the custom unit.
:type label: str, optional
"""
super().__init__(kwargs)

@cached_property
def _composed_schemas(_):
# we need this here to make our import statements work
# we must store _composed_schemas in here so the code is only run
# when we invoke this method. If we kept this at the class
# level we would get an error because the class level
# code would be run when this module is imported, and these composed
# classes don't exist yet because their module has not finished
# loading
from datadog_api_client.v1.model.number_format_unit_canonical import NumberFormatUnitCanonical
from datadog_api_client.v1.model.number_format_unit_custom import NumberFormatUnitCustom

return {
"oneOf": [
NumberFormatUnitCanonical,
NumberFormatUnitCustom,
],
}
62 changes: 62 additions & 0 deletions src/datadog_api_client/v1/model/number_format_unit_canonical.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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.
from __future__ import annotations

from typing import Union, TYPE_CHECKING

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


if TYPE_CHECKING:
from datadog_api_client.v1.model.number_format_unit_scale_type import NumberFormatUnitScaleType


class NumberFormatUnitCanonical(ModelNormal):
@cached_property
def openapi_types(_):
from datadog_api_client.v1.model.number_format_unit_scale_type import NumberFormatUnitScaleType

return {
"per_unit_name": (str,),
"type": (NumberFormatUnitScaleType,),
"unit_name": (str,),
}

attribute_map = {
"per_unit_name": "per_unit_name",
"type": "type",
"unit_name": "unit_name",
}

def __init__(
self_,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Code Quality Violation

Suggested change
self_,
self,
first parameter of a class function should be self (...read more)

In a class method (that is not a class method nor a static method), the first argument must be self by convention.

Learn More

View in Datadog  Leave us feedback  Documentation

per_unit_name: Union[str, UnsetType] = unset,
type: Union[NumberFormatUnitScaleType, UnsetType] = unset,
unit_name: Union[str, UnsetType] = unset,
**kwargs,
):
"""
Canonical unit.

:param per_unit_name: The name of the unit per item.
:type per_unit_name: str, optional

:param type: The type of unit scale.
:type type: NumberFormatUnitScaleType, optional

:param unit_name: The name of the unit.
:type unit_name: str, optional
"""
if per_unit_name is not unset:
kwargs["per_unit_name"] = per_unit_name
if type is not unset:
kwargs["type"] = type
if unit_name is not unset:
kwargs["unit_name"] = unit_name
super().__init__(kwargs)
Loading