-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add style object to dashboard widget formulas (#1266)
Co-authored-by: ci.datadog-api-spec <[email protected]>
- Loading branch information
1 parent
00eb938
commit 7a7be3c
Showing
10 changed files
with
221 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...os/test_create_a_new_dashboard_with_timeseries_widget_and_formula_style_attributes.frozen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2022-12-13T17:13:10.406Z |
44 changes: 44 additions & 0 deletions
44
...rios/test_create_a_new_dashboard_with_timeseries_widget_and_formula_style_attributes.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters