Skip to content

Commit 7a7be3c

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add style object to dashboard widget formulas (#1266)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 00eb938 commit 7a7be3c

10 files changed

+221
-4
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.4",
7-
"regenerated": "2022-12-09 17:41:11.134424",
8-
"spec_repo_commit": "9e20f8a4"
7+
"regenerated": "2022-12-13 17:18:24.643012",
8+
"spec_repo_commit": "8cd868ba"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.4",
12-
"regenerated": "2022-12-09 17:41:11.145845",
13-
"spec_repo_commit": "9e20f8a4"
12+
"regenerated": "2022-12-13 17:18:24.654013",
13+
"spec_repo_commit": "8cd868ba"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18043,6 +18043,8 @@ components:
1804318043
type: string
1804418044
limit:
1804518045
$ref: '#/components/schemas/WidgetFormulaLimit'
18046+
style:
18047+
$ref: '#/components/schemas/WidgetFormulaStyle'
1804618048
required:
1804718049
- formula
1804818050
type: object
@@ -18056,6 +18058,20 @@ components:
1805618058
order:
1805718059
$ref: '#/components/schemas/QuerySortOrder'
1805818060
type: object
18061+
WidgetFormulaStyle:
18062+
description: Styling options for widget formulas.
18063+
properties:
18064+
palette:
18065+
description: The color palette used to display the formula. A guide to the
18066+
available color palettes can be found at https://docs.datadoghq.com/dashboards/guide/widget_colors
18067+
example: classic
18068+
type: string
18069+
palette_index:
18070+
description: Index specifying which color to use within the palette.
18071+
example: 1
18072+
format: int64
18073+
type: integer
18074+
type: object
1805918075
WidgetGrouping:
1806018076
description: The kind of grouping to use.
1806118077
enum:

docs/datadog_api_client.v1.model.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,6 +5167,13 @@ widget\_formula\_limit
51675167
:members:
51685168
:show-inheritance:
51695169

5170+
widget\_formula\_style
5171+
----------------------
5172+
5173+
.. automodule:: datadog_api_client.v1.model.widget_formula_style
5174+
:members:
5175+
:show-inheritance:
5176+
51705177
widget\_grouping
51715178
----------------
51725179

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""
2+
Create a new dashboard with timeseries widget and formula style attributes
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
7+
from datadog_api_client.v1.model.dashboard import Dashboard
8+
from datadog_api_client.v1.model.dashboard_layout_type import DashboardLayoutType
9+
from datadog_api_client.v1.model.dashboard_reflow_type import DashboardReflowType
10+
from datadog_api_client.v1.model.formula_and_function_metric_data_source import FormulaAndFunctionMetricDataSource
11+
from datadog_api_client.v1.model.formula_and_function_metric_query_definition import (
12+
FormulaAndFunctionMetricQueryDefinition,
13+
)
14+
from datadog_api_client.v1.model.formula_and_function_response_format import FormulaAndFunctionResponseFormat
15+
from datadog_api_client.v1.model.timeseries_widget_definition import TimeseriesWidgetDefinition
16+
from datadog_api_client.v1.model.timeseries_widget_definition_type import TimeseriesWidgetDefinitionType
17+
from datadog_api_client.v1.model.timeseries_widget_legend_column import TimeseriesWidgetLegendColumn
18+
from datadog_api_client.v1.model.timeseries_widget_legend_layout import TimeseriesWidgetLegendLayout
19+
from datadog_api_client.v1.model.timeseries_widget_request import TimeseriesWidgetRequest
20+
from datadog_api_client.v1.model.widget import Widget
21+
from datadog_api_client.v1.model.widget_display_type import WidgetDisplayType
22+
from datadog_api_client.v1.model.widget_formula import WidgetFormula
23+
from datadog_api_client.v1.model.widget_formula_style import WidgetFormulaStyle
24+
from datadog_api_client.v1.model.widget_line_type import WidgetLineType
25+
from datadog_api_client.v1.model.widget_line_width import WidgetLineWidth
26+
from datadog_api_client.v1.model.widget_request_style import WidgetRequestStyle
27+
from datadog_api_client.v1.model.widget_time import WidgetTime
28+
29+
body = Dashboard(
30+
title="Example-Create_a_new_dashboard_with_timeseries_widget_and_formula_style_attributes with formula style",
31+
widgets=[
32+
Widget(
33+
definition=TimeseriesWidgetDefinition(
34+
title="styled timeseries",
35+
show_legend=True,
36+
legend_layout=TimeseriesWidgetLegendLayout.AUTO,
37+
legend_columns=[
38+
TimeseriesWidgetLegendColumn.AVG,
39+
TimeseriesWidgetLegendColumn.MIN,
40+
TimeseriesWidgetLegendColumn.MAX,
41+
TimeseriesWidgetLegendColumn.VALUE,
42+
TimeseriesWidgetLegendColumn.SUM,
43+
],
44+
time=WidgetTime(),
45+
type=TimeseriesWidgetDefinitionType.TIMESERIES,
46+
requests=[
47+
TimeseriesWidgetRequest(
48+
formulas=[
49+
WidgetFormula(
50+
formula="query1",
51+
style=WidgetFormulaStyle(
52+
palette_index=4,
53+
palette="classic",
54+
),
55+
),
56+
],
57+
queries=[
58+
FormulaAndFunctionMetricQueryDefinition(
59+
query="avg:system.cpu.user{*}",
60+
data_source=FormulaAndFunctionMetricDataSource.METRICS,
61+
name="query1",
62+
),
63+
],
64+
response_format=FormulaAndFunctionResponseFormat.TIMESERIES,
65+
style=WidgetRequestStyle(
66+
palette="dog_classic",
67+
line_type=WidgetLineType.SOLID,
68+
line_width=WidgetLineWidth.NORMAL,
69+
),
70+
display_type=WidgetDisplayType.LINE,
71+
),
72+
],
73+
),
74+
),
75+
],
76+
layout_type=DashboardLayoutType.ORDERED,
77+
reflow_type=DashboardReflowType.AUTO,
78+
)
79+
80+
configuration = Configuration()
81+
with ApiClient(configuration) as api_client:
82+
api_instance = DashboardsApi(api_client)
83+
response = api_instance.create_dashboard(body=body)
84+
85+
print(response)

src/datadog_api_client/v1/model/widget_formula.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from datadog_api_client.v1.model.table_widget_cell_display_mode import TableWidgetCellDisplayMode
1818
from datadog_api_client.v1.model.widget_conditional_format import WidgetConditionalFormat
1919
from datadog_api_client.v1.model.widget_formula_limit import WidgetFormulaLimit
20+
from datadog_api_client.v1.model.widget_formula_style import WidgetFormulaStyle
2021

2122

2223
class WidgetFormula(ModelNormal):
@@ -25,13 +26,15 @@ def openapi_types(_):
2526
from datadog_api_client.v1.model.table_widget_cell_display_mode import TableWidgetCellDisplayMode
2627
from datadog_api_client.v1.model.widget_conditional_format import WidgetConditionalFormat
2728
from datadog_api_client.v1.model.widget_formula_limit import WidgetFormulaLimit
29+
from datadog_api_client.v1.model.widget_formula_style import WidgetFormulaStyle
2830

2931
return {
3032
"alias": (str,),
3133
"cell_display_mode": (TableWidgetCellDisplayMode,),
3234
"conditional_formats": ([WidgetConditionalFormat],),
3335
"formula": (str,),
3436
"limit": (WidgetFormulaLimit,),
37+
"style": (WidgetFormulaStyle,),
3538
}
3639

3740
attribute_map = {
@@ -40,6 +43,7 @@ def openapi_types(_):
4043
"conditional_formats": "conditional_formats",
4144
"formula": "formula",
4245
"limit": "limit",
46+
"style": "style",
4347
}
4448

4549
def __init__(
@@ -49,6 +53,7 @@ def __init__(
4953
cell_display_mode: Union[TableWidgetCellDisplayMode, UnsetType] = unset,
5054
conditional_formats: Union[List[WidgetConditionalFormat], UnsetType] = unset,
5155
limit: Union[WidgetFormulaLimit, UnsetType] = unset,
56+
style: Union[WidgetFormulaStyle, UnsetType] = unset,
5257
**kwargs,
5358
):
5459
"""
@@ -68,6 +73,9 @@ def __init__(
6873
6974
:param limit: Options for limiting results returned.
7075
:type limit: WidgetFormulaLimit, optional
76+
77+
:param style: Styling options for widget formulas.
78+
:type style: WidgetFormulaStyle, optional
7179
"""
7280
if alias is not unset:
7381
kwargs["alias"] = alias
@@ -77,6 +85,8 @@ def __init__(
7785
kwargs["conditional_formats"] = conditional_formats
7886
if limit is not unset:
7987
kwargs["limit"] = limit
88+
if style is not unset:
89+
kwargs["style"] = style
8090
super().__init__(kwargs)
8191

8292
self_.formula = formula
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
# Copyright 2019-Present Datadog, Inc.
4+
from __future__ import annotations
5+
6+
from typing import Union
7+
8+
from datadog_api_client.model_utils import (
9+
ModelNormal,
10+
cached_property,
11+
unset,
12+
UnsetType,
13+
)
14+
15+
16+
class WidgetFormulaStyle(ModelNormal):
17+
@cached_property
18+
def openapi_types(_):
19+
return {
20+
"palette": (str,),
21+
"palette_index": (int,),
22+
}
23+
24+
attribute_map = {
25+
"palette": "palette",
26+
"palette_index": "palette_index",
27+
}
28+
29+
def __init__(self_, palette: Union[str, UnsetType] = unset, palette_index: Union[int, UnsetType] = unset, **kwargs):
30+
"""
31+
Styling options for widget formulas.
32+
33+
: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
34+
:type palette: str, optional
35+
36+
:param palette_index: Index specifying which color to use within the palette.
37+
:type palette_index: int, optional
38+
"""
39+
if palette is not unset:
40+
kwargs["palette"] = palette
41+
if palette_index is not unset:
42+
kwargs["palette_index"] = palette_index
43+
super().__init__(kwargs)

src/datadog_api_client/v1/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@
830830
from datadog_api_client.v1.model.widget_field_sort import WidgetFieldSort
831831
from datadog_api_client.v1.model.widget_formula import WidgetFormula
832832
from datadog_api_client.v1.model.widget_formula_limit import WidgetFormulaLimit
833+
from datadog_api_client.v1.model.widget_formula_style import WidgetFormulaStyle
833834
from datadog_api_client.v1.model.widget_grouping import WidgetGrouping
834835
from datadog_api_client.v1.model.widget_horizontal_align import WidgetHorizontalAlign
835836
from datadog_api_client.v1.model.widget_image_sizing import WidgetImageSizing
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2022-12-13T17:13:10.406Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
interactions:
2+
- request:
3+
body: '{"layout_type":"ordered","reflow_type":"auto","title":"Test-Create_a_new_dashboard_with_timeseries_widget_and_formula_style_attributes-1670951590
4+
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
5+
timeseries","type":"timeseries"}}]}'
6+
headers:
7+
accept:
8+
- application/json
9+
content-type:
10+
- application/json
11+
method: POST
12+
uri: https://api.datadoghq.com/api/v1/dashboard
13+
response:
14+
body:
15+
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
16+
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
17+
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"}
18+
19+
'
20+
headers:
21+
content-type:
22+
- application/json
23+
status:
24+
code: 200
25+
message: OK
26+
- request:
27+
body: null
28+
headers:
29+
accept:
30+
- application/json
31+
method: DELETE
32+
uri: https://api.datadoghq.com/api/v1/dashboard/k2c-ici-a4c
33+
response:
34+
body:
35+
string: '{"deleted_dashboard_id":"k2c-ici-a4c"}
36+
37+
'
38+
headers:
39+
content-type:
40+
- application/json
41+
status:
42+
code: 200
43+
message: OK
44+
version: 1

tests/v1/features/dashboards.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,16 @@ Feature: Dashboards
479479
When the request is sent
480480
Then the response status is 200 OK
481481

482+
@team:DataDog/dashboards
483+
Scenario: Create a new dashboard with timeseries widget and formula style attributes
484+
Given new "CreateDashboard" request
485+
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"}
486+
When the request is sent
487+
Then the response status is 200 OK
488+
And the response "widgets[0].definition.requests[0].formulas[0].formula" is equal to "query1"
489+
And the response "widgets[0].definition.requests[0].formulas[0].style.palette" is equal to "classic"
490+
And the response "widgets[0].definition.requests[0].formulas[0].style.palette_index" is equal to 4
491+
482492
@team:DataDog/dashboards
483493
Scenario: Create a new dashboard with timeseries widget containing style attributes
484494
Given new "CreateDashboard" request

0 commit comments

Comments
 (0)