Skip to content

Commit

Permalink
Add tags field to dashboard API spec (#1907)
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 Mar 27, 2023
1 parent dc40827 commit cc32fd4
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 7 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-03-24 16:41:52.513181",
"spec_repo_commit": "9bdb5ee6"
"regenerated": "2023-03-27 19:48:14.533432",
"spec_repo_commit": "b6741167"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2023-03-24 16:41:52.525844",
"spec_repo_commit": "9bdb5ee6"
"regenerated": "2023-03-27 19:48:14.545514",
"spec_repo_commit": "b6741167"
}
}
}
8 changes: 8 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,14 @@ components:
description: A role UUID.
type: string
type: array
tags:
description: List of team names representing ownership of a dashboard.
items:
description: The name of a Datadog team of the form `team:<name>`
type: string
maxItems: 5
nullable: true
type: array
template_variable_presets:
description: Array of template variables saved views.
items:
Expand Down
36 changes: 36 additions & 0 deletions api/datadogV1/model_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type Dashboard struct {
ReflowType *DashboardReflowType `json:"reflow_type,omitempty"`
// A list of role identifiers. Only the author and users associated with at least one of these roles can edit this dashboard.
RestrictedRoles []string `json:"restricted_roles,omitempty"`
// List of team names representing ownership of a dashboard.
Tags []string `json:"tags,omitempty"`
// Array of template variables saved views.
TemplateVariablePresets []DashboardTemplateVariablePreset `json:"template_variable_presets,omitempty"`
// List of template variables for this dashboard.
Expand Down Expand Up @@ -408,6 +410,35 @@ func (o *Dashboard) SetRestrictedRoles(v []string) {
o.RestrictedRoles = v
}

// GetTags returns the Tags field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *Dashboard) GetTags() []string {
if o == nil {
var ret []string
return ret
}
return o.Tags
}

// GetTagsOk returns a tuple with the Tags field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned.
func (o *Dashboard) GetTagsOk() (*[]string, bool) {
if o == nil || o.Tags == nil {
return nil, false
}
return &o.Tags, true
}

// HasTags returns a boolean if a field has been set.
func (o *Dashboard) HasTags() bool {
return o != nil && o.Tags != nil
}

// SetTags gets a reference to the given []string and assigns it to the Tags field.
func (o *Dashboard) SetTags(v []string) {
o.Tags = v
}

