|
| 1 | +// Scalar cross product query with apm_resource_stats data source returns "OK" response |
| 2 | + |
| 3 | +import com.datadog.api.client.ApiClient; |
| 4 | +import com.datadog.api.client.ApiException; |
| 5 | +import com.datadog.api.client.v2.api.MetricsApi; |
| 6 | +import com.datadog.api.client.v2.model.ApmResourceStatName; |
| 7 | +import com.datadog.api.client.v2.model.ApmResourceStatsDataSource; |
| 8 | +import com.datadog.api.client.v2.model.ApmResourceStatsQuery; |
| 9 | +import com.datadog.api.client.v2.model.FormulaLimit; |
| 10 | +import com.datadog.api.client.v2.model.QueryFormula; |
| 11 | +import com.datadog.api.client.v2.model.QuerySortOrder; |
| 12 | +import com.datadog.api.client.v2.model.ScalarFormulaQueryRequest; |
| 13 | +import com.datadog.api.client.v2.model.ScalarFormulaQueryResponse; |
| 14 | +import com.datadog.api.client.v2.model.ScalarFormulaRequest; |
| 15 | +import com.datadog.api.client.v2.model.ScalarFormulaRequestAttributes; |
| 16 | +import com.datadog.api.client.v2.model.ScalarFormulaRequestType; |
| 17 | +import com.datadog.api.client.v2.model.ScalarQuery; |
| 18 | +import java.util.Collections; |
| 19 | + |
| 20 | +public class Example { |
| 21 | + public static void main(String[] args) { |
| 22 | + ApiClient defaultClient = ApiClient.getDefaultApiClient(); |
| 23 | + MetricsApi apiInstance = new MetricsApi(defaultClient); |
| 24 | + |
| 25 | + ScalarFormulaQueryRequest body = |
| 26 | + new ScalarFormulaQueryRequest() |
| 27 | + .data( |
| 28 | + new ScalarFormulaRequest() |
| 29 | + .attributes( |
| 30 | + new ScalarFormulaRequestAttributes() |
| 31 | + .formulas( |
| 32 | + Collections.singletonList( |
| 33 | + new QueryFormula() |
| 34 | + .formula("a") |
| 35 | + .limit( |
| 36 | + new FormulaLimit() |
| 37 | + .count(10) |
| 38 | + .order(QuerySortOrder.DESC)))) |
| 39 | + .from(1636625471000L) |
| 40 | + .queries( |
| 41 | + Collections.singletonList( |
| 42 | + new ScalarQuery( |
| 43 | + new ApmResourceStatsQuery() |
| 44 | + .dataSource( |
| 45 | + ApmResourceStatsDataSource.APM_RESOURCE_STATS) |
| 46 | + .name("a") |
| 47 | + .env("staging") |
| 48 | + .service("azure-bill-import") |
| 49 | + .stat(ApmResourceStatName.HITS) |
| 50 | + .operationName("cassandra.query") |
| 51 | + .groupBy(Collections.singletonList("resource_name")) |
| 52 | + .primaryTagName("datacenter") |
| 53 | + .primaryTagValue("*")))) |
| 54 | + .to(1636629071000L)) |
| 55 | + .type(ScalarFormulaRequestType.SCALAR_REQUEST)); |
| 56 | + |
| 57 | + try { |
| 58 | + ScalarFormulaQueryResponse result = apiInstance.queryScalarData(body); |
| 59 | + System.out.println(result); |
| 60 | + } catch (ApiException e) { |
| 61 | + System.err.println("Exception when calling MetricsApi#queryScalarData"); |
| 62 | + System.err.println("Status code: " + e.getCode()); |
| 63 | + System.err.println("Reason: " + e.getResponseBody()); |
| 64 | + System.err.println("Response headers: " + e.getResponseHeaders()); |
| 65 | + e.printStackTrace(); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments