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
54 changes: 54 additions & 0 deletions examples/v2/metrics/QueryTimeseriesData_873207911.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Timeseries query with top function 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.MetricsDataSource;
import com.datadog.api.client.v2.model.MetricsTimeseriesQuery;
import com.datadog.api.client.v2.model.QueryFormula;
import com.datadog.api.client.v2.model.TimeseriesFormulaQueryRequest;
import com.datadog.api.client.v2.model.TimeseriesFormulaQueryResponse;
import com.datadog.api.client.v2.model.TimeseriesFormulaRequest;
import com.datadog.api.client.v2.model.TimeseriesFormulaRequestAttributes;
import com.datadog.api.client.v2.model.TimeseriesFormulaRequestType;
import com.datadog.api.client.v2.model.TimeseriesQuery;
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);

TimeseriesFormulaQueryRequest body =
new TimeseriesFormulaQueryRequest()
.data(
new TimeseriesFormulaRequest()
.attributes(
new TimeseriesFormulaRequestAttributes()
.formulas(
Collections.singletonList(
new QueryFormula().formula("top(a, 1, 'max', 'desc')")))
.from(1636625471000L)
.queries(
Collections.singletonList(
new TimeseriesQuery(
new MetricsTimeseriesQuery()
.dataSource(MetricsDataSource.METRICS)
.query("avg:system.cpu.user{*} by {host}")
.name("a"))))
.to(1636629071000L))
.type(TimeseriesFormulaRequestType.TIMESERIES_REQUEST));

