Skip to content

Commit

Permalink
Add sort field to List Stream Widget's request query (#2020)
Browse files Browse the repository at this point in the history
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored May 31, 2023
1 parent 2edbce5 commit 5cd5960
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 5 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": "2023-05-30 14:29:03.063764",
"spec_repo_commit": "adf5379f"
"regenerated": "2023-05-31 17:18:55.869686",
"spec_repo_commit": "3b710977"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2023-05-30 14:29:03.079023",
"spec_repo_commit": "adf5379f"
"regenerated": "2023-05-31 17:18:55.882420",
"spec_repo_commit": "3b710977"
}
}
}
2 changes: 2 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4289,6 +4289,8 @@ components:
description: Widget query.
example: '@service:app'
type: string
sort:
$ref: '#/components/schemas/WidgetFieldSort'
storage:
description: Option for storage location. Feature in Private Beta.
example: indexes
Expand Down
44 changes: 43 additions & 1 deletion api/datadogV1/model_list_stream_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type ListStreamQuery struct {
Indexes []string `json:"indexes,omitempty"`
// Widget query.
QueryString string `json:"query_string"`
// Which column and order to sort by
Sort *WidgetFieldSort `json:"sort,omitempty"`
// Option for storage location. Feature in Private Beta.
Storage *string `json:"storage,omitempty"`
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
Expand Down Expand Up @@ -211,6 +213,34 @@ func (o *ListStreamQuery) SetQueryString(v string) {
o.QueryString = v
}

// GetSort returns the Sort field value if set, zero value otherwise.
func (o *ListStreamQuery) GetSort() WidgetFieldSort {
if o == nil || o.Sort == nil {
var ret WidgetFieldSort
return ret
}
return *o.Sort
}

// GetSortOk returns a tuple with the Sort field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *ListStreamQuery) GetSortOk() (*WidgetFieldSort, bool) {
if o == nil || o.Sort == nil {
return nil, false
}
return o.Sort, true
}

// HasSort returns a boolean if a field has been set.
func (o *ListStreamQuery) HasSort() bool {
return o != nil && o.Sort != nil
}

// SetSort gets a reference to the given WidgetFieldSort and assigns it to the Sort field.
func (o *ListStreamQuery) SetSort(v WidgetFieldSort) {
o.Sort = &v
}

