Skip to content

Commit

Permalink
Fix Toplist widget's stacked display style - remove legend as require…
Browse files Browse the repository at this point in the history
…d field (#2184)

Co-authored-by: ci.datadog-api-spec <[email protected]>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored Oct 2, 2024
1 parent 465f013 commit cc2b046
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 10 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.6",
"regenerated": "2024-10-02 14:33:47.623313",
"spec_repo_commit": "3b4747f4"
"regenerated": "2024-10-02 16:22:33.012208",
"spec_repo_commit": "3f12bebc"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-10-02 14:33:47.636722",
"spec_repo_commit": "3b4747f4"
"regenerated": "2024-10-02 16:22:33.026114",
"spec_repo_commit": "3f12bebc"
}
}
}
1 change: 0 additions & 1 deletion .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18188,7 +18188,6 @@ components:
$ref: '#/components/schemas/ToplistWidgetStackedType'
required:
- type
- legend
type: object
ToplistWidgetStackedType:
default: stacked
Expand Down
98 changes: 98 additions & 0 deletions examples/v1/dashboards/CreateDashboard_1413226400.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""
Create a new dashboard with a toplist widget with stacked type and no legend specified
"""

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.formula_and_function_metric_aggregation import FormulaAndFunctionMetricAggregation
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.group_type import GroupType
from datadog_api_client.v1.model.toplist_widget_definition import ToplistWidgetDefinition
from datadog_api_client.v1.model.toplist_widget_definition_type import ToplistWidgetDefinitionType
from datadog_api_client.v1.model.toplist_widget_request import ToplistWidgetRequest
from datadog_api_client.v1.model.toplist_widget_scaling import ToplistWidgetScaling
from datadog_api_client.v1.model.toplist_widget_stacked import ToplistWidgetStacked
from datadog_api_client.v1.model.toplist_widget_stacked_type import ToplistWidgetStackedType
from datadog_api_client.v1.model.toplist_widget_style import ToplistWidgetStyle
from datadog_api_client.v1.model.widget import Widget
from datadog_api_client.v1.model.widget_formula import WidgetFormula
from datadog_api_client.v1.model.widget_group_sort import WidgetGroupSort
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_sort import WidgetSort
from datadog_api_client.v1.model.widget_sort_by import WidgetSortBy
from datadog_api_client.v1.model.widget_text_align import WidgetTextAlign

body = Dashboard(
title="Example-Dashboard",
description="",
widgets=[
Widget(
layout=WidgetLayout(
x=0,
y=0,
width=47,
height=15,
),
definition=ToplistWidgetDefinition(
title="",
title_size="16",
title_align=WidgetTextAlign.LEFT,
time=WidgetLegacyLiveSpan(),
style=ToplistWidgetStyle(
display=ToplistWidgetStacked(
type=ToplistWidgetStackedType.STACKED,
),
scaling=ToplistWidgetScaling.RELATIVE,
palette="dog_classic",
),
type=ToplistWidgetDefinitionType.TOPLIST,
requests=[
ToplistWidgetRequest(
queries=[
FormulaAndFunctionMetricQueryDefinition(
data_source=FormulaAndFunctionMetricDataSource.METRICS,
name="query1",
query="avg:system.cpu.user{*} by {service}",
aggregator=FormulaAndFunctionMetricAggregation.AVG,
),
],
formulas=[
WidgetFormula(
formula="query1",
),
],
sort=WidgetSortBy(
count=10,
order_by=[
WidgetGroupSort(
type=GroupType.GROUP,
name="service",
order=WidgetSort.ASCENDING,
),
],
),
response_format=FormulaAndFunctionResponseFormat.SCALAR,
),
],
),
),
],
template_variables=[],
layout_type=DashboardLayoutType.FREE,
is_read_only=False,
notify_list=[],
)

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

print(response)
2 changes: 1 addition & 1 deletion src/datadog_api_client/v1/model/toplist_widget_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, **kwargs):
Top list widget display options.
:param legend: Top list widget stacked legend behavior.
:type legend: ToplistWidgetLegend
:type legend: ToplistWidgetLegend, optional
:param type: Top list widget stacked display type.
:type type: ToplistWidgetStackedType
Expand Down
13 changes: 9 additions & 4 deletions src/datadog_api_client/v1/model/toplist_widget_stacked.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Union, TYPE_CHECKING

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


Expand All @@ -32,17 +34,20 @@ def openapi_types(_):
"type": "type",
}

def __init__(self_, legend: ToplistWidgetLegend, type: ToplistWidgetStackedType, **kwargs):
def __init__(
self_, type: ToplistWidgetStackedType, legend: Union[ToplistWidgetLegend, UnsetType] = unset, **kwargs
):
"""
Top list widget stacked display options.
:param legend: Top list widget stacked legend behavior.
:type legend: ToplistWidgetLegend
:type legend: ToplistWidgetLegend, optional
:param type: Top list widget stacked display type.
:type type: ToplistWidgetStackedType
"""
if legend is not unset:
kwargs["legend"] = legend
super().__init__(kwargs)

self_.legend = legend
self_.type = type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-09-30T17:24:52.299Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
interactions:
- request:
body: '{"description":"","is_read_only":false,"layout_type":"free","notify_list":[],"template_variables":[],"title":"Test-Create_a_new_dashboard_with_a_toplist_widget_with_stacked_type_and_no_legend_specified-1727717092","widgets":[{"definition":{"requests":[{"formulas":[{"formula":"query1"}],"queries":[{"aggregator":"avg","data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*}
by {service}"}],"response_format":"scalar","sort":{"count":10,"order_by":[{"name":"service","order":"asc","type":"group"}]}}],"style":{"display":{"type":"stacked"},"palette":"dog_classic","scaling":"relative"},"time":{},"title":"","title_align":"left","title_size":"16","type":"toplist"},"layout":{"height":15,"width":47,"x":0,"y":0}}]}'
headers:
accept:
- application/json
content-type:
- application/json
method: POST
uri: https://api.datadoghq.com/api/v1/dashboard
response:
body:
string: '{"id":"2az-xeg-xar","title":"Test-Create_a_new_dashboard_with_a_toplist_widget_with_stacked_type_and_no_legend_specified-1727717092","description":"","author_handle":"[email protected]","author_name":null,"layout_type":"free","url":"/dashboard/2az-xeg-xar/test-createanewdashboardwithatoplistwidgetwithstackedtypeandnolegendspecified-17","is_read_only":false,"template_variables":[],"widgets":[{"definition":{"requests":[{"formulas":[{"formula":"query1"}],"queries":[{"aggregator":"avg","data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*}
by {service}"}],"response_format":"scalar","sort":{"count":10,"order_by":[{"name":"service","order":"asc","type":"group"}]}}],"style":{"display":{"type":"stacked"},"palette":"dog_classic","scaling":"relative"},"time":{},"title":"","title_align":"left","title_size":"16","type":"toplist"},"layout":{"height":15,"width":47,"x":0,"y":0},"id":688132644515996}],"notify_list":[],"created_at":"2024-09-30T17:24:52.542207+00:00","modified_at":"2024-09-30T17:24:52.542207+00:00","experience_type":"default","restricted_roles":[]}
'
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/2az-xeg-xar
response:
body:
string: '{"deleted_dashboard_id":"2az-xeg-xar"}
'
headers:
content-type:
- application/json
status:
code: 200
message: OK
version: 1
13 changes: 13 additions & 0 deletions tests/v1/features/dashboards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ Feature: Dashboards
And the response "widgets[0].definition.requests[0].sort.order_by[0].type" is equal to "group"
And the response "widgets[0].definition.requests[0].sort.order_by[0].name" is equal to "service"

@skip-typescript @team:DataDog/dashboards-backend
Scenario: Create a new dashboard with a toplist widget with stacked type and no legend specified
Given new "CreateDashboard" request
And body with value {"title":"{{ unique }}","description":"","widgets":[{"layout":{"x":0,"y":0,"width":47,"height":15},"definition":{"title":"","title_size":"16","title_align":"left","time":{},"style":{"display": {"type": "stacked"},"scaling": "relative","palette": "dog_classic"},"type":"toplist","requests":[{"queries":[{"data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*} by {service}","aggregator":"avg"}],"formulas":[{"formula":"query1"}],"sort":{"count":10,"order_by":[{"type":"group","name":"service","order":"asc"}]},"response_format":"scalar"}]}}],"template_variables":[],"layout_type":"free","is_read_only":false,"notify_list":[]}
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.type" is equal to "toplist"
And the response "widgets[0].definition.requests[0].sort.order_by[0].order" is equal to "asc"
And the response "widgets[0].definition.requests[0].sort.order_by[0].type" is equal to "group"
And the response "widgets[0].definition.requests[0].sort.order_by[0].name" is equal to "service"
And the response "widgets[0].definition.style.display.type" is equal to "stacked"
And the response "widgets[0].definition.style.display" does not have field "legend"

@team:DataDog/dashboards-backend
Scenario: Create a new dashboard with alert_graph widget
Given there is a valid "monitor" in the system
Expand Down

0 comments on commit cc2b046

Please sign in to comment.