try {
TimeseriesFormulaQueryResponse result = apiInstance.queryTimeseriesData(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MetricsApi#queryTimeseriesData");
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 @@ -1144,6 +1144,16 @@ Feature: Metrics
Then the response status is 200 OK
And the response "data.type" is equal to "timeseries_response"

@team:ddoghq/timeseries-query
Scenario: Timeseries query with top function metadata returns "OK" response
Given a valid "appKeyAuth" key in the system
And new "QueryTimeseriesData" request
And body with value {"data": {"attributes": {"formulas": [{"formula": "top(a, 1, 'max', 'desc')"}], "from": {{ timestamp('now - 1h') }}000, "queries": [{"data_source": "metrics", "query": "avg:system.cpu.user{*} by {host}", "name": "a"}], "to": {{ timestamp('now') }}000}, "type": "timeseries_request"}}
When the request is sent
Then the response status is 200 OK
And the response "data.type" is equal to "timeseries_response"
And the response "data.attributes.series[0].query_index" is equal to 0

@team:ddoghq/metrics-experience
Scenario: Update a derived metric returns "Bad Request" response
Given a valid "appKeyAuth" key in the system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8757,6 +8757,13 @@
"scenario": "Timeseries 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/timeseries-query-with-top-function-metadata-returns-ok-response.json",
"scenario": "Timeseries query with top function 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/Timeseries query with top function metadata returns \"OK\" response",
"operation_id": "QueryTimeseriesData",
"request": {
"body": {
"schema": {
"format": null,
"ref": "TimeseriesFormulaQueryRequest",
"type": "object"
},
"source": "inline",
"value": {
"$openapi_transformer_template": "{\"data\": {\"attributes\": {\"formulas\": [{\"formula\": \"top(a, 1, 'max', 'desc')\"}], \"from\": {{ timestamp('now - 1h') }}000, \"queries\": [{\"data_source\": \"metrics\", \"query\": \"avg:system.cpu.user{*} by {host}\", \"name\": \"a\"}], \"to\": {{ timestamp('now') }}000}, \"type\": \"timeseries_request\"}}"
}
},
"content_type": "application/json",
"method": "POST",
"pagination": false,
"parameters": [],
"path": "/api/v2/query/timeseries"
},
"scenario": "Timeseries query with top function metadata returns \"OK\" response",
"schema_version": 1,
"version": "v2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5061,6 +5061,57 @@
"scenario": "Timeseries cross product query with spans data source returns \"OK\" response",
"version": "v2"
},
{
"feature": "Metrics",
"frozen_at": "2026-12-04T04:15:28.166Z",
"interactions": [
{
"request": {
"body": {
"type": "json",
"value": {
"data": {
"attributes": {
"formulas": [
{
"formula": "top(a, 1, 'max', 'desc')"
}
],
"from": 1796354128000,
"queries": [
{
"data_source": "metrics",
"name": "a",
"query": "avg:system.cpu.user{*} by {host}"
}
],
"to": 1796357728000
},
"type": "timeseries_request"
}
}
},
"content_type": "application/json",
"method": "POST",
"path": "/api/v2/query/timeseries",
"query": []
},
"response": {
"body": {
"encoding": "text",
"value": "{\"data\":{\"id\":\"0\",\"type\":\"timeseries_response\",\"attributes\":{\"series\":[{\"attributes\":{\"top\":{\"method\":[\"max\"],\"order\":[\"desc\"],\"value\":[50.92276144904113]}},\"group_tags\":[\"host:control-0-17181f25-581c-43a1-8f25-529c288125a8\"],\"query_index\":0,\"unit\":[{\"family\":\"percentage\",\"name\":\"percent\",\"plural\":\"percent\",\"scale_factor\":1.0,\"short_name\":\"%\",\"id\":17},null]}],\"times\":[1796354140000,1796354160000,1796354180000,1796354200000,1796354220000,1796354240000,1796354260000,1796354280000,1796354300000,1796354320000,1796354340000,1796354360000,1796354380000,1796354400000,1796354420000,1796354440000,1796354460000,1796354480000,1796354500000,1796354520000,1796354540000,1796354560000,1796354580000,1796354600000,1796354620000,1796354640000,1796354660000,1796354680000,1796354700000,1796354720000,1796354740000,1796354760000,1796354780000,1796354800000,1796354820000,1796354840000,1796354860000,1796354880000,1796354900000,1796354920000,1796354940000,1796354960000,1796354980000,1796355000000,1796355020000,1796355040000,1796355060000,1796355080000,1796355100000,1796355120000,1796355140000,1796355160000,1796355180000,1796355200000,1796355220000,1796355240000,1796355260000,1796355280000,1796355300000,1796355320000,1796355340000,1796355360000,1796355380000,1796355400000,1796355420000,1796355440000,1796355460000,1796355480000,1796355500000,1796355520000,1796355540000,1796355560000,1796355580000,1796355600000,1796355620000,1796355640000,1796355660000,1796355680000,1796355700000,1796355720000,1796355740000,1796355760000,1796355780000,1796355800000,1796355820000,1796355840000,1796355860000,1796355880000,1796355900000,1796355920000,1796355940000,1796355960000,1796355980000,1796356000000,1796356020000,1796356040000,1796356060000,1796356080000,1796356100000,1796356120000,1796356140000,1796356160000,1796356180000,1796356200000,1796356220000,1796356240000,1796356260000,1796356280000,1796356300000,1796356320000,1796356340000,1796356360000,1796356380000,1796356400000,1796356420000,1796356440000,1796356460000,1796356480000,1796356500000,1796356520000,1796356540000,1796356560000,1796356580000,1796356600000,1796356620000,1796356640000,1796356660000,1796356680000,1796356700000,1796356720000,1796356740000,1796356760000,1796356780000,1796356800000,1796356820000,1796356840000,1796356860000,1796356880000,1796356900000,1796356920000,1796356940000,1796356960000,1796356980000,1796357000000,1796357020000,1796357040000,1796357060000,1796357080000,1796357100000,1796357120000,1796357140000,1796357160000,1796357180000,1796357200000,1796357220000,1796357240000,1796357260000,1796357280000,1796357300000,1796357320000,1796357340000,1796357360000,1796357380000,1796357400000,1796357420000,1796357440000,1796357460000,1796357480000,1796357500000,1796357520000,1796357540000,1796357560000,1796357580000,1796357600000,1796357620000,1796357640000,1796357660000,1796357680000,1796357700000,1796357720000],\"values\":[[28.263889,14.875744,36.446551,28.675958,15.222729,32.112247,28.760908,16.812609,34.640022,31.668712,25.726091,47.093223,24.886562,21.438793,41.952055,22.754282,25.052699,50.922761,18.25784,25.400124,42.69046,20.475192,22.12068,43.245101,32.607625,21.970149,42.935717,12.469352,27.408567,43.039724,29.301356,20.26273,43.816741,18.35443,24.321521,41.867677,12.176991,26.623137,39.547038,31.416769,23.2865,33.587786,35.421016,20.573436,41.050449,13.156966,26.280722,27.250608,31.537133,21.391728,36.809176,19.971871,26.205062,33.956386,27.63503,21.313673,41.704036,26.447814,23.791304,25.347705,26.405323,30.339806,26.273552,28.221635,21.935033,32.212205,25.528645,24.913013,27.963738,26.791277,26.716807,26.642336,27.153418,25.965889,27.741266,27.643286,21.144452,32.883351,30.165764,20.526316,41.066482,27.62319,23.205575,29.948007,23.865604,25.657599,27.449593,26.773561,25.436148,26.588398,32.533255,15.696466,37.107352,28.817799,12.548467,38.557128,25.995119,16.297857,35.285962,29.826389,30.921958,31.469743,29.208434,11.527581,34.664518,29.331942,26.292057,31.642901,28.878116,11.189802,35.397058,28.05383,12.068966,33.249104,33.763203,34.277301,34.791399,24.912526,15.857947,35.256513,26.463457,15.646018,30.889762,28.511967,16.022292,22.960379,27.301255,26.350645,34.449832,33.973165,33.496499,33.019832,25.730181,11.394197,34.978489,26.798749,13.822285,34.761215,29.661903,11.698774,34.888199,27.464545,26.281163,35.122618,30.475236,21.180471,35.330579,28.086744,18.626728,40.910659,26.0478,17.469893,45.532942,28.241065,17.824521,43.825249,27.8826,18.506566,47.509447,34.640985,21.772522,37.358101,22.245467,20.571234,48.464164,27.529658,26.265237,28.313671,29.587236,21.877614,44.506259,25.200979,33.108333,43.921703,32.526328,21.130952,49.811837,37.585734,22.997085,22.997085]]}}}\n"
},
"headers": {
"content-type": "application/vnd.api+json"
},
"reason": "OK",
"status": 200
}
}
],
"scenario": "Timeseries query with top function metadata returns \"OK\" response",
"version": "v2"
},
{
"feature": "Metrics",
"frozen_at": "2026-10-13T19:38:48.794Z",
Expand Down
Loading