Skip to content

Commit

Permalink
Add style object to dashboard widget formulas (#1266)
Browse files Browse the repository at this point in the history
Co-authored-by: ci.datadog-api-spec <[email protected]>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored Dec 13, 2022
1 parent 00eb938 commit 7a7be3c
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 4 deletions.
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.4",
"regenerated": "2022-12-09 17:41:11.134424",
"spec_repo_commit": "9e20f8a4"
"regenerated": "2022-12-13 17:18:24.643012",
"spec_repo_commit": "8cd868ba"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2022-12-09 17:41:11.145845",
"spec_repo_commit": "9e20f8a4"
"regenerated": "2022-12-13 17:18:24.654013",
"spec_repo_commit": "8cd868ba"
}
}
}
16 changes: 16 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18043,6 +18043,8 @@ components:
type: string
limit:
$ref: '#/components/schemas/WidgetFormulaLimit'
style:
$ref: '#/components/schemas/WidgetFormulaStyle'
required:
- formula
type: object
Expand All @@ -18056,6 +18058,20 @@ components:
order:
$ref: '#/components/schemas/QuerySortOrder'
type: object
WidgetFormulaStyle:
description: Styling options for widget formulas.
properties:
palette:
description: The color palette used to display the formula. A guide to the
available color palettes can be found at https://docs.datadoghq.com/dashboards/guide/widget_colors
example: classic
type: string
palette_index:
description: Index specifying which color to use within the palette.
example: 1
format: int64
type: integer
type: object
WidgetGrouping:
description: The kind of grouping to use.
enum:
Expand Down
7 changes: 7 additions & 0 deletions docs/datadog_api_client.v1.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5167,6 +5167,13 @@ widget\_formula\_limit
:members:
:show-inheritance:

widget\_formula\_style
----------------------

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

widget\_grouping
----------------

