Skip to content

Commit 1232bf4

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Dashboards - Add semantic_mode support to FormulaAndFunctionMetricQueryDefinition (DataDog#3506)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 4243f11 commit 1232bf4

10 files changed

Lines changed: 352 additions & 6 deletions

.generator/schemas/v1/openapi.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,11 +2952,24 @@ components:
29522952
description: Metrics query definition.
29532953
example: avg:system.cpu.user{*}
29542954
type: string
2955+
semantic_mode:
2956+
$ref: '#/components/schemas/FormulaAndFunctionMetricSemanticMode'
29552957
required:
29562958
- data_source
29572959
- query
29582960
- name
29592961
type: object
2962+
FormulaAndFunctionMetricSemanticMode:
2963+
description: Semantic mode for metrics queries. This determines how metrics
2964+
from different sources are combined or displayed.
2965+
enum:
2966+
- combined
2967+
- native
2968+
example: combined
2969+
type: string
2970+
x-enum-varnames:
2971+
- COMBINED
2972+
- NATIVE
29602973
FormulaAndFunctionProcessQueryDataSource:
29612974
description: Data sources that rely on the process backend.
29622975
enum:

api/datadogV1/model_formula_and_function_metric_query_definition.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type FormulaAndFunctionMetricQueryDefinition struct {
2222
Name string `json:"name"`
2323
// Metrics query definition.
2424
Query string `json:"query"`
25+
// Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed.
26+
SemanticMode *FormulaAndFunctionMetricSemanticMode `json:"semantic_mode,omitempty"`
2527
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
2628
UnparsedObject map[string]interface{} `json:"-"`
2729
AdditionalProperties map[string]interface{} `json:"-"`
@@ -172,6 +174,34 @@ func (o *FormulaAndFunctionMetricQueryDefinition) SetQuery(v string) {
172174
o.Query = v
173175
}
174176

177+
// GetSemanticMode returns the SemanticMode field value if set, zero value otherwise.
178+
func (o *FormulaAndFunctionMetricQueryDefinition) GetSemanticMode() FormulaAndFunctionMetricSemanticMode {
179+
if o == nil || o.SemanticMode == nil {
180+
var ret FormulaAndFunctionMetricSemanticMode
181+
return ret
182+
}
183+
return *o.SemanticMode
184+
}
185+
186+
// GetSemanticModeOk returns a tuple with the SemanticMode field value if set, nil otherwise
187+
// and a boolean to check if the value has been set.
188+
func (o *FormulaAndFunctionMetricQueryDefinition) GetSemanticModeOk() (*FormulaAndFunctionMetricSemanticMode, bool) {
189+
if o == nil || o.SemanticMode == nil {
190+
return nil, false
191+
}
192+
return o.SemanticMode, true
193+
}
194+
195+
// HasSemanticMode returns a boolean if a field has been set.
196+
func (o *FormulaAndFunctionMetricQueryDefinition) HasSemanticMode() bool {
197+
return o != nil && o.SemanticMode != nil
198+
}
199+
200+
// SetSemanticMode gets a reference to the given FormulaAndFunctionMetricSemanticMode and assigns it to the SemanticMode field.
201+
func (o *FormulaAndFunctionMetricQueryDefinition) SetSemanticMode(v FormulaAndFunctionMetricSemanticMode) {
202+
o.SemanticMode = &v
203+
}
204+
175205
// MarshalJSON serializes the struct using spec logic.
176206
func (o FormulaAndFunctionMetricQueryDefinition) MarshalJSON() ([]byte, error) {
177207
toSerialize := map[string]interface{}{}
@@ -187,6 +217,9 @@ func (o FormulaAndFunctionMetricQueryDefinition) MarshalJSON() ([]byte, error) {
187217
toSerialize["data_source"] = o.DataSource
188218
toSerialize["name"] = o.Name
189219
toSerialize["query"] = o.Query
220+
if o.SemanticMode != nil {
221+
toSerialize["semantic_mode"] = o.SemanticMode
222+
}
190223

191224
for key, value := range o.AdditionalProperties {
192225
toSerialize[key] = value
@@ -197,11 +230,12 @@ func (o FormulaAndFunctionMetricQueryDefinition) MarshalJSON() ([]byte, error) {
197230
// UnmarshalJSON deserializes the given payload.
198231
func (o *FormulaAndFunctionMetricQueryDefinition) UnmarshalJSON(bytes []byte) (err error) {
199232
all := struct {
200-
Aggregator *FormulaAndFunctionMetricAggregation `json:"aggregator,omitempty"`
201-
CrossOrgUuids []string `json:"cross_org_uuids,omitempty"`
202-
DataSource *FormulaAndFunctionMetricDataSource `json:"data_source"`
203-
Name *string `json:"name"`
204-
Query *string `json:"query"`
233+
Aggregator *FormulaAndFunctionMetricAggregation `json:"aggregator,omitempty"`
234+
CrossOrgUuids []string `json:"cross_org_uuids,omitempty"`
235+
DataSource *FormulaAndFunctionMetricDataSource `json:"data_source"`
236+
Name *string `json:"name"`
237+
Query *string `json:"query"`
238+
SemanticMode *FormulaAndFunctionMetricSemanticMode `json:"semantic_mode,omitempty"`
205239
}{}
206240
if err = datadog.Unmarshal(bytes, &all); err != nil {
207241
return datadog.Unmarshal(bytes, &o.UnparsedObject)
@@ -217,7 +251,7 @@ func (o *FormulaAndFunctionMetricQueryDefinition) UnmarshalJSON(bytes []byte) (e
217251
}
218252
additionalProperties := make(map[string]interface{})
219253
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
220-
datadog.DeleteKeys(additionalProperties, &[]string{"aggregator", "cross_org_uuids", "data_source", "name", "query"})
254+
datadog.DeleteKeys(additionalProperties, &[]string{"aggregator", "cross_org_uuids", "data_source", "name", "query", "semantic_mode"})
221255
} else {
222256
return err
223257
}
@@ -236,6 +270,11 @@ func (o *FormulaAndFunctionMetricQueryDefinition) UnmarshalJSON(bytes []byte) (e
236270
}
237271
o.Name = *all.Name
238272
o.Query = *all.Query
273+
if all.SemanticMode != nil && !all.SemanticMode.IsValid() {
274+
hasInvalidField = true
275+
} else {
276+
o.SemanticMode = all.SemanticMode
277+
}
239278

240279
if len(additionalProperties) > 0 {
241280
o.AdditionalProperties = additionalProperties
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
// FormulaAndFunctionMetricSemanticMode Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed.
14+
type FormulaAndFunctionMetricSemanticMode string
15+
16+
// List of FormulaAndFunctionMetricSemanticMode.
17+
const (
18+
FORMULAANDFUNCTIONMETRICSEMANTICMODE_COMBINED FormulaAndFunctionMetricSemanticMode = "combined"
19+
FORMULAANDFUNCTIONMETRICSEMANTICMODE_NATIVE FormulaAndFunctionMetricSemanticMode = "native"
20+
)
21+
22+
var allowedFormulaAndFunctionMetricSemanticModeEnumValues = []FormulaAndFunctionMetricSemanticMode{
23+
FORMULAANDFUNCTIONMETRICSEMANTICMODE_COMBINED,
24+
FORMULAANDFUNCTIONMETRICSEMANTICMODE_NATIVE,
25+
}
26+
27+
// GetAllowedValues reeturns the list of possible values.
28+
func (v *FormulaAndFunctionMetricSemanticMode) GetAllowedValues() []FormulaAndFunctionMetricSemanticMode {
29+
return allowedFormulaAndFunctionMetricSemanticModeEnumValues
30+
}
31+
32+
// UnmarshalJSON deserializes the given payload.
33+
func (v *FormulaAndFunctionMetricSemanticMode) UnmarshalJSON(src []byte) error {
34+
var value string
35+
err := datadog.Unmarshal(src, &value)
36+
if err != nil {
37+
return err
38+
}
39+
*v = FormulaAndFunctionMetricSemanticMode(value)
40+
return nil
41+
}
42+
43+
// NewFormulaAndFunctionMetricSemanticModeFromValue returns a pointer to a valid FormulaAndFunctionMetricSemanticMode
44+
// for the value passed as argument, or an error if the value passed is not allowed by the enum.
45+
func NewFormulaAndFunctionMetricSemanticModeFromValue(v string) (*FormulaAndFunctionMetricSemanticMode, error) {
46+
ev := FormulaAndFunctionMetricSemanticMode(v)
47+
if ev.IsValid() {
48+
return &ev, nil
49+
}
50+
return nil, fmt.Errorf("invalid value '%v' for FormulaAndFunctionMetricSemanticMode: valid values are %v", v, allowedFormulaAndFunctionMetricSemanticModeEnumValues)
51+
}
52+
53+
// IsValid return true if the value is valid for the enum, false otherwise.
54+
func (v FormulaAndFunctionMetricSemanticMode) IsValid() bool {
55+
for _, existing := range allowedFormulaAndFunctionMetricSemanticModeEnumValues {
56+
if existing == v {
57+
return true
58+
}
59+
}
60+
return false
61+
}
62+
63+
// Ptr returns reference to FormulaAndFunctionMetricSemanticMode value.
64+
func (v FormulaAndFunctionMetricSemanticMode) Ptr() *FormulaAndFunctionMetricSemanticMode {
65+
return &v
66+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Create a new dashboard with a timeseries widget using formulas and functions metrics query with native semantic_mode
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 native semantic_mode",
19+
Widgets: []datadogV1.Widget{
20+
{
21+
Definition: datadogV1.WidgetDefinition{
22+
TimeseriesWidgetDefinition: &datadogV1.TimeseriesWidgetDefinition{
23+
Type: datadogV1.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES,
24+
Requests: []datadogV1.TimeseriesWidgetRequest{
25+
{
26+
Queries: []datadogV1.FormulaAndFunctionQueryDefinition{
27+
datadogV1.FormulaAndFunctionQueryDefinition{
28+
FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{
29+
DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS,
30+
Name: "query1",
31+
Query: "avg:system.cpu.user{*}",
32+
SemanticMode: datadogV1.FORMULAANDFUNCTIONMETRICSEMANTICMODE_NATIVE.Ptr(),
33+
}},
34+
},
35+
ResponseFormat: datadogV1.FORMULAANDFUNCTIONRESPONSEFORMAT_TIMESERIES.Ptr(),
36+
Formulas: []datadogV1.WidgetFormula{
37+
{
38+
Formula: "query1",
39+
},
40+
},
41+
DisplayType: datadogV1.WIDGETDISPLAYTYPE_LINE.Ptr(),
42+
},
43+
},
44+
}},
45+
},
46+
},
47+
}
48+
ctx := datadog.NewDefaultContext(context.Background())
49+
configuration := datadog.NewConfiguration()
50+
apiClient := datadog.NewAPIClient(configuration)
51+
api := datadogV1.NewDashboardsApi(apiClient)
52+
resp, r, err := api.CreateDashboard(ctx, body)
53+
54+
if err != nil {
55+
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err)
56+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
57+
}
58+
59+
responseContent, _ := json.MarshalIndent(resp, "", " ")
60+
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent)
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Create a new dashboard with a timeseries widget using formulas and functions metrics query with combined semantic_mode
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 combined semantic_mode",
19+
Widgets: []datadogV1.Widget{
20+
{
21+
Definition: datadogV1.WidgetDefinition{
22+
TimeseriesWidgetDefinition: &datadogV1.TimeseriesWidgetDefinition{
23+
Type: datadogV1.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES,
24+
Requests: []datadogV1.TimeseriesWidgetRequest{
25+
{
26+
Queries: []datadogV1.FormulaAndFunctionQueryDefinition{
27+
datadogV1.FormulaAndFunctionQueryDefinition{
28+
FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{
29+
DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS,
30+
Name: "query1",
31+
Query: "avg:system.cpu.user{*}",
32+
SemanticMode: datadogV1.FORMULAANDFUNCTIONMETRICSEMANTICMODE_COMBINED.Ptr(),
33+
}},
34+
},
35+
ResponseFormat: datadogV1.FORMULAANDFUNCTIONRESPONSEFORMAT_TIMESERIES.Ptr(),
36+
Formulas: []datadogV1.WidgetFormula{
37+
{
38+
Formula: "query1",
39+
},
40+
},
41+
DisplayType: datadogV1.WIDGETDISPLAYTYPE_LINE.Ptr(),
42+
},
43+
},
44+
}},
45+
},
46+
},
47+
}
48+
ctx := datadog.NewDefaultContext(context.Background())
49+
configuration := datadog.NewConfiguration()
50+
apiClient := datadog.NewAPIClient(configuration)
51+
api := datadogV1.NewDashboardsApi(apiClient)
52+
resp, r, err := api.CreateDashboard(ctx, body)
53+
54+
if err != nil {
55+
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err)
56+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
57+
}
58+
59+
responseContent, _ := json.MarshalIndent(resp, "", " ")
60+
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent)
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-12-08T18:40:10.047Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
interactions:
2+
- request:
3+
body: |
4+
{"layout_type":"ordered","title":"Test-Create_a_new_dashboard_with_a_timeseries_widget_using_formulas_and_functions_metrics_query_with_comb-1765219210 with combined semantic_mode","widgets":[{"definition":{"requests":[{"display_type":"line","formulas":[{"formula":"query1"}],"queries":[{"data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*}","semantic_mode":"combined"}],"response_format":"timeseries"}],"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":"bpt-wdw-b9x","title":"Test-Create_a_new_dashboard_with_a_timeseries_widget_using_formulas_and_functions_metrics_query_with_comb-1765219210
16+
with combined semantic_mode","description":null,"author_handle":"frog@datadoghq.com","author_name":"frog","layout_type":"ordered","url":"/dashboard/bpt-wdw-b9x/test-createanewdashboardwithatimeserieswidgetusingformulasandfunctionsmetricsque","template_variables":null,"widgets":[{"definition":{"requests":[{"display_type":"line","formulas":[{"formula":"query1"}],"queries":[{"data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*}","semantic_mode":"combined"}],"response_format":"timeseries"}],"type":"timeseries"},"id":7196642548461969}],"notify_list":null,"created_at":"2025-12-08T18:40:10.214467+00:00","modified_at":"2025-12-08T18:40:10.214467+00:00","restricted_roles":[]}'
17+
code: 200
18+
duration: 0ms
19+
headers:
20+
Content-Type:
21+
- application/json
22+
status: 200 OK
23+
- request:
24+
body: ''
25+
form: {}
26+
headers:
27+
Accept:
28+
- application/json
29+
id: 1
30+
method: DELETE
31+
url: https://api.datadoghq.com/api/v1/dashboard/bpt-wdw-b9x
32+
response:
33+
body: '{"deleted_dashboard_id":"bpt-wdw-b9x"}'
34+
code: 200
35+
duration: 0ms
36+
headers:
37+
Content-Type:
38+
- application/json
39+
status: 200 OK
40+
version: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-12-08T18:32:38.191Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
interactions:
2+
- request:
3+
body: |
4+
{"layout_type":"ordered","title":"Test-Create_a_new_dashboard_with_a_timeseries_widget_using_formulas_and_functions_metrics_query_with_nati-1765218758 with native semantic_mode","widgets":[{"definition":{"requests":[{"display_type":"line","formulas":[{"formula":"query1"}],"queries":[{"data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*}","semantic_mode":"native"}],"response_format":"timeseries"}],"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":"ptr-h98-jx4","title":"Test-Create_a_new_dashboard_with_a_timeseries_widget_using_formulas_and_functions_metrics_query_with_nati-1765218758
16+
with native semantic_mode","description":null,"author_handle":"frog@datadoghq.com","author_name":"frog","layout_type":"ordered","url":"/dashboard/ptr-h98-jx4/test-createanewdashboardwithatimeserieswidgetusingformulasandfunctionsmetricsque","template_variables":null,"widgets":[{"definition":{"requests":[{"display_type":"line","formulas":[{"formula":"query1"}],"queries":[{"data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*}","semantic_mode":"native"}],"response_format":"timeseries"}],"type":"timeseries"},"id":7543625669678795}],"notify_list":null,"created_at":"2025-12-08T18:32:38.359385+00:00","modified_at":"2025-12-08T18:32:38.359385+00:00","restricted_roles":[]}'
17+
code: 200
18+
duration: 0ms
19+
headers:
20+
Content-Type:
21+
- application/json
22+
status: 200 OK
23+
- request:
24+
body: ''
25+
form: {}
26+
headers:
27+
Accept:
28+
- application/json
29+
id: 1
30+
method: DELETE
31+
url: https://api.datadoghq.com/api/v1/dashboard/ptr-h98-jx4
32+
response:
33+
body: '{"deleted_dashboard_id":"ptr-h98-jx4"}'
34+
code: 200
35+
duration: 0ms
36+
headers:
37+
Content-Type:
38+
- application/json
39+
status: 200 OK
40+
version: 2

0 commit comments

Comments
 (0)