// GetStorage returns the Storage field value if set, zero value otherwise.
func (o *ListStreamQuery) GetStorage() string {
if o == nil || o.Storage == nil {
Expand Down Expand Up @@ -259,6 +289,9 @@ func (o ListStreamQuery) MarshalJSON() ([]byte, error) {
toSerialize["indexes"] = o.Indexes
}
toSerialize["query_string"] = o.QueryString
if o.Sort != nil {
toSerialize["sort"] = o.Sort
}
if o.Storage != nil {
toSerialize["storage"] = o.Storage
}
Expand All @@ -283,6 +316,7 @@ func (o *ListStreamQuery) UnmarshalJSON(bytes []byte) (err error) {
GroupBy []ListStreamGroupByItems `json:"group_by,omitempty"`
Indexes []string `json:"indexes,omitempty"`
QueryString string `json:"query_string"`
Sort *WidgetFieldSort `json:"sort,omitempty"`
Storage *string `json:"storage,omitempty"`
}{}
err = json.Unmarshal(bytes, &required)
Expand All @@ -306,7 +340,7 @@ func (o *ListStreamQuery) UnmarshalJSON(bytes []byte) (err error) {
}
additionalProperties := make(map[string]interface{})
if err = json.Unmarshal(bytes, &additionalProperties); err == nil {
datadog.DeleteKeys(additionalProperties, &[]string{"compute", "data_source", "event_size", "group_by", "indexes", "query_string", "storage"})
datadog.DeleteKeys(additionalProperties, &[]string{"compute", "data_source", "event_size", "group_by", "indexes", "query_string", "sort", "storage"})
} else {
return err
}
Expand All @@ -332,6 +366,14 @@ func (o *ListStreamQuery) UnmarshalJSON(bytes []byte) (err error) {
o.GroupBy = all.GroupBy
o.Indexes = all.Indexes
o.QueryString = all.QueryString
if all.Sort != nil && all.Sort.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Sort = all.Sort
o.Storage = all.Storage
if len(additionalProperties) > 0 {
o.AdditionalProperties = additionalProperties
Expand Down
61 changes: 61 additions & 0 deletions examples/v1/dashboards/CreateDashboard_1877023900.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Create a new dashboard with list_stream widget with a valid sort parameter ASC

package main

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
)

func main() {
body := datadogV1.Dashboard{
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
Title: "Example-Dashboard with list_stream widget",
Widgets: []datadogV1.Widget{
{
Definition: datadogV1.WidgetDefinition{
ListStreamWidgetDefinition: &datadogV1.ListStreamWidgetDefinition{
Type: datadogV1.LISTSTREAMWIDGETDEFINITIONTYPE_LIST_STREAM,
Requests: []datadogV1.ListStreamWidgetRequest{
{
Columns: []datadogV1.ListStreamColumn{
{
Width: datadogV1.LISTSTREAMCOLUMNWIDTH_AUTO,
Field: "timestamp",
},
},
Query: datadogV1.ListStreamQuery{
DataSource: datadogV1.LISTSTREAMSOURCE_EVENT_STREAM,
QueryString: "",
EventSize: datadogV1.WIDGETEVENTSIZE_LARGE.Ptr(),
Sort: &datadogV1.WidgetFieldSort{
Column: "timestamp",
Order: datadogV1.WIDGETSORT_ASCENDING,
},
},
ResponseFormat: datadogV1.LISTSTREAMRESPONSEFORMAT_EVENT_LIST,
},
},
}},
},
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV1.NewDashboardsApi(apiClient)
resp, r, err := api.CreateDashboard(ctx, body)

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}

responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent)
}
61 changes: 61 additions & 0 deletions examples/v1/dashboards/CreateDashboard_2361531620.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Create a new dashboard with list_stream widget with a valid sort parameter DESC

package main

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
)

func main() {
body := datadogV1.Dashboard{
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
Title: "Example-Dashboard with list_stream widget",
Widgets: []datadogV1.Widget{
{
Definition: datadogV1.WidgetDefinition{
ListStreamWidgetDefinition: &datadogV1.ListStreamWidgetDefinition{
Type: datadogV1.LISTSTREAMWIDGETDEFINITIONTYPE_LIST_STREAM,
Requests: []datadogV1.ListStreamWidgetRequest{
{
Columns: []datadogV1.ListStreamColumn{
{
Width: datadogV1.LISTSTREAMCOLUMNWIDTH_AUTO,
Field: "timestamp",
},
},
Query: datadogV1.ListStreamQuery{
DataSource: datadogV1.LISTSTREAMSOURCE_EVENT_STREAM,
QueryString: "",
EventSize: datadogV1.WIDGETEVENTSIZE_LARGE.Ptr(),
Sort: &datadogV1.WidgetFieldSort{
Column: "timestamp",
Order: datadogV1.WIDGETSORT_DESCENDING,
},
},
ResponseFormat: datadogV1.LISTSTREAMRESPONSEFORMAT_EVENT_LIST,
},
},
}},
},
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV1.NewDashboardsApi(apiClient)
resp, r, err := api.CreateDashboard(ctx, body)

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}

responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-05-31T17:12:24.532Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
interactions:
- request:
body: |
{"layout_type":"ordered","title":"Test-Create_a_new_dashboard_with_list_stream_widget_with_a_valid_sort_parameter_ASC-1685553144 with list_stream widget","widgets":[{"definition":{"requests":[{"columns":[{"field":"timestamp","width":"auto"}],"query":{"data_source":"event_stream","event_size":"l","query_string":"","sort":{"column":"timestamp","order":"asc"}},"response_format":"event_list"}],"type":"list_stream"}}]}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: POST
url: https://api.datadoghq.com/api/v1/dashboard
response:
body: '{"id":"td2-he3-3vj","title":"Test-Create_a_new_dashboard_with_list_stream_widget_with_a_valid_sort_parameter_ASC-1685553144
with list_stream widget","description":null,"author_handle":"frog@datadoghq.com","author_name":null,"layout_type":"ordered","url":"/dashboard/td2-he3-3vj/test-createanewdashboardwithliststreamwidgetwithavalidsortparameterasc-168555314","is_read_only":false,"template_variables":null,"widgets":[{"definition":{"requests":[{"columns":[{"field":"timestamp","width":"auto"}],"query":{"data_source":"event_stream","event_size":"l","query_string":"","sort":{"column":"timestamp","order":"asc"}},"response_format":"event_list"}],"type":"list_stream"},"id":4579982797049164}],"notify_list":null,"created_at":"2023-05-31T17:12:24.700217+00:00","modified_at":"2023-05-31T17:12:24.700217+00:00","restricted_roles":[]}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
- request:
body: ''
form: {}
headers:
Accept:
- application/json
method: DELETE
url: https://api.datadoghq.com/api/v1/dashboard/td2-he3-3vj
response:
body: '{"deleted_dashboard_id":"td2-he3-3vj"}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-05-31T17:12:24.923Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
interactions:
- request:
body: |
{"layout_type":"ordered","title":"Test-Create_a_new_dashboard_with_list_stream_widget_with_a_valid_sort_parameter_DESC-1685553144 with list_stream widget","widgets":[{"definition":{"requests":[{"columns":[{"field":"timestamp","width":"auto"}],"query":{"data_source":"event_stream","event_size":"l","query_string":"","sort":{"column":"timestamp","order":"desc"}},"response_format":"event_list"}],"type":"list_stream"}}]}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: POST
url: https://api.datadoghq.com/api/v1/dashboard
response:
body: '{"id":"mwn-7ph-8z8","title":"Test-Create_a_new_dashboard_with_list_stream_widget_with_a_valid_sort_parameter_DESC-1685553144
with list_stream widget","description":null,"author_handle":"frog@datadoghq.com","author_name":null,"layout_type":"ordered","url":"/dashboard/mwn-7ph-8z8/test-createanewdashboardwithliststreamwidgetwithavalidsortparameterdesc-16855531","is_read_only":false,"template_variables":null,"widgets":[{"definition":{"requests":[{"columns":[{"field":"timestamp","width":"auto"}],"query":{"data_source":"event_stream","event_size":"l","query_string":"","sort":{"column":"timestamp","order":"desc"}},"response_format":"event_list"}],"type":"list_stream"},"id":8830087860290510}],"notify_list":null,"created_at":"2023-05-31T17:12:25.020023+00:00","modified_at":"2023-05-31T17:12:25.020023+00:00","restricted_roles":[]}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
- request:
body: ''
form: {}
headers:
Accept:
- application/json
method: DELETE
url: https://api.datadoghq.com/api/v1/dashboard/mwn-7ph-8z8
response:
body: '{"deleted_dashboard_id":"mwn-7ph-8z8"}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
version: 1
26 changes: 26 additions & 0 deletions tests/scenarios/features/v1/dashboards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,32 @@ Feature: Dashboards
And the response "widgets[0].definition.type" is equal to "list_stream"
And the response "widgets[0].definition.requests[0].query.data_source" is equal to "apm_issue_stream"

@team:DataDog/dashboards-backend
Scenario: Create a new dashboard with list_stream widget with a valid sort parameter ASC
Given new "CreateDashboard" request
And body with value {"layout_type": "ordered","title": "{{ unique }} with list_stream widget","widgets": [{"definition": {"type": "list_stream","requests": [{"columns": [{"width": "auto","field": "timestamp"}],"query": {"data_source": "event_stream","query_string": "","event_size": "l", "sort": {"column": "timestamp", "order": "asc"}},"response_format": "event_list"}]}}]}
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.type" is equal to "list_stream"
And the response "widgets[0].definition.requests[0].response_format" is equal to "event_list"
And the response "widgets[0].definition.requests[0].query.data_source" is equal to "event_stream"
And the response "widgets[0].definition.requests[0].query.event_size" is equal to "l"
And the response "widgets[0].definition.requests[0].query.sort.column" is equal to "timestamp"
And the response "widgets[0].definition.requests[0].query.sort.order" is equal to "asc"

@team:DataDog/dashboards-backend
Scenario: Create a new dashboard with list_stream widget with a valid sort parameter DESC
Given new "CreateDashboard" request
And body with value {"layout_type": "ordered","title": "{{ unique }} with list_stream widget","widgets": [{"definition": {"type": "list_stream","requests": [{"columns": [{"width": "auto","field": "timestamp"}],"query": {"data_source": "event_stream","query_string": "","event_size": "l", "sort": {"column": "timestamp", "order": "desc"}},"response_format": "event_list"}]}}]}
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.type" is equal to "list_stream"
And the response "widgets[0].definition.requests[0].response_format" is equal to "event_list"
And the response "widgets[0].definition.requests[0].query.data_source" is equal to "event_stream"
And the response "widgets[0].definition.requests[0].query.event_size" is equal to "l"
And the response "widgets[0].definition.requests[0].query.sort.column" is equal to "timestamp"
And the response "widgets[0].definition.requests[0].query.sort.order" is equal to "desc"

@team:DataDog/dashboards-backend
Scenario: Create a new dashboard with log_stream widget
Given new "CreateDashboard" request
Expand Down

0 comments on commit 5cd5960

Please sign in to comment.