Expand Down
85 changes: 85 additions & 0 deletions examples/v1/dashboards/CreateDashboard_41622531.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""
Create a new dashboard with timeseries widget and formula style attributes
"""

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.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_column import TimeseriesWidgetLegendColumn
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_formula_style import WidgetFormulaStyle
from datadog_api_client.v1.model.widget_line_type import WidgetLineType
from datadog_api_client.v1.model.widget_line_width import WidgetLineWidth
from datadog_api_client.v1.model.widget_request_style import WidgetRequestStyle
from datadog_api_client.v1.model.widget_time import WidgetTime

body = Dashboard(
title="Example-Create_a_new_dashboard_with_timeseries_widget_and_formula_style_attributes with formula style",
widgets=[
Widget(
definition=TimeseriesWidgetDefinition(
title="styled timeseries",
show_legend=True,
legend_layout=TimeseriesWidgetLegendLayout.AUTO,
legend_columns=[
TimeseriesWidgetLegendColumn.AVG,
TimeseriesWidgetLegendColumn.MIN,
TimeseriesWidgetLegendColumn.MAX,
TimeseriesWidgetLegendColumn.VALUE,
TimeseriesWidgetLegendColumn.SUM,
],
time=WidgetTime(),
type=TimeseriesWidgetDefinitionType.TIMESERIES,
requests=[
TimeseriesWidgetRequest(
formulas=[
WidgetFormula(
formula="query1",
style=WidgetFormulaStyle(
palette_index=4,
palette="classic",
),
),
],
queries=[
FormulaAndFunctionMetricQueryDefinition(
query="avg:system.cpu.user{*}",
data_source=FormulaAndFunctionMetricDataSource.METRICS,
name="query1",
),
],
response_format=FormulaAndFunctionResponseFormat.TIMESERIES,
style=WidgetRequestStyle(
palette="dog_classic",
line_type=WidgetLineType.SOLID,
line_width=WidgetLineWidth.NORMAL,
),
display_type=WidgetDisplayType.LINE,
),
],
),
),
],
layout_type=DashboardLayoutType.ORDERED,
reflow_type=DashboardReflowType.AUTO,
)

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

print(response)
10 changes: 10 additions & 0 deletions src/datadog_api_client/v1/model/widget_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from datadog_api_client.v1.model.table_widget_cell_display_mode import TableWidgetCellDisplayMode
from datadog_api_client.v1.model.widget_conditional_format import WidgetConditionalFormat
from datadog_api_client.v1.model.widget_formula_limit import WidgetFormulaLimit
from datadog_api_client.v1.model.widget_formula_style import WidgetFormulaStyle


class WidgetFormula(ModelNormal):
Expand All @@ -25,13 +26,15 @@ def openapi_types(_):
from datadog_api_client.v1.model.table_widget_cell_display_mode import TableWidgetCellDisplayMode
from datadog_api_client.v1.model.widget_conditional_format import WidgetConditionalFormat
from datadog_api_client.v1.model.widget_formula_limit import WidgetFormulaLimit
from datadog_api_client.v1.model.widget_formula_style import WidgetFormulaStyle

return {
"alias": (str,),
"cell_display_mode": (TableWidgetCellDisplayMode,),
"conditional_formats": ([WidgetConditionalFormat],),
"formula": (str,),
"limit": (WidgetFormulaLimit,),
"style": (WidgetFormulaStyle,),
}

attribute_map = {
Expand All @@ -40,6 +43,7 @@ def openapi_types(_):
"conditional_formats": "conditional_formats",
"formula": "formula",
"limit": "limit",
"style": "style",
}

def __init__(
Expand All @@ -49,6 +53,7 @@ def __init__(
cell_display_mode: Union[TableWidgetCellDisplayMode, UnsetType] = unset,
conditional_formats: Union[List[WidgetConditionalFormat], UnsetType] = unset,
limit: Union[WidgetFormulaLimit, UnsetType] = unset,
style: Union[WidgetFormulaStyle, UnsetType] = unset,
**kwargs,
):
"""
Expand All @@ -68,6 +73,9 @@ def __init__(
:param limit: Options for limiting results returned.
:type limit: WidgetFormulaLimit, optional
:param style: Styling options for widget formulas.
:type style: WidgetFormulaStyle, optional
"""
if alias is not unset:
kwargs["alias"] = alias
Expand All @@ -77,6 +85,8 @@ def __init__(
kwargs["conditional_formats"] = conditional_formats
if limit is not unset:
kwargs["limit"] = limit
if style is not unset:
kwargs["style"] = style
super().__init__(kwargs)

self_.formula = formula
43 changes: 43 additions & 0 deletions src/datadog_api_client/v1/model/widget_formula_style.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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

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


class WidgetFormulaStyle(ModelNormal):
@cached_property
def openapi_types(_):
return {
"palette": (str,),
"palette_index": (int,),
}

attribute_map = {
"palette": "palette",
"palette_index": "palette_index",
}

def __init__(self_, palette: Union[str, UnsetType] = unset, palette_index: Union[int, UnsetType] = unset, **kwargs):
"""
Styling options for widget formulas.
:param palette: The color palette used to display the formula. A guide to the available color palettes can be found at https://docs.datadoghq.com/dashboards/guide/widget_colors
:type palette: str, optional
:param palette_index: Index specifying which color to use within the palette.
:type palette_index: int, optional
"""
if palette is not unset:
kwargs["palette"] = palette
if palette_index is not unset:
kwargs["palette_index"] = palette_index
super().__init__(kwargs)
1 change: 1 addition & 0 deletions src/datadog_api_client/v1/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@
from datadog_api_client.v1.model.widget_field_sort import WidgetFieldSort
from datadog_api_client.v1.model.widget_formula import WidgetFormula
from datadog_api_client.v1.model.widget_formula_limit import WidgetFormulaLimit
from datadog_api_client.v1.model.widget_formula_style import WidgetFormulaStyle
from datadog_api_client.v1.model.widget_grouping import WidgetGrouping
from datadog_api_client.v1.model.widget_horizontal_align import WidgetHorizontalAlign
from datadog_api_client.v1.model.widget_image_sizing import WidgetImageSizing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2022-12-13T17:13:10.406Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
interactions:
- request:
body: '{"layout_type":"ordered","reflow_type":"auto","title":"Test-Create_a_new_dashboard_with_timeseries_widget_and_formula_style_attributes-1670951590
with formula style","widgets":[{"definition":{"legend_columns":["avg","min","max","value","sum"],"legend_layout":"auto","requests":[{"display_type":"line","formulas":[{"formula":"query1","style":{"palette":"classic","palette_index":4}}],"queries":[{"data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*}"}],"response_format":"timeseries","style":{"line_type":"solid","line_width":"normal","palette":"dog_classic"}}],"show_legend":true,"time":{},"title":"styled
timeseries","type":"timeseries"}}]}'
headers:
accept:
- application/json
content-type:
- application/json
method: POST
uri: https://api.datadoghq.com/api/v1/dashboard
response:
body:
string: '{"notify_list":null,"description":null,"restricted_roles":[],"author_name":null,"template_variables":null,"is_read_only":false,"id":"k2c-ici-a4c","title":"Test-Create_a_new_dashboard_with_timeseries_widget_and_formula_style_attributes-1670951590
with formula style","url":"/dashboard/k2c-ici-a4c/test-createanewdashboardwithtimeserieswidgetandformulastyleattributes-1670951590","created_at":"2022-12-13T17:13:10.630153+00:00","modified_at":"2022-12-13T17:13:10.630153+00:00","reflow_type":"auto","author_handle":"[email protected]","widgets":[{"definition":{"legend_columns":["avg","min","max","value","sum"],"title":"styled
timeseries","legend_layout":"auto","show_legend":true,"time":{},"requests":[{"formulas":[{"formula":"query1","style":{"palette_index":4,"palette":"classic"}}],"style":{"line_width":"normal","palette":"dog_classic","line_type":"solid"},"display_type":"line","response_format":"timeseries","queries":[{"query":"avg:system.cpu.user{*}","data_source":"metrics","name":"query1"}]}],"type":"timeseries"},"id":5980026334932933}],"layout_type":"ordered"}
'
headers:
content-type:
- application/json
status:
code: 200
message: OK
- request:
body: null
headers:
accept:
- application/json
method: DELETE
uri: https://api.datadoghq.com/api/v1/dashboard/k2c-ici-a4c
response:
body:
string: '{"deleted_dashboard_id":"k2c-ici-a4c"}
'
headers:
content-type:
- application/json
status:
code: 200
message: OK
version: 1
10 changes: 10 additions & 0 deletions tests/v1/features/dashboards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,16 @@ Feature: Dashboards
When the request is sent
Then the response status is 200 OK

@team:DataDog/dashboards
Scenario: Create a new dashboard with timeseries widget and formula style attributes
Given new "CreateDashboard" request
And body with value {"title": "{{ unique }} with formula style","widgets": [{"definition": {"title": "styled timeseries","show_legend": true,"legend_layout": "auto","legend_columns": ["avg","min","max","value","sum"],"time": {},"type": "timeseries","requests": [{"formulas": [{"formula": "query1","style": {"palette_index": 4,"palette": "classic"}}],"queries": [{"query": "avg:system.cpu.user{*}","data_source": "metrics","name": "query1"}],"response_format": "timeseries","style": {"palette": "dog_classic","line_type": "solid","line_width": "normal"},"display_type": "line"}]}}],"layout_type": "ordered","reflow_type": "auto"}
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.requests[0].formulas[0].formula" is equal to "query1"
And the response "widgets[0].definition.requests[0].formulas[0].style.palette" is equal to "classic"
And the response "widgets[0].definition.requests[0].formulas[0].style.palette_index" is equal to 4

@team:DataDog/dashboards
Scenario: Create a new dashboard with timeseries widget containing style attributes
Given new "CreateDashboard" request
Expand Down

0 comments on commit 7a7be3c

Please sign in to comment.