Skip to content

Commit cd574a7

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add order_by field to timeseries widget request schema (DataDog#3631)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent eabfde6 commit cd574a7

13 files changed

Lines changed: 436 additions & 4 deletions

.generator/schemas/v1/openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25956,6 +25956,8 @@ components:
2595625956
$ref: '#/components/schemas/WidgetLineType'
2595725957
line_width:
2595825958
$ref: '#/components/schemas/WidgetLineWidth'
25959+
order_by:
25960+
$ref: '#/components/schemas/WidgetStyleOrderBy'
2595925961
palette:
2596025962
description: Color palette to apply to the widget.
2596125963
type: string
@@ -26018,6 +26020,19 @@ components:
2601826020
description: Color palette to apply to the widget.
2601926021
type: string
2602026022
type: object
26023+
WidgetStyleOrderBy:
26024+
description: 'How to order series in timeseries visualizations.
26025+
26026+
- `tags`: Order series alphabetically by tag name (default behavior)
26027+
26028+
- `values`: Order series by their current metric values (typically descending)'
26029+
enum:
26030+
- tags
26031+
- values
26032+
type: string
26033+
x-enum-varnames:
26034+
- TAGS
26035+
- VALUES
2602126036
WidgetSummaryType:
2602226037
description: Which summary type should be used.
2602326038
enum:

api/datadogV1/model_widget_request_style.go

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ type WidgetRequestStyle struct {
1414
LineType *WidgetLineType `json:"line_type,omitempty"`
1515
// Width of line displayed.
1616
LineWidth *WidgetLineWidth `json:"line_width,omitempty"`
17+
// How to order series in timeseries visualizations.
18+
// - `tags`: Order series alphabetically by tag name (default behavior)
19+
// - `values`: Order series by their current metric values (typically descending)
20+
OrderBy *WidgetStyleOrderBy `json:"order_by,omitempty"`
1721
// Color palette to apply to the widget.
1822
Palette *string `json:"palette,omitempty"`
1923
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
@@ -94,6 +98,34 @@ func (o *WidgetRequestStyle) SetLineWidth(v WidgetLineWidth) {
9498
o.LineWidth = &v
9599
}
96100

101+
// GetOrderBy returns the OrderBy field value if set, zero value otherwise.
102+
func (o *WidgetRequestStyle) GetOrderBy() WidgetStyleOrderBy {
103+
if o == nil || o.OrderBy == nil {
104+
var ret WidgetStyleOrderBy
105+
return ret
106+
}
107+
return *o.OrderBy
108+
}
109+
110+
// GetOrderByOk returns a tuple with the OrderBy field value if set, nil otherwise
111+
// and a boolean to check if the value has been set.
112+
func (o *WidgetRequestStyle) GetOrderByOk() (*WidgetStyleOrderBy, bool) {
113+
if o == nil || o.OrderBy == nil {
114+
return nil, false
115+
}
116+
return o.OrderBy, true
117+
}
118+
119+
// HasOrderBy returns a boolean if a field has been set.
120+
func (o *WidgetRequestStyle) HasOrderBy() bool {
121+
return o != nil && o.OrderBy != nil
122+
}
123+
124+
// SetOrderBy gets a reference to the given WidgetStyleOrderBy and assigns it to the OrderBy field.
125+
func (o *WidgetRequestStyle) SetOrderBy(v WidgetStyleOrderBy) {
126+
o.OrderBy = &v
127+
}
128+
97129
// GetPalette returns the Palette field value if set, zero value otherwise.
98130
func (o *WidgetRequestStyle) GetPalette() string {
99131
if o == nil || o.Palette == nil {
@@ -134,6 +166,9 @@ func (o WidgetRequestStyle) MarshalJSON() ([]byte, error) {
134166
if o.LineWidth != nil {
135167
toSerialize["line_width"] = o.LineWidth
136168
}
169+
if o.OrderBy != nil {
170+
toSerialize["order_by"] = o.OrderBy
171+
}
137172
if o.Palette != nil {
138173
toSerialize["palette"] = o.Palette
139174
}
@@ -147,16 +182,17 @@ func (o WidgetRequestStyle) MarshalJSON() ([]byte, error) {
147182
// UnmarshalJSON deserializes the given payload.
148183
func (o *WidgetRequestStyle) UnmarshalJSON(bytes []byte) (err error) {
149184
all := struct {
150-
LineType *WidgetLineType `json:"line_type,omitempty"`
151-
LineWidth *WidgetLineWidth `json:"line_width,omitempty"`
152-
Palette *string `json:"palette,omitempty"`
185+
LineType *WidgetLineType `json:"line_type,omitempty"`
186+
LineWidth *WidgetLineWidth `json:"line_width,omitempty"`
187+
OrderBy *WidgetStyleOrderBy `json:"order_by,omitempty"`
188+
Palette *string `json:"palette,omitempty"`
153189
}{}
154190
if err = datadog.Unmarshal(bytes, &all); err != nil {
155191
return datadog.Unmarshal(bytes, &o.UnparsedObject)
156192
}
157193
additionalProperties := make(map[string]interface{})
158194
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
159-
datadog.DeleteKeys(additionalProperties, &[]string{"line_type", "line_width", "palette"})
195+
datadog.DeleteKeys(additionalProperties, &[]string{"line_type", "line_width", "order_by", "palette"})
160196
} else {
161197
return err
162198
}
@@ -172,6 +208,11 @@ func (o *WidgetRequestStyle) UnmarshalJSON(bytes []byte) (err error) {
172208
} else {
173209
o.LineWidth = all.LineWidth
174210
}
211+
if all.OrderBy != nil && !all.OrderBy.IsValid() {
212+
hasInvalidField = true
213+
} else {
214+
o.OrderBy = all.OrderBy
215+
}
175216
o.Palette = all.Palette
176217

177218
if len(additionalProperties) > 0 {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
5+
package datadogV1
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
11+
)
12+
13+
// WidgetStyleOrderBy How to order series in timeseries visualizations.
14+
// - `tags`: Order series alphabetically by tag name (default behavior)
15+
// - `values`: Order series by their current metric values (typically descending)
16+
type WidgetStyleOrderBy string
17+
18+
// List of WidgetStyleOrderBy.
19+
const (
20+
WIDGETSTYLEORDERBY_TAGS WidgetStyleOrderBy = "tags"
21+
WIDGETSTYLEORDERBY_VALUES WidgetStyleOrderBy = "values"
22+
)
23+
24+
var allowedWidgetStyleOrderByEnumValues = []WidgetStyleOrderBy{
25+
WIDGETSTYLEORDERBY_TAGS,
26+
WIDGETSTYLEORDERBY_VALUES,
27+
}
28+
29+
// GetAllowedValues reeturns the list of possible values.
30+
func (v *WidgetStyleOrderBy) GetAllowedValues() []WidgetStyleOrderBy {
31+
return allowedWidgetStyleOrderByEnumValues
32+
}
33+
34+
// UnmarshalJSON deserializes the given payload.
35+
func (v *WidgetStyleOrderBy) UnmarshalJSON(src []byte) error {
36+
var value string
37+
err := datadog.Unmarshal(src, &value)
38+
if err != nil {
39+
return err
40+
}
41+
*v = WidgetStyleOrderBy(value)
42+
return nil
43+
}
44+
45+
// NewWidgetStyleOrderByFromValue returns a pointer to a valid WidgetStyleOrderBy
46+
// for the value passed as argument, or an error if the value passed is not allowed by the enum.
47+
func NewWidgetStyleOrderByFromValue(v string) (*WidgetStyleOrderBy, error) {
48+
ev := WidgetStyleOrderBy(v)
49+
if ev.IsValid() {
50+
return &ev, nil
51+
}
52+
return nil, fmt.Errorf("invalid value '%v' for WidgetStyleOrderBy: valid values are %v", v, allowedWidgetStyleOrderByEnumValues)
53+
}
54+
55+
// IsValid return true if the value is valid for the enum, false otherwise.
56+
func (v WidgetStyleOrderBy) IsValid() bool {
57+
for _, existing := range allowedWidgetStyleOrderByEnumValues {
58+
if existing == v {
59+
return true
60+
}
61+
}
62+
return false
63+
}
64+
65+
// Ptr returns reference to WidgetStyleOrderBy value.
66+
func (v WidgetStyleOrderBy) Ptr() *WidgetStyleOrderBy {
67+
return &v
68+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Create a new dashboard with timeseries widget using order_by values
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"encoding/json"
8+
"fmt"
9+
"os"
10+
11+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
12+
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
13+
)
14+
15+
func main() {
16+
body := datadogV1.Dashboard{
17+
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
18+
Title: "Example-Dashboard with order_by values",
19+
Widgets: []datadogV1.Widget{
20+
{
21+
Definition: datadogV1.WidgetDefinition{
22+
TimeseriesWidgetDefinition: &datadogV1.TimeseriesWidgetDefinition{
23+
Type: datadogV1.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES,
24+
Requests: []datadogV1.TimeseriesWidgetRequest{
25+
{
26+
Q: datadog.PtrString("avg:system.cpu.user{*} by {host}"),
27+
Style: &datadogV1.WidgetRequestStyle{
28+
Palette: datadog.PtrString("warm"),
29+
OrderBy: datadogV1.WIDGETSTYLEORDERBY_VALUES.Ptr(),
30+
},
31+
DisplayType: datadogV1.WIDGETDISPLAYTYPE_LINE.Ptr(),
32+
},
33+
},
34+
}},
35+
},
36+
},
37+
}
38+
ctx := datadog.NewDefaultContext(context.Background())
39+
configuration := datadog.NewConfiguration()
40+
apiClient := datadog.NewAPIClient(configuration)
41+
api := datadogV1.NewDashboardsApi(apiClient)
42+
resp, r, err := api.CreateDashboard(ctx, body)
43+
44+
if err != nil {
45+
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err)
46+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
47+
}
48+
49+
responseContent, _ := json.MarshalIndent(resp, "", " ")
50+
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent)
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Create a new dashboard with timeseries widget without order_by for backward compatibility
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"encoding/json"
8+
"fmt"
9+
"os"
10+
11+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
12+
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
13+
)
14+
15+
func main() {
16+
body := datadogV1.Dashboard{
17+
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
18+
Title: "Example-Dashboard without order_by",
19+
Widgets: []datadogV1.Widget{
20+
{
21+
Definition: datadogV1.WidgetDefinition{
22+
TimeseriesWidgetDefinition: &datadogV1.TimeseriesWidgetDefinition{
23+
Type: datadogV1.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES,
24+
Requests: []datadogV1.TimeseriesWidgetRequest{
25+
{
26+
Q: datadog.PtrString("avg:system.cpu.user{*} by {host}"),
27+
Style: &datadogV1.WidgetRequestStyle{
28+
Palette: datadog.PtrString("dog_classic"),
29+
LineType: datadogV1.WIDGETLINETYPE_SOLID.Ptr(),
30+
LineWidth: datadogV1.WIDGETLINEWIDTH_NORMAL.Ptr(),
31+
},
32+
DisplayType: datadogV1.WIDGETDISPLAYTYPE_LINE.Ptr(),
33+
},
34+
},
35+
}},
36+
},
37+
},
38+
}
39+
ctx := datadog.NewDefaultContext(context.Background())
40+
configuration := datadog.NewConfiguration()
41+
apiClient := datadog.NewAPIClient(configuration)
42+
api := datadogV1.NewDashboardsApi(apiClient)
43+
resp, r, err := api.CreateDashboard(ctx, body)
44+
45+
if err != nil {
46+
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err)
47+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
48+
}
49+
50+
responseContent, _ := json.MarshalIndent(resp, "", " ")
51+
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent)
52+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Create a new dashboard with timeseries widget using order_by tags
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"encoding/json"
8+
"fmt"
9+
"os"
10+
11+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
12+
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
13+
)
14+
15+
func main() {
16+
body := datadogV1.Dashboard{
17+
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
18+
Title: "Example-Dashboard with order_by tags",
19+
Widgets: []datadogV1.Widget{
20+
{
21+
Definition: datadogV1.WidgetDefinition{
22+
TimeseriesWidgetDefinition: &datadogV1.TimeseriesWidgetDefinition{
23+
Type: datadogV1.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES,
24+
Requests: []datadogV1.TimeseriesWidgetRequest{
25+
{
26+
Q: datadog.PtrString("avg:system.cpu.user{*} by {host}"),
27+
Style: &datadogV1.WidgetRequestStyle{
28+
Palette: datadog.PtrString("dog_classic"),
29+
OrderBy: datadogV1.WIDGETSTYLEORDERBY_TAGS.Ptr(),
30+
},
31+
DisplayType: datadogV1.WIDGETDISPLAYTYPE_LINE.Ptr(),
32+
},
33+
},
34+
}},
35+
},
36+
},
37+
}
38+
ctx := datadog.NewDefaultContext(context.Background())
39+
configuration := datadog.NewConfiguration()
40+
apiClient := datadog.NewAPIClient(configuration)
41+
api := datadogV1.NewDashboardsApi(apiClient)
42+
resp, r, err := api.CreateDashboard(ctx, body)
43+
44+
if err != nil {
45+
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err)
46+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
47+
}
48+
49+
responseContent, _ := json.MarshalIndent(resp, "", " ")
50+
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent)
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026-01-20T23:39:22.864Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
interactions:
2+
- request:
3+
body: |
4+
{"layout_type":"ordered","title":"Test-Create_a_new_dashboard_with_timeseries_widget_using_order_by_tags-1768952362 with order_by tags","widgets":[{"definition":{"requests":[{"display_type":"line","q":"avg:system.cpu.user{*} by {host}","style":{"order_by":"tags","palette":"dog_classic"}}],"type":"timeseries"}}]}
5+
form: {}
6+
headers:
7+
Accept:
8+
- application/json
9+
Content-Type:
10+
- application/json
11+
id: 0
12+
method: POST
13+
url: https://api.datadoghq.com/api/v1/dashboard
14+
response:
15+
body: '{"id":"2r3-a4g-ubz","title":"Test-Create_a_new_dashboard_with_timeseries_widget_using_order_by_tags-1768952362
16+
with order_by tags","description":null,"author_handle":"frog@datadoghq.com","author_name":"frog","layout_type":"ordered","url":"/dashboard/2r3-a4g-ubz/test-createanewdashboardwithtimeserieswidgetusingorderbytags-1768952362-with-ord","template_variables":null,"widgets":[{"definition":{"requests":[{"display_type":"line","q":"avg:system.cpu.user{*}
17+
by {host}","style":{"order_by":"tags","palette":"dog_classic"}}],"type":"timeseries"},"id":8704189893014651}],"notify_list":null,"created_at":"2026-01-20T23:39:22.992533+00:00","modified_at":"2026-01-20T23:39:22.992533+00:00","restricted_roles":[]}'
18+
code: 200
19+
duration: 0ms
20+
headers:
21+
Content-Type:
22+
- application/json
23+
status: 200 OK
24+
- request:
25+
body: ''
26+
form: {}
27+
headers:
28+
Accept:
29+
- application/json
30+
id: 1
31+
method: DELETE
32+
url: https://api.datadoghq.com/api/v1/dashboard/2r3-a4g-ubz
33+
response:
34+
body: '{"deleted_dashboard_id":"2r3-a4g-ubz"}'
35+
code: 200
36+
duration: 0ms
37+
headers:
38+
Content-Type:
39+
- application/json
40+
status: 200 OK
41+
version: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026-01-20T23:39:50.889Z

0 commit comments

Comments
 (0)