Skip to content
Open
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
63 changes: 63 additions & 0 deletions examples/v2/metrics/QueryScalarData_1034033281.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Scalar query with grouped row count metadata returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.MetricsApi;
import com.datadog.api.client.v2.model.FormulaLimit;
import com.datadog.api.client.v2.model.MetricsAggregator;
import com.datadog.api.client.v2.model.MetricsDataSource;
import com.datadog.api.client.v2.model.MetricsScalarQuery;
import com.datadog.api.client.v2.model.QueryFormula;
import com.datadog.api.client.v2.model.QuerySortOrder;
import com.datadog.api.client.v2.model.ScalarFormulaQueryRequest;
import com.datadog.api.client.v2.model.ScalarFormulaQueryResponse;
import com.datadog.api.client.v2.model.ScalarFormulaRequest;
import com.datadog.api.client.v2.model.ScalarFormulaRequestAttributes;
import com.datadog.api.client.v2.model.ScalarFormulaRequestType;
import com.datadog.api.client.v2.model.ScalarQuery;
import java.util.Collections;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
MetricsApi apiInstance = new MetricsApi(defaultClient);

ScalarFormulaQueryRequest body =
new ScalarFormulaQueryRequest()
.data(
new ScalarFormulaRequest()
.attributes(
new ScalarFormulaRequestAttributes()
.formulas(
Collections.singletonList(
new QueryFormula()
.formula("a")
.limit(
new FormulaLimit()
.count(1)
.order(QuerySortOrder.DESC))))
.from(1636625471000L)
.queries(
Collections.singletonList(
new ScalarQuery(
new MetricsScalarQuery()
.dataSource(MetricsDataSource.METRICS)
.query("avg:system.cpu.user{*} by {host}")
.name("a")
.aggregator(MetricsAggregator.AVG))))
.to(1636629071000L))
.type(ScalarFormulaRequestType.SCALAR_REQUEST));