// GetTemplateVariablePresets returns the TemplateVariablePresets field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *Dashboard) GetTemplateVariablePresets() []DashboardTemplateVariablePreset {
if o == nil {
Expand Down Expand Up @@ -585,6 +616,9 @@ func (o Dashboard) MarshalJSON() ([]byte, error) {
if o.RestrictedRoles != nil {
toSerialize["restricted_roles"] = o.RestrictedRoles
}
if o.Tags != nil {
toSerialize["tags"] = o.Tags
}
if o.TemplateVariablePresets != nil {
toSerialize["template_variable_presets"] = o.TemplateVariablePresets
}
Expand Down Expand Up @@ -623,6 +657,7 @@ func (o *Dashboard) UnmarshalJSON(bytes []byte) (err error) {
NotifyList []string `json:"notify_list,omitempty"`
ReflowType *DashboardReflowType `json:"reflow_type,omitempty"`
RestrictedRoles []string `json:"restricted_roles,omitempty"`
Tags []string `json:"tags,omitempty"`
TemplateVariablePresets []DashboardTemplateVariablePreset `json:"template_variable_presets,omitempty"`
TemplateVariables []DashboardTemplateVariable `json:"template_variables,omitempty"`
Title string `json:"title"`
Expand Down Expand Up @@ -678,6 +713,7 @@ func (o *Dashboard) UnmarshalJSON(bytes []byte) (err error) {
o.NotifyList = all.NotifyList
o.ReflowType = all.ReflowType
o.RestrictedRoles = all.RestrictedRoles
o.Tags = all.Tags
o.TemplateVariablePresets = all.TemplateVariablePresets
o.TemplateVariables = all.TemplateVariables
o.Title = all.Title
Expand Down
89 changes: 89 additions & 0 deletions examples/v1/dashboards/CreateDashboard_2064651578.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Create a new dashboard with team tags returns "OK" response

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{
Title: "Example-Create_a_new_dashboard_with_team_tags_returns_OK_response",
Widgets: []datadogV1.Widget{
{
Definition: datadogV1.WidgetDefinition{
ChangeWidgetDefinition: &datadogV1.ChangeWidgetDefinition{
Title: datadog.PtrString(""),
TitleSize: datadog.PtrString("16"),
TitleAlign: datadogV1.WIDGETTEXTALIGN_LEFT.Ptr(),
Time: &datadogV1.WidgetTime{},
Type: datadogV1.CHANGEWIDGETDEFINITIONTYPE_CHANGE,
Requests: []datadogV1.ChangeWidgetRequest{
{
Formulas: []datadogV1.WidgetFormula{
{
Formula: "hour_before(query1)",
},
{
Formula: "query1",
},
},
Queries: []datadogV1.FormulaAndFunctionQueryDefinition{
datadogV1.FormulaAndFunctionQueryDefinition{
FormulaAndFunctionEventQueryDefinition: &datadogV1.FormulaAndFunctionEventQueryDefinition{
DataSource: datadogV1.FORMULAANDFUNCTIONEVENTSDATASOURCE_LOGS,
Name: "query1",
Search: &datadogV1.FormulaAndFunctionEventQueryDefinitionSearch{
Query: "",
},
Indexes: []string{
"*",
},
Compute: datadogV1.FormulaAndFunctionEventQueryDefinitionCompute{
Aggregation: datadogV1.FORMULAANDFUNCTIONEVENTAGGREGATION_COUNT,
},
GroupBy: []datadogV1.FormulaAndFunctionEventQueryGroupBy{},
}},
},
ResponseFormat: datadogV1.FORMULAANDFUNCTIONRESPONSEFORMAT_SCALAR.Ptr(),
CompareTo: datadogV1.WIDGETCOMPARETO_HOUR_BEFORE.Ptr(),
IncreaseGood: datadog.PtrBool(true),
OrderBy: datadogV1.WIDGETORDERBY_CHANGE.Ptr(),
ChangeType: datadogV1.WIDGETCHANGETYPE_ABSOLUTE.Ptr(),
OrderDir: datadogV1.WIDGETSORT_DESCENDING.Ptr(),
},
},
}},
Layout: &datadogV1.WidgetLayout{
X: 0,
Y: 0,
Width: 4,
Height: 4,
},
},
},
Tags: []string{
"team:foobar",
},
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
}
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)
}
64 changes: 64 additions & 0 deletions examples/v1/dashboards/UpdateDashboard_3454865944.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Update a dashboard with tags returns "OK" response

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() {
// there is a valid "dashboard" in the system
DashboardID := os.Getenv("DASHBOARD_ID")

body := datadogV1.Dashboard{
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
Title: "Example-Update_a_dashboard_with_tags_returns_OK_response with list_stream widget",
Description: *datadog.NewNullableString(datadog.PtrString("Updated description")),
Tags: []string{
"team:foo",
"team:bar",
},
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_APM_ISSUE_STREAM,
QueryString: "",
},
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.UpdateDashboard(ctx, DashboardID, body)

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

responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.UpdateDashboard`:\n%s\n", responseContent)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-03-08T22:44:59.472Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
interactions:
- request:
body: |
{"layout_type":"ordered","tags":["tm:foobar"],"title":"Test-Create_a_new_dashboard_with_invalid_team_tags_returns_Bad_Request_response-1678315499","widgets":[{"definition":{"requests":[{"change_type":"absolute","compare_to":"hour_before","formulas":[{"formula":"hour_before(query1)"},{"formula":"query1"}],"increase_good":true,"order_by":"change","order_dir":"desc","queries":[{"compute":{"aggregation":"count"},"data_source":"logs","group_by":[],"indexes":["*"],"name":"query1","search":{"query":""}}],"response_format":"scalar"}],"time":{},"title":"","title_align":"left","title_size":"16","type":"change"},"layout":{"height":4,"width":4,"x":0,"y":0}}]}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: POST
url: https://api.datadoghq.com/api/v1/dashboard
response:
body: '{"errors":["Invalid tag format. Tag key must be `team`."]}'
code: 400
duration: ''
headers:
Content-Type:
- application/json
status: 400 Bad Request
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-03-08T20:53:52.326Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
interactions:
- request:
body: |
{"layout_type":"ordered","tags":["team:foobar"],"title":"Test-Create_a_new_dashboard_with_team_tags_returns_OK_response-1678308832","widgets":[{"definition":{"requests":[{"change_type":"absolute","compare_to":"hour_before","formulas":[{"formula":"hour_before(query1)"},{"formula":"query1"}],"increase_good":true,"order_by":"change","order_dir":"desc","queries":[{"compute":{"aggregation":"count"},"data_source":"logs","group_by":[],"indexes":["*"],"name":"query1","search":{"query":""}}],"response_format":"scalar"}],"time":{},"title":"","title_align":"left","title_size":"16","type":"change"},"layout":{"height":4,"width":4,"x":0,"y":0}}]}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: POST
url: https://api.datadoghq.com/api/v1/dashboard
response:
body: '{"id":"cvx-m2c-ntf","title":"Test-Create_a_new_dashboard_with_team_tags_returns_OK_response-1678308832","description":null,"author_handle":"frog@datadoghq.com","author_name":null,"layout_type":"ordered","url":"/dashboard/cvx-m2c-ntf/test-createanewdashboardwithteamtagsreturnsokresponse-1678308832","is_read_only":false,"template_variables":null,"widgets":[{"definition":{"requests":[{"change_type":"absolute","compare_to":"hour_before","formulas":[{"formula":"hour_before(query1)"},{"formula":"query1"}],"increase_good":true,"order_by":"change","order_dir":"desc","queries":[{"compute":{"aggregation":"count"},"data_source":"logs","group_by":[],"indexes":["*"],"name":"query1","search":{"query":""}}],"response_format":"scalar"}],"time":{},"title":"","title_align":"left","title_size":"16","type":"change"},"layout":{"height":4,"width":4,"x":0,"y":0},"id":3494387223047491}],"notify_list":null,"created_at":"2023-03-08T20:53:52.690739+00:00","modified_at":"2023-03-08T20:53:52.690739+00:00","tags":["team:foobar"],"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/cvx-m2c-ntf
response:
body: '{"deleted_dashboard_id":"cvx-m2c-ntf"}

'
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-03-10T23:23:35.716Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
interactions:
- request:
body: |
{"layout_type":"ordered","title":"Test-Update_a_dashboard_with_tags_returns_OK_response-1678490615 with Profile Metrics Query","widgets":[{"definition":{"requests":[{"profile_metrics_query":{"compute":{"aggregation":"sum","facet":"@prof_core_cpu_cores"},"group_by":[{"facet":"service","limit":10,"sort":{"aggregation":"sum","facet":"@prof_core_cpu_cores","order":"desc"}}],"search":{"query":"runtime:jvm"}}}],"type":"timeseries"}}]}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: POST
url: https://api.datadoghq.com/api/v1/dashboard
response:
body: '{"id":"ad2-8ch-y8s","title":"Test-Update_a_dashboard_with_tags_returns_OK_response-1678490615
with Profile Metrics Query","description":null,"author_handle":"frog@datadoghq.com","author_name":null,"layout_type":"ordered","url":"/dashboard/ad2-8ch-y8s/test-updateadashboardwithtagsreturnsokresponse-1678490615-with-profile-metrics-q","is_read_only":false,"template_variables":null,"widgets":[{"definition":{"requests":[{"profile_metrics_query":{"compute":{"aggregation":"sum","facet":"@prof_core_cpu_cores"},"group_by":[{"facet":"service","limit":10,"sort":{"aggregation":"sum","facet":"@prof_core_cpu_cores","order":"desc"}}],"search":{"query":"runtime:jvm"}}}],"type":"timeseries"},"id":6897153580739865}],"notify_list":null,"created_at":"2023-03-10T23:23:35.908079+00:00","modified_at":"2023-03-10T23:23:35.908079+00:00","tags":[],"restricted_roles":[]}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
- request:
body: |
{"description":"Updated description","layout_type":"ordered","tags":["team:foo","team:bar"],"title":"Test-Update_a_dashboard_with_tags_returns_OK_response-1678490615 with list_stream widget","widgets":[{"definition":{"requests":[{"columns":[{"field":"timestamp","width":"auto"}],"query":{"data_source":"apm_issue_stream","query_string":""},"response_format":"event_list"}],"type":"list_stream"}}]}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: PUT
url: https://api.datadoghq.com/api/v1/dashboard/ad2-8ch-y8s
response:
body: '{"id":"ad2-8ch-y8s","title":"Test-Update_a_dashboard_with_tags_returns_OK_response-1678490615
with list_stream widget","description":"Updated description","author_handle":"frog@datadoghq.com","author_name":null,"layout_type":"ordered","url":"/dashboard/ad2-8ch-y8s/test-updateadashboardwithtagsreturnsokresponse-1678490615-with-liststream-widget","is_read_only":false,"template_variables":null,"widgets":[{"definition":{"requests":[{"columns":[{"field":"timestamp","width":"auto"}],"query":{"data_source":"apm_issue_stream","query_string":""},"response_format":"event_list"}],"type":"list_stream"},"id":4545330920817753}],"notify_list":null,"created_at":"2023-03-10T23:23:35.908079+00:00","modified_at":"2023-03-10T23:23:36.124521+00:00","tags":["team:foo","team:bar"],"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/ad2-8ch-y8s
response:
body: '{"deleted_dashboard_id":"ad2-8ch-y8s"}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
version: 1
Loading

0 comments on commit cc32fd4

Please sign in to comment.