Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for template variable multiselect in dashboards #1668

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "2022-09-16 08:46:36.930376",
"spec_repo_commit": "f1faacea"
"regenerated": "2022-09-16 13:42:49.599994",
"spec_repo_commit": "acc0b78b"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2022-09-16 08:46:36.947672",
"spec_repo_commit": "f1faacea"
"regenerated": "2022-09-16 13:42:49.615641",
"spec_repo_commit": "acc0b78b"
}
}
}
32 changes: 30 additions & 2 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1250,10 +1250,25 @@ components:
nullable: true
type: array
default:
description: The default value for the template variable on dashboard load.
deprecated: true
description: (deprecated) The default value for the template variable on
dashboard load. Cannot be used in conjunction with `defaults`.
example: my-host
nullable: true
type: string
defaults:
description: One or many default values for template variables on load.
If more than one default is specified, they will be unioned together with
`OR`. Cannot be used in conjunction with `default`.
example:
- my-host-1
- my-host-2
items:
description: One of many default values for the template variable on dashboard
load.
minLength: 1
type: string
type: array
name:
description: The name of the variable.
example: host1
Expand Down Expand Up @@ -1286,8 +1301,21 @@ components:
description: The name of the variable.
type: string
value:
description: The value of the template variable within the saved view.
deprecated: true
description: (deprecated) The value of the template variable within the
saved view. Cannot be used in conjunction with `values`.
type: string
values:
description: One or many template variable values within the saved view,
which will be unioned together using `OR` if more than one is specified.
Cannot be used in conjunction with `value`.
items:
description: One or many values of the template variable within the saved
view.
minLength: 1
type: string
minItems: 1
type: array
type: object
DeletedMonitor:
description: Response from the delete monitor call.
Expand Down
45 changes: 44 additions & 1 deletion api/datadogV1/model_dashboard_template_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import (
type DashboardTemplateVariable struct {
// The list of values that the template variable drop-down is limited to.
AvailableValues []string `json:"available_values,omitempty"`
// The default value for the template variable on dashboard load.
// (deprecated) The default value for the template variable on dashboard load. Cannot be used in conjunction with `defaults`.
// Deprecated
Default datadog.NullableString `json:"default,omitempty"`
// One or many default values for template variables on load. If more than one default is specified, they will be unioned together with `OR`. Cannot be used in conjunction with `default`.
Defaults []string `json:"defaults,omitempty"`
// The name of the variable.
Name string `json:"name"`
// The tag prefix associated with the variable. Only tags with this prefix appear in the variable drop-down.
Expand Down Expand Up @@ -78,6 +81,7 @@ func (o *DashboardTemplateVariable) SetAvailableValues(v []string) {
}

// GetDefault returns the Default field value if set, zero value otherwise (both if not set or set to explicit null).
// Deprecated
func (o *DashboardTemplateVariable) GetDefault() string {
if o == nil || o.Default.Get() == nil {
var ret string
Expand All @@ -89,6 +93,7 @@ func (o *DashboardTemplateVariable) GetDefault() string {
// GetDefaultOk returns a tuple with the Default 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.
// Deprecated
func (o *DashboardTemplateVariable) GetDefaultOk() (*string, bool) {
if o == nil {
return nil, false
Expand All @@ -106,6 +111,7 @@ func (o *DashboardTemplateVariable) HasDefault() bool {
}

// SetDefault gets a reference to the given datadog.NullableString and assigns it to the Default field.
// Deprecated
func (o *DashboardTemplateVariable) SetDefault(v string) {
o.Default.Set(&v)
}
Expand All @@ -120,6 +126,38 @@ func (o *DashboardTemplateVariable) UnsetDefault() {
o.Default.Unset()
}

// GetDefaults returns the Defaults field value if set, zero value otherwise.
func (o *DashboardTemplateVariable) GetDefaults() []string {
if o == nil || o.Defaults == nil {
var ret []string
return ret
}
return o.Defaults
}

// GetDefaultsOk returns a tuple with the Defaults field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *DashboardTemplateVariable) GetDefaultsOk() (*[]string, bool) {
if o == nil || o.Defaults == nil {
return nil, false
}
return &o.Defaults, true
}

// HasDefaults returns a boolean if a field has been set.
func (o *DashboardTemplateVariable) HasDefaults() bool {
if o != nil && o.Defaults != nil {
return true
}

return false
}

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

// GetName returns the Name field value.
func (o *DashboardTemplateVariable) GetName() string {
if o == nil {
Expand Down Expand Up @@ -198,6 +236,9 @@ func (o DashboardTemplateVariable) MarshalJSON() ([]byte, error) {
if o.Default.IsSet() {
toSerialize["default"] = o.Default.Get()
}
if o.Defaults != nil {
toSerialize["defaults"] = o.Defaults
}
toSerialize["name"] = o.Name
if o.Prefix.IsSet() {
toSerialize["prefix"] = o.Prefix.Get()
Expand All @@ -218,6 +259,7 @@ func (o *DashboardTemplateVariable) UnmarshalJSON(bytes []byte) (err error) {
all := struct {
AvailableValues []string `json:"available_values,omitempty"`
Default datadog.NullableString `json:"default,omitempty"`
Defaults []string `json:"defaults,omitempty"`
Name string `json:"name"`
Prefix datadog.NullableString `json:"prefix,omitempty"`
}{}
Expand All @@ -239,6 +281,7 @@ func (o *DashboardTemplateVariable) UnmarshalJSON(bytes []byte) (err error) {
}
o.AvailableValues = all.AvailableValues
o.Default = all.Default
o.Defaults = all.Defaults
o.Name = all.Name
o.Prefix = all.Prefix
return nil
Expand Down
49 changes: 46 additions & 3 deletions api/datadogV1/model_dashboard_template_variable_preset_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
type DashboardTemplateVariablePresetValue struct {
// The name of the variable.
Name *string `json:"name,omitempty"`
// The value of the template variable within the saved view.
// (deprecated) The value of the template variable within the saved view. Cannot be used in conjunction with `values`.
// Deprecated
Value *string `json:"value,omitempty"`
// One or many template variable values within the saved view, which will be unioned together using `OR` if more than one is specified. Cannot be used in conjunction with `value`.
Values []string `json:"values,omitempty"`
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject map[string]interface{} `json:-`
AdditionalProperties map[string]interface{}
Expand Down Expand Up @@ -69,6 +72,7 @@ func (o *DashboardTemplateVariablePresetValue) SetName(v string) {
}

// GetValue returns the Value field value if set, zero value otherwise.
// Deprecated
func (o *DashboardTemplateVariablePresetValue) GetValue() string {
if o == nil || o.Value == nil {
var ret string
Expand All @@ -79,6 +83,7 @@ func (o *DashboardTemplateVariablePresetValue) GetValue() string {

// GetValueOk returns a tuple with the Value field value if set, nil otherwise
// and a boolean to check if the value has been set.
// Deprecated
func (o *DashboardTemplateVariablePresetValue) GetValueOk() (*string, bool) {
if o == nil || o.Value == nil {
return nil, false
Expand All @@ -96,10 +101,43 @@ func (o *DashboardTemplateVariablePresetValue) HasValue() bool {
}

// SetValue gets a reference to the given string and assigns it to the Value field.
// Deprecated
func (o *DashboardTemplateVariablePresetValue) SetValue(v string) {
o.Value = &v
}

// GetValues returns the Values field value if set, zero value otherwise.
func (o *DashboardTemplateVariablePresetValue) GetValues() []string {
if o == nil || o.Values == nil {
var ret []string
return ret
}
return o.Values
}

// GetValuesOk returns a tuple with the Values field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *DashboardTemplateVariablePresetValue) GetValuesOk() (*[]string, bool) {
if o == nil || o.Values == nil {
return nil, false
}
return &o.Values, true
}

// HasValues returns a boolean if a field has been set.
func (o *DashboardTemplateVariablePresetValue) HasValues() bool {
if o != nil && o.Values != nil {
return true
}

return false
}

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

// MarshalJSON serializes the struct using spec logic.
func (o DashboardTemplateVariablePresetValue) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
Expand All @@ -112,6 +150,9 @@ func (o DashboardTemplateVariablePresetValue) MarshalJSON() ([]byte, error) {
if o.Value != nil {
toSerialize["value"] = o.Value
}
if o.Values != nil {
toSerialize["values"] = o.Values
}

for key, value := range o.AdditionalProperties {
toSerialize[key] = value
Expand All @@ -123,8 +164,9 @@ func (o DashboardTemplateVariablePresetValue) MarshalJSON() ([]byte, error) {
func (o *DashboardTemplateVariablePresetValue) UnmarshalJSON(bytes []byte) (err error) {
raw := map[string]interface{}{}
all := struct {
Name *string `json:"name,omitempty"`
Value *string `json:"value,omitempty"`
Name *string `json:"name,omitempty"`
Value *string `json:"value,omitempty"`
Values []string `json:"values,omitempty"`
}{}
err = json.Unmarshal(bytes, &all)
if err != nil {
Expand All @@ -137,5 +179,6 @@ func (o *DashboardTemplateVariablePresetValue) UnmarshalJSON(bytes []byte) (err
}
o.Name = all.Name
o.Value = all.Value
o.Values = all.Values
return nil
}
79 changes: 79 additions & 0 deletions examples/v1/dashboards/CreateDashboard_2850365602.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Create a new dashboard with template variable presets using values 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{
Description: *datadog.NewNullableString(nil),
IsReadOnly: datadog.PtrBool(false),
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
NotifyList: []string{},
ReflowType: datadogV1.DASHBOARDREFLOWTYPE_AUTO.Ptr(),
RestrictedRoles: []string{},
TemplateVariablePresets: []datadogV1.DashboardTemplateVariablePreset{
{
Name: datadog.PtrString("my saved view"),
TemplateVariables: []datadogV1.DashboardTemplateVariablePresetValue{
{
Name: datadog.PtrString("datacenter"),
Values: []string{
"*",
"my-host",
},
},
},
},
},
TemplateVariables: []datadogV1.DashboardTemplateVariable{
{
AvailableValues: []string{
"my-host",
"host1",
"host2",
},
Defaults: []string{
"my-host",
},
Name: "host1",
Prefix: *datadog.NewNullableString(datadog.PtrString("host")),
},
},
Title: "",
Widgets: []datadogV1.Widget{
{
Definition: datadogV1.WidgetDefinition{
HostMapWidgetDefinition: &datadogV1.HostMapWidgetDefinition{
Requests: datadogV1.HostMapWidgetDefinitionRequests{
Fill: &datadogV1.HostMapRequest{
Q: datadog.PtrString("avg:system.cpu.user{*}"),
},
},
Type: datadogV1.HOSTMAPWIDGETDEFINITIONTYPE_HOSTMAP,
}},
},
},
}
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)
}
Loading