try {
ScalarFormulaQueryResponse result = apiInstance.queryScalarData(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MetricsApi#queryScalarData");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,16 @@ Feature: Metrics
Then the response status is 200 OK
And the response "data.type" is equal to "scalar_response"

@team:ddoghq/timeseries-query
Scenario: Scalar query with grouped row count metadata returns "OK" response
Given a valid "appKeyAuth" key in the system
And new "QueryScalarData" request
And body with value {"data": {"attributes": {"formulas": [{"formula": "a", "limit": {"count": 1, "order": "desc"}}], "from": {{ timestamp('now - 1h') }}000, "queries": [{"data_source": "metrics", "query": "avg:system.cpu.user{*} by {host}", "name": "a", "aggregator": "avg"}], "to": {{ timestamp('now') }}000}, "type": "scalar_request"}}
When the request is sent
Then the response status is 200 OK
And the response "data.type" is equal to "scalar_response"
And the response "data.attributes.columns[0].type" is equal to "group"

@generated @skip @team:ddoghq/metrics-intake
Scenario: Submit metrics returns "Bad Request" response
Given new "SubmitMetrics" request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8603,6 +8603,13 @@
"scenario": "Scalar cross product query with spans data source returns \"OK\" response",
"version": "v2"
},
{
"feature": "Metrics",
"feature_file": "../../com/datadog/api/client/v2/api/metrics.feature",
"file": "v2/metrics/scalar-query-with-grouped-row-count-metadata-returns-ok-response.json",
"scenario": "Scalar query with grouped row count metadata returns \"OK\" response",
"version": "v2"
},
{
"feature": "Metrics",
"feature_file": "../../com/datadog/api/client/v2/api/metrics.feature",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"api": "Metrics",
"expected_status": 200,
"feature": "Metrics",
"id": "v2/Metrics/Scalar query with grouped row count metadata returns \"OK\" response",
"operation_id": "QueryScalarData",
"request": {
"body": {
"schema": {
"format": null,
"ref": "ScalarFormulaQueryRequest",
"type": "object"
},
"source": "inline",
"value": {
"$openapi_transformer_template": "{\"data\": {\"attributes\": {\"formulas\": [{\"formula\": \"a\", \"limit\": {\"count\": 1, \"order\": \"desc\"}}], \"from\": {{ timestamp('now - 1h') }}000, \"queries\": [{\"data_source\": \"metrics\", \"query\": \"avg:system.cpu.user{*} by {host}\", \"name\": \"a\", \"aggregator\": \"avg\"}], \"to\": {{ timestamp('now') }}000}, \"type\": \"scalar_request\"}}"
}
},
"content_type": "application/json",
"method": "POST",
"pagination": false,
"parameters": [],
"path": "/api/v2/query/scalar"
},
"scenario": "Scalar query with grouped row count metadata returns \"OK\" response",
"schema_version": 1,
"version": "v2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,7 @@
},
{
"feature": "Metrics",
"frozen_at": "2024-03-25T19:28:00.854Z",
"frozen_at": "2026-10-22T15:05:21.723Z",
"interactions": [
{
"request": {
Expand All @@ -2447,7 +2447,7 @@
}
}
],
"from": 1711391280000,
"from": 1792677921000,
"queries": [
{
"aggregator": "avg",
Expand All @@ -2456,7 +2456,7 @@
"query": "avg:system.cpu.user{*}"
}
],
"to": 1711394880000
"to": 1792681521000
},
"type": "scalar_request"
}
Expand All @@ -2470,10 +2470,10 @@
"response": {
"body": {
"encoding": "text",
"value": "{\"data\":{\"type\":\"scalar_response\",\"attributes\":{\"columns\":[{\"values\":[6.368151928283307],\"name\":\"a\",\"meta\":{\"unit\":[{\"short_name\":\"%\",\"id\":17,\"plural\":\"percent\",\"name\":\"percent\",\"family\":\"percentage\",\"scale_factor\":1.0},null]},\"type\":\"number\"}]}}}"
"value": "{\"data\":{\"id\":\"0\",\"type\":\"scalar_response\",\"attributes\":{\"columns\":[{\"name\":\"a\",\"values\":[0.5286438660222104],\"type\":\"number\",\"meta\":{\"unit\":[{\"family\":\"percentage\",\"name\":\"percent\",\"plural\":\"percent\",\"scale_factor\":1.0,\"short_name\":\"%\",\"id\":17},null]}}]}}}"
},
"headers": {
"content-type": "application/json"
"content-type": "application/vnd.api+json"
},
"reason": "OK",
"status": 200
Expand Down Expand Up @@ -3663,6 +3663,62 @@
"scenario": "Scalar cross product query with spans data source returns \"OK\" response",
"version": "v2"
},
{
"feature": "Metrics",
"frozen_at": "2026-12-04T04:15:29.778Z",
"interactions": [
{
"request": {
"body": {
"type": "json",
"value": {
"data": {
"attributes": {
"formulas": [
{
"formula": "a",
"limit": {
"count": 1,
"order": "desc"
}
}
],
"from": 1796354129000,
"queries": [
{
"aggregator": "avg",
"data_source": "metrics",
"name": "a",
"query": "avg:system.cpu.user{*} by {host}"
}
],
"to": 1796357729000
},
"type": "scalar_request"
}
}
},
"content_type": "application/json",
"method": "POST",
"path": "/api/v2/query/scalar",
"query": []
},
"response": {
"body": {
"encoding": "text",
"value": "{\"data\":{\"id\":\"0\",\"type\":\"scalar_response\",\"attributes\":{\"columns\":[{\"name\":\"host\",\"values\":[[\"control-0-17181f25-581c-43a1-8f25-529c288125a8\"]],\"type\":\"group\"},{\"name\":\"a\",\"values\":[28.427062986788517],\"type\":\"number\",\"meta\":{\"unit\":[{\"family\":\"percentage\",\"name\":\"percent\",\"plural\":\"percent\",\"scale_factor\":1.0,\"short_name\":\"%\",\"id\":17},null]}}],\"total_count\":8}}}"
},
"headers": {
"content-type": "application/vnd.api+json"
},
"reason": "OK",
"status": 200
}
}
],
"scenario": "Scalar query with grouped row count metadata returns \"OK\" response",
"version": "v2"
},
{
"feature": "Metrics",
"frozen_at": "2022-07-12T21:45:36.018Z",
Expand Down
Loading