From 2378b7aebbee04e8ee207131bc7d2cc61ae1a5cb Mon Sep 17 00:00:00 2001 From: "api-clients-generation-pipeline[bot]" <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Date: Tue, 9 Dec 2025 23:39:23 +0000 Subject: [PATCH] Dashboards - Add semantic_mode support to FormulaAndFunctionMetricQueryDefinition (#2817) Co-authored-by: ci.datadog-api-spec --- .generator/schemas/v1/openapi.yaml | 13 ++++++ ...s-query-with-combined-semantic-mode.frozen | 1 + ...rics-query-with-combined-semantic-mode.yml | 44 +++++++++++++++++++ ...ics-query-with-native-semantic-mode.frozen | 1 + ...etrics-query-with-native-semantic-mode.yml | 44 +++++++++++++++++++ .../dashboards/CreateDashboard_3685886950.rb | 36 +++++++++++++++ .../dashboards/CreateDashboard_865807520.rb | 36 +++++++++++++++ features/v1/dashboards.feature | 24 ++++++++++ lib/datadog_api_client/inflector.rb | 1 + ...la_and_function_metric_query_definition.rb | 16 +++++-- ...rmula_and_function_metric_semantic_mode.rb | 27 ++++++++++++ 11 files changed, 240 insertions(+), 3 deletions(-) create mode 100644 cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-combined-semantic-mode.frozen create mode 100644 cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-combined-semantic-mode.yml create mode 100644 cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-native-semantic-mode.frozen create mode 100644 cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-native-semantic-mode.yml create mode 100644 examples/v1/dashboards/CreateDashboard_3685886950.rb create mode 100644 examples/v1/dashboards/CreateDashboard_865807520.rb create mode 100644 lib/datadog_api_client/v1/models/formula_and_function_metric_semantic_mode.rb diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 4fc8dbe37859..afb32a4a89a0 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -2952,11 +2952,24 @@ components: description: Metrics query definition. example: avg:system.cpu.user{*} type: string + semantic_mode: + $ref: '#/components/schemas/FormulaAndFunctionMetricSemanticMode' required: - data_source - query - name type: object + FormulaAndFunctionMetricSemanticMode: + description: Semantic mode for metrics queries. This determines how metrics + from different sources are combined or displayed. + enum: + - combined + - native + example: combined + type: string + x-enum-varnames: + - COMBINED + - NATIVE FormulaAndFunctionProcessQueryDataSource: description: Data sources that rely on the process backend. enum: diff --git a/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-combined-semantic-mode.frozen b/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-combined-semantic-mode.frozen new file mode 100644 index 000000000000..0f7fd4489e4a --- /dev/null +++ b/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-combined-semantic-mode.frozen @@ -0,0 +1 @@ +2025-12-08T18:40:10.047Z \ No newline at end of file diff --git a/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-combined-semantic-mode.yml b/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-combined-semantic-mode.yml new file mode 100644 index 000000000000..edc4696a8b07 --- /dev/null +++ b/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-combined-semantic-mode.yml @@ -0,0 +1,44 @@ +http_interactions: +- recorded_at: Mon, 08 Dec 2025 18:40:10 GMT + request: + body: + encoding: UTF-8 + string: '{"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"}}]}' + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + uri: https://api.datadoghq.com/api/v1/dashboard + response: + body: + encoding: UTF-8 + string: '{"id":"bpt-wdw-b9x","title":"Test-Create_a_new_dashboard_with_a_timeseries_widget_using_formulas_and_functions_metrics_query_with_comb-1765219210 + 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":[]}' + headers: + Content-Type: + - application/json + status: + code: 200 + message: OK +- recorded_at: Mon, 08 Dec 2025 18:40:10 GMT + request: + body: null + headers: + Accept: + - application/json + method: DELETE + uri: https://api.datadoghq.com/api/v1/dashboard/bpt-wdw-b9x + response: + body: + encoding: UTF-8 + string: '{"deleted_dashboard_id":"bpt-wdw-b9x"}' + headers: + Content-Type: + - application/json + status: + code: 200 + message: OK +recorded_with: VCR 6.0.0 diff --git a/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-native-semantic-mode.frozen b/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-native-semantic-mode.frozen new file mode 100644 index 000000000000..1acb8f2716e0 --- /dev/null +++ b/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-native-semantic-mode.frozen @@ -0,0 +1 @@ +2025-12-08T18:32:38.191Z \ No newline at end of file diff --git a/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-native-semantic-mode.yml b/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-native-semantic-mode.yml new file mode 100644 index 000000000000..318ce92276dd --- /dev/null +++ b/cassettes/features/v1/dashboards/Create-a-new-dashboard-with-a-timeseries-widget-using-formulas-and-functions-metrics-query-with-native-semantic-mode.yml @@ -0,0 +1,44 @@ +http_interactions: +- recorded_at: Mon, 08 Dec 2025 18:32:38 GMT + request: + body: + encoding: UTF-8 + string: '{"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"}}]}' + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + uri: https://api.datadoghq.com/api/v1/dashboard + response: + body: + encoding: UTF-8 + string: '{"id":"ptr-h98-jx4","title":"Test-Create_a_new_dashboard_with_a_timeseries_widget_using_formulas_and_functions_metrics_query_with_nati-1765218758 + 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":[]}' + headers: + Content-Type: + - application/json + status: + code: 200 + message: OK +- recorded_at: Mon, 08 Dec 2025 18:32:38 GMT + request: + body: null + headers: + Accept: + - application/json + method: DELETE + uri: https://api.datadoghq.com/api/v1/dashboard/ptr-h98-jx4 + response: + body: + encoding: UTF-8 + string: '{"deleted_dashboard_id":"ptr-h98-jx4"}' + headers: + Content-Type: + - application/json + status: + code: 200 + message: OK +recorded_with: VCR 6.0.0 diff --git a/examples/v1/dashboards/CreateDashboard_3685886950.rb b/examples/v1/dashboards/CreateDashboard_3685886950.rb new file mode 100644 index 000000000000..ca7f24de6978 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_3685886950.rb @@ -0,0 +1,36 @@ +# Create a new dashboard with a timeseries widget using formulas and functions metrics query with native semantic_mode + +require "datadog_api_client" +api_instance = DatadogAPIClient::V1::DashboardsAPI.new + +body = DatadogAPIClient::V1::Dashboard.new({ + layout_type: DatadogAPIClient::V1::DashboardLayoutType::ORDERED, + title: "Example-Dashboard with native semantic_mode", + widgets: [ + DatadogAPIClient::V1::Widget.new({ + definition: DatadogAPIClient::V1::TimeseriesWidgetDefinition.new({ + type: DatadogAPIClient::V1::TimeseriesWidgetDefinitionType::TIMESERIES, + requests: [ + DatadogAPIClient::V1::TimeseriesWidgetRequest.new({ + queries: [ + DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({ + data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS, + name: "query1", + query: "avg:system.cpu.user{*}", + semantic_mode: DatadogAPIClient::V1::FormulaAndFunctionMetricSemanticMode::NATIVE, + }), + ], + response_format: DatadogAPIClient::V1::FormulaAndFunctionResponseFormat::TIMESERIES, + formulas: [ + DatadogAPIClient::V1::WidgetFormula.new({ + formula: "query1", + }), + ], + display_type: DatadogAPIClient::V1::WidgetDisplayType::LINE, + }), + ], + }), + }), + ], +}) +p api_instance.create_dashboard(body) diff --git a/examples/v1/dashboards/CreateDashboard_865807520.rb b/examples/v1/dashboards/CreateDashboard_865807520.rb new file mode 100644 index 000000000000..46ef777316b7 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_865807520.rb @@ -0,0 +1,36 @@ +# Create a new dashboard with a timeseries widget using formulas and functions metrics query with combined semantic_mode + +require "datadog_api_client" +api_instance = DatadogAPIClient::V1::DashboardsAPI.new + +body = DatadogAPIClient::V1::Dashboard.new({ + layout_type: DatadogAPIClient::V1::DashboardLayoutType::ORDERED, + title: "Example-Dashboard with combined semantic_mode", + widgets: [ + DatadogAPIClient::V1::Widget.new({ + definition: DatadogAPIClient::V1::TimeseriesWidgetDefinition.new({ + type: DatadogAPIClient::V1::TimeseriesWidgetDefinitionType::TIMESERIES, + requests: [ + DatadogAPIClient::V1::TimeseriesWidgetRequest.new({ + queries: [ + DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({ + data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS, + name: "query1", + query: "avg:system.cpu.user{*}", + semantic_mode: DatadogAPIClient::V1::FormulaAndFunctionMetricSemanticMode::COMBINED, + }), + ], + response_format: DatadogAPIClient::V1::FormulaAndFunctionResponseFormat::TIMESERIES, + formulas: [ + DatadogAPIClient::V1::WidgetFormula.new({ + formula: "query1", + }), + ], + display_type: DatadogAPIClient::V1::WidgetDisplayType::LINE, + }), + ], + }), + }), + ], +}) +p api_instance.create_dashboard(body) diff --git a/features/v1/dashboards.feature b/features/v1/dashboards.feature index 0d161522e954..3eeebebdc24c 100644 --- a/features/v1/dashboards.feature +++ b/features/v1/dashboards.feature @@ -195,6 +195,30 @@ Feature: Dashboards And the response "widgets[0].definition.requests[0].formulas[0].formula" is equal to "query1" And the response "widgets[0].definition.time.live_span" is equal to "week_to_date" + @team:DataDog/dashboards-backend + Scenario: Create a new dashboard with a timeseries widget using formulas and functions metrics query with combined semantic_mode + Given new "CreateDashboard" request + And body with value {"layout_type": "ordered", "title": "{{ unique }} with combined semantic_mode", "widgets": [{"definition": {"type": "timeseries", "requests": [{"queries": [{"data_source": "metrics", "name": "query1", "query": "avg:system.cpu.user{*}", "semantic_mode": "combined"}], "response_format": "timeseries", "formulas": [{"formula": "query1"}], "display_type": "line"}]}}]} + When the request is sent + Then the response status is 200 OK + And the response "widgets[0].definition.requests[0].response_format" is equal to "timeseries" + And the response "widgets[0].definition.requests[0].queries[0].data_source" is equal to "metrics" + And the response "widgets[0].definition.requests[0].queries[0].name" is equal to "query1" + And the response "widgets[0].definition.requests[0].queries[0].query" is equal to "avg:system.cpu.user{*}" + And the response "widgets[0].definition.requests[0].queries[0].semantic_mode" is equal to "combined" + + @team:DataDog/dashboards-backend + Scenario: Create a new dashboard with a timeseries widget using formulas and functions metrics query with native semantic_mode + Given new "CreateDashboard" request + And body with value {"layout_type": "ordered", "title": "{{ unique }} with native semantic_mode", "widgets": [{"definition": {"type": "timeseries", "requests": [{"queries": [{"data_source": "metrics", "name": "query1", "query": "avg:system.cpu.user{*}", "semantic_mode": "native"}], "response_format": "timeseries", "formulas": [{"formula": "query1"}], "display_type": "line"}]}}]} + When the request is sent + Then the response status is 200 OK + And the response "widgets[0].definition.requests[0].response_format" is equal to "timeseries" + And the response "widgets[0].definition.requests[0].queries[0].data_source" is equal to "metrics" + And the response "widgets[0].definition.requests[0].queries[0].name" is equal to "query1" + And the response "widgets[0].definition.requests[0].queries[0].query" is equal to "avg:system.cpu.user{*}" + And the response "widgets[0].definition.requests[0].queries[0].semantic_mode" is equal to "native" + @team:DataDog/dashboards-backend Scenario: Create a new dashboard with a toplist widget sorted by group Given new "CreateDashboard" request diff --git a/lib/datadog_api_client/inflector.rb b/lib/datadog_api_client/inflector.rb index 12cd943aba84..9a311d18bec0 100644 --- a/lib/datadog_api_client/inflector.rb +++ b/lib/datadog_api_client/inflector.rb @@ -134,6 +134,7 @@ def overrides "v1.formula_and_function_metric_aggregation" => "FormulaAndFunctionMetricAggregation", "v1.formula_and_function_metric_data_source" => "FormulaAndFunctionMetricDataSource", "v1.formula_and_function_metric_query_definition" => "FormulaAndFunctionMetricQueryDefinition", + "v1.formula_and_function_metric_semantic_mode" => "FormulaAndFunctionMetricSemanticMode", "v1.formula_and_function_process_query_data_source" => "FormulaAndFunctionProcessQueryDataSource", "v1.formula_and_function_process_query_definition" => "FormulaAndFunctionProcessQueryDefinition", "v1.formula_and_function_query_definition" => "FormulaAndFunctionQueryDefinition", diff --git a/lib/datadog_api_client/v1/models/formula_and_function_metric_query_definition.rb b/lib/datadog_api_client/v1/models/formula_and_function_metric_query_definition.rb index f7d96919ca4e..abe07f88d3f9 100644 --- a/lib/datadog_api_client/v1/models/formula_and_function_metric_query_definition.rb +++ b/lib/datadog_api_client/v1/models/formula_and_function_metric_query_definition.rb @@ -36,6 +36,9 @@ class FormulaAndFunctionMetricQueryDefinition # Metrics query definition. attr_reader :query + # Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed. + attr_accessor :semantic_mode + attr_accessor :additional_properties # Attribute mapping from ruby-style variable name to JSON key. @@ -46,7 +49,8 @@ def self.attribute_map :'cross_org_uuids' => :'cross_org_uuids', :'data_source' => :'data_source', :'name' => :'name', - :'query' => :'query' + :'query' => :'query', + :'semantic_mode' => :'semantic_mode' } end @@ -58,7 +62,8 @@ def self.openapi_types :'cross_org_uuids' => :'Array', :'data_source' => :'FormulaAndFunctionMetricDataSource', :'name' => :'String', - :'query' => :'String' + :'query' => :'String', + :'semantic_mode' => :'FormulaAndFunctionMetricSemanticMode' } end @@ -101,6 +106,10 @@ def initialize(attributes = {}) if attributes.key?(:'query') self.query = attributes[:'query'] end + + if attributes.key?(:'semantic_mode') + self.semantic_mode = attributes[:'semantic_mode'] + end end # Check to see if the all the properties in the model are valid @@ -185,6 +194,7 @@ def ==(o) data_source == o.data_source && name == o.name && query == o.query && + semantic_mode == o.semantic_mode && additional_properties == o.additional_properties end @@ -192,7 +202,7 @@ def ==(o) # @return [Integer] Hash code # @!visibility private def hash - [aggregator, cross_org_uuids, data_source, name, query, additional_properties].hash + [aggregator, cross_org_uuids, data_source, name, query, semantic_mode, additional_properties].hash end end end diff --git a/lib/datadog_api_client/v1/models/formula_and_function_metric_semantic_mode.rb b/lib/datadog_api_client/v1/models/formula_and_function_metric_semantic_mode.rb new file mode 100644 index 000000000000..f21f29c099a2 --- /dev/null +++ b/lib/datadog_api_client/v1/models/formula_and_function_metric_semantic_mode.rb @@ -0,0 +1,27 @@ +=begin +#Datadog API V1 Collection + +#Collection of all Datadog Public endpoints. + +The version of the OpenAPI document: 1.0 +Contact: support@datadoghq.com +Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator + + 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 2020-Present Datadog, Inc. + +=end + +require 'date' +require 'time' + +module DatadogAPIClient::V1 + # Semantic mode for metrics queries. This determines how metrics from different sources are combined or displayed. + class FormulaAndFunctionMetricSemanticMode + include BaseEnumModel + + COMBINED = "combined".freeze + NATIVE = "native".freeze + end +end