|
| 1 | +// Create a tag indexing rule returns "Created" 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.TagIndexingRuleCreateAttributes; |
| 7 | +import com.datadog.api.client.v2.model.TagIndexingRuleCreateData; |
| 8 | +import com.datadog.api.client.v2.model.TagIndexingRuleCreateRequest; |
| 9 | +import com.datadog.api.client.v2.model.TagIndexingRuleDynamicTags; |
| 10 | +import com.datadog.api.client.v2.model.TagIndexingRuleMetricMatch; |
| 11 | +import com.datadog.api.client.v2.model.TagIndexingRuleOptions; |
| 12 | +import com.datadog.api.client.v2.model.TagIndexingRuleOptionsData; |
| 13 | +import com.datadog.api.client.v2.model.TagIndexingRuleResponse; |
| 14 | +import com.datadog.api.client.v2.model.TagIndexingRuleType; |
| 15 | +import java.util.Arrays; |
| 16 | +import java.util.Collections; |
| 17 | + |
| 18 | +public class Example { |
| 19 | + public static void main(String[] args) { |
| 20 | + ApiClient defaultClient = ApiClient.getDefaultApiClient(); |
| 21 | + MetricsApi apiInstance = new MetricsApi(defaultClient); |
| 22 | + |
| 23 | + TagIndexingRuleCreateRequest body = |
| 24 | + new TagIndexingRuleCreateRequest() |
| 25 | + .data( |
| 26 | + new TagIndexingRuleCreateData() |
| 27 | + .attributes( |
| 28 | + new TagIndexingRuleCreateAttributes() |
| 29 | + .excludeTagsMode(false) |
| 30 | + .metricNameMatches(Collections.singletonList("dd.test.*")) |
| 31 | + .name("my-indexing-rule") |
| 32 | + .options( |
| 33 | + new TagIndexingRuleOptions() |
| 34 | + .data( |
| 35 | + new TagIndexingRuleOptionsData() |
| 36 | + .dynamicTags( |
| 37 | + new TagIndexingRuleDynamicTags() |
| 38 | + .queriedTagsWindowSeconds(3600L) |
| 39 | + .relatedAssetTags(false)) |
| 40 | + .managePreexistingMetrics(true) |
| 41 | + .metricMatch( |
| 42 | + new TagIndexingRuleMetricMatch() |
| 43 | + .queriedWindowSeconds(3600L)) |
| 44 | + .overridePreviousRules(false)) |
| 45 | + .version(1L)) |
| 46 | + .tags(Arrays.asList("env", "service"))) |
| 47 | + .type(TagIndexingRuleType.TAG_INDEXING_RULES)); |
| 48 | + |
| 49 | + try { |
| 50 | + TagIndexingRuleResponse result = apiInstance.createTagIndexingRule(body); |
| 51 | + System.out.println(result); |
| 52 | + } catch (ApiException e) { |
| 53 | + System.err.println("Exception when calling MetricsApi#createTagIndexingRule"); |
| 54 | + System.err.println("Status code: " + e.getCode()); |
| 55 | + System.err.println("Reason: " + e.getResponseBody()); |
| 56 | + System.err.println("Response headers: " + e.getResponseHeaders()); |
| 57 | + e.printStackTrace(); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments