diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index b41f414fd36..05258906e67 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -1530,6 +1530,72 @@ components: - layout_type - widgets type: object + DashboardAvailableValuesEventsDataSource: + description: The events-based data source for the query. + enum: + - spans + - logs + - rum + example: spans + type: string + x-enum-varnames: + - SPANS + - LOGS + - RUM + DashboardAvailableValuesEventsQuery: + additionalProperties: false + description: Query for available values using an events-based data source (spans, logs, or rum). + properties: + data_source: + $ref: "#/components/schemas/DashboardAvailableValuesEventsDataSource" + group_by: + description: The fields to group by in the query. + items: + $ref: "#/components/schemas/DashboardAvailableValuesEventsQueryGroupByItems" + type: array + search: + $ref: "#/components/schemas/DashboardAvailableValuesEventsQuerySearch" + required: + - data_source + - search + - group_by + type: object + DashboardAvailableValuesEventsQueryGroupByItems: + additionalProperties: false + description: A field to group by in the available values query. + properties: + facet: + description: The facet to group by. + example: "" + type: string + required: + - facet + type: object + DashboardAvailableValuesEventsQuerySearch: + additionalProperties: false + description: The search filter for the query. + properties: + query: + description: The search query string. + example: "" + type: string + required: + - query + type: object + DashboardAvailableValuesMetricsQuery: + additionalProperties: false + description: Query for available values using the metrics data source. + properties: + data_source: + $ref: "#/components/schemas/FormulaAndFunctionMetricDataSource" + query: + description: The metrics query string. + example: "" + type: string + required: + - data_source + - query + type: object DashboardBulkActionData: description: Dashboard bulk action request data. example: {"id": "123-abc-456", "type": "dashboard"} @@ -1800,6 +1866,13 @@ components: type: string nullable: true type: array + available_values_query: + $ref: "#/components/schemas/DashboardTemplateVariableAvailableValuesQuery" + data_source_mappings: + additionalProperties: + type: string + description: A mapping from data source type to the variable value to use for that data source. + type: object default: deprecated: true description: (deprecated) The default value for the template variable on dashboard load. Cannot be used in conjunction with `defaults`. @@ -1831,6 +1904,11 @@ components: required: - name type: object + DashboardTemplateVariableAvailableValuesQuery: + description: A query that dynamically computes the list of values available for this template variable. + oneOf: + - $ref: "#/components/schemas/DashboardAvailableValuesEventsQuery" + - $ref: "#/components/schemas/DashboardAvailableValuesMetricsQuery" DashboardTemplateVariablePreset: description: Template variables saved views. properties: diff --git a/api/datadogV1/model_dashboard_available_values_events_data_source.go b/api/datadogV1/model_dashboard_available_values_events_data_source.go new file mode 100644 index 00000000000..fbaa75d5ef5 --- /dev/null +++ b/api/datadogV1/model_dashboard_available_values_events_data_source.go @@ -0,0 +1,68 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardAvailableValuesEventsDataSource The events-based data source for the query. +type DashboardAvailableValuesEventsDataSource string + +// List of DashboardAvailableValuesEventsDataSource. +const ( + DASHBOARDAVAILABLEVALUESEVENTSDATASOURCE_SPANS DashboardAvailableValuesEventsDataSource = "spans" + DASHBOARDAVAILABLEVALUESEVENTSDATASOURCE_LOGS DashboardAvailableValuesEventsDataSource = "logs" + DASHBOARDAVAILABLEVALUESEVENTSDATASOURCE_RUM DashboardAvailableValuesEventsDataSource = "rum" +) + +var allowedDashboardAvailableValuesEventsDataSourceEnumValues = []DashboardAvailableValuesEventsDataSource{ + DASHBOARDAVAILABLEVALUESEVENTSDATASOURCE_SPANS, + DASHBOARDAVAILABLEVALUESEVENTSDATASOURCE_LOGS, + DASHBOARDAVAILABLEVALUESEVENTSDATASOURCE_RUM, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *DashboardAvailableValuesEventsDataSource) GetAllowedValues() []DashboardAvailableValuesEventsDataSource { + return allowedDashboardAvailableValuesEventsDataSourceEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *DashboardAvailableValuesEventsDataSource) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = DashboardAvailableValuesEventsDataSource(value) + return nil +} + +// NewDashboardAvailableValuesEventsDataSourceFromValue returns a pointer to a valid DashboardAvailableValuesEventsDataSource +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewDashboardAvailableValuesEventsDataSourceFromValue(v string) (*DashboardAvailableValuesEventsDataSource, error) { + ev := DashboardAvailableValuesEventsDataSource(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for DashboardAvailableValuesEventsDataSource: valid values are %v", v, allowedDashboardAvailableValuesEventsDataSourceEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v DashboardAvailableValuesEventsDataSource) IsValid() bool { + for _, existing := range allowedDashboardAvailableValuesEventsDataSourceEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to DashboardAvailableValuesEventsDataSource value. +func (v DashboardAvailableValuesEventsDataSource) Ptr() *DashboardAvailableValuesEventsDataSource { + return &v +} diff --git a/api/datadogV1/model_dashboard_available_values_events_query.go b/api/datadogV1/model_dashboard_available_values_events_query.go new file mode 100644 index 00000000000..d4fc77ba8b1 --- /dev/null +++ b/api/datadogV1/model_dashboard_available_values_events_query.go @@ -0,0 +1,163 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardAvailableValuesEventsQuery Query for available values using an events-based data source (spans, logs, or rum). +type DashboardAvailableValuesEventsQuery struct { + // The events-based data source for the query. + DataSource DashboardAvailableValuesEventsDataSource `json:"data_source"` + // The fields to group by in the query. + GroupBy []DashboardAvailableValuesEventsQueryGroupByItems `json:"group_by"` + // The search filter for the query. + Search DashboardAvailableValuesEventsQuerySearch `json:"search"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` +} + +// NewDashboardAvailableValuesEventsQuery instantiates a new DashboardAvailableValuesEventsQuery object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewDashboardAvailableValuesEventsQuery(dataSource DashboardAvailableValuesEventsDataSource, groupBy []DashboardAvailableValuesEventsQueryGroupByItems, search DashboardAvailableValuesEventsQuerySearch) *DashboardAvailableValuesEventsQuery { + this := DashboardAvailableValuesEventsQuery{} + this.DataSource = dataSource + this.GroupBy = groupBy + this.Search = search + return &this +} + +// NewDashboardAvailableValuesEventsQueryWithDefaults instantiates a new DashboardAvailableValuesEventsQuery object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewDashboardAvailableValuesEventsQueryWithDefaults() *DashboardAvailableValuesEventsQuery { + this := DashboardAvailableValuesEventsQuery{} + return &this +} + +// GetDataSource returns the DataSource field value. +func (o *DashboardAvailableValuesEventsQuery) GetDataSource() DashboardAvailableValuesEventsDataSource { + if o == nil { + var ret DashboardAvailableValuesEventsDataSource + return ret + } + return o.DataSource +} + +// GetDataSourceOk returns a tuple with the DataSource field value +// and a boolean to check if the value has been set. +func (o *DashboardAvailableValuesEventsQuery) GetDataSourceOk() (*DashboardAvailableValuesEventsDataSource, bool) { + if o == nil { + return nil, false + } + return &o.DataSource, true +} + +// SetDataSource sets field value. +func (o *DashboardAvailableValuesEventsQuery) SetDataSource(v DashboardAvailableValuesEventsDataSource) { + o.DataSource = v +} + +// GetGroupBy returns the GroupBy field value. +func (o *DashboardAvailableValuesEventsQuery) GetGroupBy() []DashboardAvailableValuesEventsQueryGroupByItems { + if o == nil { + var ret []DashboardAvailableValuesEventsQueryGroupByItems + return ret + } + return o.GroupBy +} + +// GetGroupByOk returns a tuple with the GroupBy field value +// and a boolean to check if the value has been set. +func (o *DashboardAvailableValuesEventsQuery) GetGroupByOk() (*[]DashboardAvailableValuesEventsQueryGroupByItems, bool) { + if o == nil { + return nil, false + } + return &o.GroupBy, true +} + +// SetGroupBy sets field value. +func (o *DashboardAvailableValuesEventsQuery) SetGroupBy(v []DashboardAvailableValuesEventsQueryGroupByItems) { + o.GroupBy = v +} + +// GetSearch returns the Search field value. +func (o *DashboardAvailableValuesEventsQuery) GetSearch() DashboardAvailableValuesEventsQuerySearch { + if o == nil { + var ret DashboardAvailableValuesEventsQuerySearch + return ret + } + return o.Search +} + +// GetSearchOk returns a tuple with the Search field value +// and a boolean to check if the value has been set. +func (o *DashboardAvailableValuesEventsQuery) GetSearchOk() (*DashboardAvailableValuesEventsQuerySearch, bool) { + if o == nil { + return nil, false + } + return &o.Search, true +} + +// SetSearch sets field value. +func (o *DashboardAvailableValuesEventsQuery) SetSearch(v DashboardAvailableValuesEventsQuerySearch) { + o.Search = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o DashboardAvailableValuesEventsQuery) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["data_source"] = o.DataSource + toSerialize["group_by"] = o.GroupBy + toSerialize["search"] = o.Search + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *DashboardAvailableValuesEventsQuery) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + DataSource *DashboardAvailableValuesEventsDataSource `json:"data_source"` + GroupBy *[]DashboardAvailableValuesEventsQueryGroupByItems `json:"group_by"` + Search *DashboardAvailableValuesEventsQuerySearch `json:"search"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.DataSource == nil { + return fmt.Errorf("required field data_source missing") + } + if all.GroupBy == nil { + return fmt.Errorf("required field group_by missing") + } + if all.Search == nil { + return fmt.Errorf("required field search missing") + } + + hasInvalidField := false + if !all.DataSource.IsValid() { + hasInvalidField = true + } else { + o.DataSource = *all.DataSource + } + o.GroupBy = *all.GroupBy + if all.Search.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Search = *all.Search + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_dashboard_available_values_events_query_group_by_items.go b/api/datadogV1/model_dashboard_available_values_events_query_group_by_items.go new file mode 100644 index 00000000000..efa989eee99 --- /dev/null +++ b/api/datadogV1/model_dashboard_available_values_events_query_group_by_items.go @@ -0,0 +1,86 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardAvailableValuesEventsQueryGroupByItems A field to group by in the available values query. +type DashboardAvailableValuesEventsQueryGroupByItems struct { + // The facet to group by. + Facet string `json:"facet"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` +} + +// NewDashboardAvailableValuesEventsQueryGroupByItems instantiates a new DashboardAvailableValuesEventsQueryGroupByItems object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewDashboardAvailableValuesEventsQueryGroupByItems(facet string) *DashboardAvailableValuesEventsQueryGroupByItems { + this := DashboardAvailableValuesEventsQueryGroupByItems{} + this.Facet = facet + return &this +} + +// NewDashboardAvailableValuesEventsQueryGroupByItemsWithDefaults instantiates a new DashboardAvailableValuesEventsQueryGroupByItems object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewDashboardAvailableValuesEventsQueryGroupByItemsWithDefaults() *DashboardAvailableValuesEventsQueryGroupByItems { + this := DashboardAvailableValuesEventsQueryGroupByItems{} + return &this +} + +// GetFacet returns the Facet field value. +func (o *DashboardAvailableValuesEventsQueryGroupByItems) GetFacet() string { + if o == nil { + var ret string + return ret + } + return o.Facet +} + +// GetFacetOk returns a tuple with the Facet field value +// and a boolean to check if the value has been set. +func (o *DashboardAvailableValuesEventsQueryGroupByItems) GetFacetOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Facet, true +} + +// SetFacet sets field value. +func (o *DashboardAvailableValuesEventsQueryGroupByItems) SetFacet(v string) { + o.Facet = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o DashboardAvailableValuesEventsQueryGroupByItems) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["facet"] = o.Facet + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *DashboardAvailableValuesEventsQueryGroupByItems) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Facet *string `json:"facet"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Facet == nil { + return fmt.Errorf("required field facet missing") + } + o.Facet = *all.Facet + + return nil +} diff --git a/api/datadogV1/model_dashboard_available_values_events_query_search.go b/api/datadogV1/model_dashboard_available_values_events_query_search.go new file mode 100644 index 00000000000..a00b198cbef --- /dev/null +++ b/api/datadogV1/model_dashboard_available_values_events_query_search.go @@ -0,0 +1,86 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardAvailableValuesEventsQuerySearch The search filter for the query. +type DashboardAvailableValuesEventsQuerySearch struct { + // The search query string. + Query string `json:"query"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` +} + +// NewDashboardAvailableValuesEventsQuerySearch instantiates a new DashboardAvailableValuesEventsQuerySearch object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewDashboardAvailableValuesEventsQuerySearch(query string) *DashboardAvailableValuesEventsQuerySearch { + this := DashboardAvailableValuesEventsQuerySearch{} + this.Query = query + return &this +} + +// NewDashboardAvailableValuesEventsQuerySearchWithDefaults instantiates a new DashboardAvailableValuesEventsQuerySearch object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewDashboardAvailableValuesEventsQuerySearchWithDefaults() *DashboardAvailableValuesEventsQuerySearch { + this := DashboardAvailableValuesEventsQuerySearch{} + return &this +} + +// GetQuery returns the Query field value. +func (o *DashboardAvailableValuesEventsQuerySearch) GetQuery() string { + if o == nil { + var ret string + return ret + } + return o.Query +} + +// GetQueryOk returns a tuple with the Query field value +// and a boolean to check if the value has been set. +func (o *DashboardAvailableValuesEventsQuerySearch) GetQueryOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Query, true +} + +// SetQuery sets field value. +func (o *DashboardAvailableValuesEventsQuerySearch) SetQuery(v string) { + o.Query = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o DashboardAvailableValuesEventsQuerySearch) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["query"] = o.Query + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *DashboardAvailableValuesEventsQuerySearch) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Query *string `json:"query"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Query == nil { + return fmt.Errorf("required field query missing") + } + o.Query = *all.Query + + return nil +} diff --git a/api/datadogV1/model_dashboard_available_values_metrics_query.go b/api/datadogV1/model_dashboard_available_values_metrics_query.go new file mode 100644 index 00000000000..a9f1ae22aff --- /dev/null +++ b/api/datadogV1/model_dashboard_available_values_metrics_query.go @@ -0,0 +1,128 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardAvailableValuesMetricsQuery Query for available values using the metrics data source. +type DashboardAvailableValuesMetricsQuery struct { + // Data source for metrics queries. + DataSource FormulaAndFunctionMetricDataSource `json:"data_source"` + // The metrics query string. + Query string `json:"query"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` +} + +// NewDashboardAvailableValuesMetricsQuery instantiates a new DashboardAvailableValuesMetricsQuery object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewDashboardAvailableValuesMetricsQuery(dataSource FormulaAndFunctionMetricDataSource, query string) *DashboardAvailableValuesMetricsQuery { + this := DashboardAvailableValuesMetricsQuery{} + this.DataSource = dataSource + this.Query = query + return &this +} + +// NewDashboardAvailableValuesMetricsQueryWithDefaults instantiates a new DashboardAvailableValuesMetricsQuery object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewDashboardAvailableValuesMetricsQueryWithDefaults() *DashboardAvailableValuesMetricsQuery { + this := DashboardAvailableValuesMetricsQuery{} + return &this +} + +// GetDataSource returns the DataSource field value. +func (o *DashboardAvailableValuesMetricsQuery) GetDataSource() FormulaAndFunctionMetricDataSource { + if o == nil { + var ret FormulaAndFunctionMetricDataSource + return ret + } + return o.DataSource +} + +// GetDataSourceOk returns a tuple with the DataSource field value +// and a boolean to check if the value has been set. +func (o *DashboardAvailableValuesMetricsQuery) GetDataSourceOk() (*FormulaAndFunctionMetricDataSource, bool) { + if o == nil { + return nil, false + } + return &o.DataSource, true +} + +// SetDataSource sets field value. +func (o *DashboardAvailableValuesMetricsQuery) SetDataSource(v FormulaAndFunctionMetricDataSource) { + o.DataSource = v +} + +// GetQuery returns the Query field value. +func (o *DashboardAvailableValuesMetricsQuery) GetQuery() string { + if o == nil { + var ret string + return ret + } + return o.Query +} + +// GetQueryOk returns a tuple with the Query field value +// and a boolean to check if the value has been set. +func (o *DashboardAvailableValuesMetricsQuery) GetQueryOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Query, true +} + +// SetQuery sets field value. +func (o *DashboardAvailableValuesMetricsQuery) SetQuery(v string) { + o.Query = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o DashboardAvailableValuesMetricsQuery) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["data_source"] = o.DataSource + toSerialize["query"] = o.Query + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *DashboardAvailableValuesMetricsQuery) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + DataSource *FormulaAndFunctionMetricDataSource `json:"data_source"` + Query *string `json:"query"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.DataSource == nil { + return fmt.Errorf("required field data_source missing") + } + if all.Query == nil { + return fmt.Errorf("required field query missing") + } + + hasInvalidField := false + if !all.DataSource.IsValid() { + hasInvalidField = true + } else { + o.DataSource = *all.DataSource + } + o.Query = *all.Query + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_dashboard_template_variable.go b/api/datadogV1/model_dashboard_template_variable.go index cf41bc8b64e..81f6044638d 100644 --- a/api/datadogV1/model_dashboard_template_variable.go +++ b/api/datadogV1/model_dashboard_template_variable.go @@ -14,6 +14,10 @@ import ( type DashboardTemplateVariable struct { // The list of values that the template variable drop-down is limited to. AvailableValues datadog.NullableList[string] `json:"available_values,omitempty"` + // A query that dynamically computes the list of values available for this template variable. + AvailableValuesQuery *DashboardTemplateVariableAvailableValuesQuery `json:"available_values_query,omitempty"` + // A mapping from data source type to the variable value to use for that data source. + DataSourceMappings map[string]string `json:"data_source_mappings,omitempty"` // (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"` @@ -87,6 +91,62 @@ func (o *DashboardTemplateVariable) UnsetAvailableValues() { o.AvailableValues.Unset() } +// GetAvailableValuesQuery returns the AvailableValuesQuery field value if set, zero value otherwise. +func (o *DashboardTemplateVariable) GetAvailableValuesQuery() DashboardTemplateVariableAvailableValuesQuery { + if o == nil || o.AvailableValuesQuery == nil { + var ret DashboardTemplateVariableAvailableValuesQuery + return ret + } + return *o.AvailableValuesQuery +} + +// GetAvailableValuesQueryOk returns a tuple with the AvailableValuesQuery field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DashboardTemplateVariable) GetAvailableValuesQueryOk() (*DashboardTemplateVariableAvailableValuesQuery, bool) { + if o == nil || o.AvailableValuesQuery == nil { + return nil, false + } + return o.AvailableValuesQuery, true +} + +// HasAvailableValuesQuery returns a boolean if a field has been set. +func (o *DashboardTemplateVariable) HasAvailableValuesQuery() bool { + return o != nil && o.AvailableValuesQuery != nil +} + +// SetAvailableValuesQuery gets a reference to the given DashboardTemplateVariableAvailableValuesQuery and assigns it to the AvailableValuesQuery field. +func (o *DashboardTemplateVariable) SetAvailableValuesQuery(v DashboardTemplateVariableAvailableValuesQuery) { + o.AvailableValuesQuery = &v +} + +// GetDataSourceMappings returns the DataSourceMappings field value if set, zero value otherwise. +func (o *DashboardTemplateVariable) GetDataSourceMappings() map[string]string { + if o == nil || o.DataSourceMappings == nil { + var ret map[string]string + return ret + } + return o.DataSourceMappings +} + +// GetDataSourceMappingsOk returns a tuple with the DataSourceMappings field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DashboardTemplateVariable) GetDataSourceMappingsOk() (*map[string]string, bool) { + if o == nil || o.DataSourceMappings == nil { + return nil, false + } + return &o.DataSourceMappings, true +} + +// HasDataSourceMappings returns a boolean if a field has been set. +func (o *DashboardTemplateVariable) HasDataSourceMappings() bool { + return o != nil && o.DataSourceMappings != nil +} + +// SetDataSourceMappings gets a reference to the given map[string]string and assigns it to the DataSourceMappings field. +func (o *DashboardTemplateVariable) SetDataSourceMappings(v map[string]string) { + o.DataSourceMappings = v +} + // 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 { @@ -267,6 +327,12 @@ func (o DashboardTemplateVariable) MarshalJSON() ([]byte, error) { if o.AvailableValues.IsSet() { toSerialize["available_values"] = o.AvailableValues.Get() } + if o.AvailableValuesQuery != nil { + toSerialize["available_values_query"] = o.AvailableValuesQuery + } + if o.DataSourceMappings != nil { + toSerialize["data_source_mappings"] = o.DataSourceMappings + } if o.Default.IsSet() { toSerialize["default"] = o.Default.Get() } @@ -290,12 +356,14 @@ func (o DashboardTemplateVariable) MarshalJSON() ([]byte, error) { // UnmarshalJSON deserializes the given payload. func (o *DashboardTemplateVariable) UnmarshalJSON(bytes []byte) (err error) { all := struct { - AvailableValues datadog.NullableList[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"` - Type datadog.NullableString `json:"type,omitempty"` + AvailableValues datadog.NullableList[string] `json:"available_values,omitempty"` + AvailableValuesQuery *DashboardTemplateVariableAvailableValuesQuery `json:"available_values_query,omitempty"` + DataSourceMappings map[string]string `json:"data_source_mappings,omitempty"` + Default datadog.NullableString `json:"default,omitempty"` + Defaults []string `json:"defaults,omitempty"` + Name *string `json:"name"` + Prefix datadog.NullableString `json:"prefix,omitempty"` + Type datadog.NullableString `json:"type,omitempty"` }{} if err = datadog.Unmarshal(bytes, &all); err != nil { return datadog.Unmarshal(bytes, &o.UnparsedObject) @@ -305,11 +373,13 @@ func (o *DashboardTemplateVariable) UnmarshalJSON(bytes []byte) (err error) { } additionalProperties := make(map[string]interface{}) if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { - datadog.DeleteKeys(additionalProperties, &[]string{"available_values", "default", "defaults", "name", "prefix", "type"}) + datadog.DeleteKeys(additionalProperties, &[]string{"available_values", "available_values_query", "data_source_mappings", "default", "defaults", "name", "prefix", "type"}) } else { return err } o.AvailableValues = all.AvailableValues + o.AvailableValuesQuery = all.AvailableValuesQuery + o.DataSourceMappings = all.DataSourceMappings o.Default = all.Default o.Defaults = all.Defaults o.Name = *all.Name diff --git a/api/datadogV1/model_dashboard_template_variable_available_values_query.go b/api/datadogV1/model_dashboard_template_variable_available_values_query.go new file mode 100644 index 00000000000..0610da1a257 --- /dev/null +++ b/api/datadogV1/model_dashboard_template_variable_available_values_query.go @@ -0,0 +1,105 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV1 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardTemplateVariableAvailableValuesQuery - A query that dynamically computes the list of values available for this template variable. +type DashboardTemplateVariableAvailableValuesQuery struct { + DashboardAvailableValuesEventsQuery *DashboardAvailableValuesEventsQuery + DashboardAvailableValuesMetricsQuery *DashboardAvailableValuesMetricsQuery + + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject interface{} +} + +// DashboardAvailableValuesEventsQueryAsDashboardTemplateVariableAvailableValuesQuery is a convenience function that returns DashboardAvailableValuesEventsQuery wrapped in DashboardTemplateVariableAvailableValuesQuery. +func DashboardAvailableValuesEventsQueryAsDashboardTemplateVariableAvailableValuesQuery(v *DashboardAvailableValuesEventsQuery) DashboardTemplateVariableAvailableValuesQuery { + return DashboardTemplateVariableAvailableValuesQuery{DashboardAvailableValuesEventsQuery: v} +} + +// DashboardAvailableValuesMetricsQueryAsDashboardTemplateVariableAvailableValuesQuery is a convenience function that returns DashboardAvailableValuesMetricsQuery wrapped in DashboardTemplateVariableAvailableValuesQuery. +func DashboardAvailableValuesMetricsQueryAsDashboardTemplateVariableAvailableValuesQuery(v *DashboardAvailableValuesMetricsQuery) DashboardTemplateVariableAvailableValuesQuery { + return DashboardTemplateVariableAvailableValuesQuery{DashboardAvailableValuesMetricsQuery: v} +} + +// UnmarshalJSON turns data into one of the pointers in the struct. +func (obj *DashboardTemplateVariableAvailableValuesQuery) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into DashboardAvailableValuesEventsQuery + err = datadog.Unmarshal(data, &obj.DashboardAvailableValuesEventsQuery) + if err == nil { + if obj.DashboardAvailableValuesEventsQuery != nil && obj.DashboardAvailableValuesEventsQuery.UnparsedObject == nil { + jsonDashboardAvailableValuesEventsQuery, _ := datadog.Marshal(obj.DashboardAvailableValuesEventsQuery) + if string(jsonDashboardAvailableValuesEventsQuery) == "{}" { // empty struct + obj.DashboardAvailableValuesEventsQuery = nil + } else { + match++ + } + } else { + obj.DashboardAvailableValuesEventsQuery = nil + } + } else { + obj.DashboardAvailableValuesEventsQuery = nil + } + + // try to unmarshal data into DashboardAvailableValuesMetricsQuery + err = datadog.Unmarshal(data, &obj.DashboardAvailableValuesMetricsQuery) + if err == nil { + if obj.DashboardAvailableValuesMetricsQuery != nil && obj.DashboardAvailableValuesMetricsQuery.UnparsedObject == nil { + jsonDashboardAvailableValuesMetricsQuery, _ := datadog.Marshal(obj.DashboardAvailableValuesMetricsQuery) + if string(jsonDashboardAvailableValuesMetricsQuery) == "{}" { // empty struct + obj.DashboardAvailableValuesMetricsQuery = nil + } else { + match++ + } + } else { + obj.DashboardAvailableValuesMetricsQuery = nil + } + } else { + obj.DashboardAvailableValuesMetricsQuery = nil + } + + if match != 1 { // more than 1 match + // reset to nil + obj.DashboardAvailableValuesEventsQuery = nil + obj.DashboardAvailableValuesMetricsQuery = nil + return datadog.Unmarshal(data, &obj.UnparsedObject) + } + return nil // exactly one match +} + +// MarshalJSON turns data from the first non-nil pointers in the struct to JSON. +func (obj DashboardTemplateVariableAvailableValuesQuery) MarshalJSON() ([]byte, error) { + if obj.DashboardAvailableValuesEventsQuery != nil { + return datadog.Marshal(&obj.DashboardAvailableValuesEventsQuery) + } + + if obj.DashboardAvailableValuesMetricsQuery != nil { + return datadog.Marshal(&obj.DashboardAvailableValuesMetricsQuery) + } + + if obj.UnparsedObject != nil { + return datadog.Marshal(obj.UnparsedObject) + } + return nil, nil // no data in oneOf schemas +} + +// GetActualInstance returns the actual instance. +func (obj *DashboardTemplateVariableAvailableValuesQuery) GetActualInstance() interface{} { + if obj.DashboardAvailableValuesEventsQuery != nil { + return obj.DashboardAvailableValuesEventsQuery + } + + if obj.DashboardAvailableValuesMetricsQuery != nil { + return obj.DashboardAvailableValuesMetricsQuery + } + + // all schemas are nil + return nil +} diff --git a/tests/scenarios/features/v1/dashboards.feature b/tests/scenarios/features/v1/dashboards.feature index 28e57ec5e2a..404e2f6d342 100644 --- a/tests/scenarios/features/v1/dashboards.feature +++ b/tests/scenarios/features/v1/dashboards.feature @@ -90,7 +90,7 @@ Feature: Dashboards @generated @skip @team:DataDog/dashboards-backend Scenario: Create a new dashboard returns "Bad Request" response Given new "CreateDashboard" request - And body with value {"description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} + And body with value {"description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "available_values_query": {"data_source": "spans", "group_by": [{"facet": ""}], "search": {"query": ""}}, "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} When the request is sent Then the response status is 400 Bad Request @@ -1481,7 +1481,7 @@ Feature: Dashboards Scenario: Update a dashboard returns "Bad Request" response Given new "UpdateDashboard" request And request contains "dashboard_id" parameter from "REPLACE.ME" - And body with value {"description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} + And body with value {"description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "available_values_query": {"data_source": "spans", "group_by": [{"facet": ""}], "search": {"query": ""}}, "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} When the request is sent Then the response status is 400 Bad Request @@ -1489,7 +1489,7 @@ Feature: Dashboards Scenario: Update a dashboard returns "Item Not Found" response Given new "UpdateDashboard" request And request contains "dashboard_id" parameter from "REPLACE.ME" - And body with value {"description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} + And body with value {"description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "available_values_query": {"data_source": "spans", "group_by": [{"facet": ""}], "search": {"query": ""}}, "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} When the request is sent Then the response status is 404 Item Not Found