From f43626d65e223b0b165a84938bfd6e71daa94043 Mon Sep 17 00:00:00 2001 From: "api-clients-generation-pipeline[bot]" <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:19:06 +0000 Subject: [PATCH] Update retention filters public API (#2263) Co-authored-by: ci.datadog-api-spec Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> --- .apigentools-info | 8 +- .generator/schemas/v2/openapi.yaml | 52 +++- .../UpdateApmRetentionFilter.java | 8 +- .../client/v2/api/ApmRetentionFiltersApi.java | 9 + .../RetentionFilterUpdateAttributes.java | 268 ++++++++++++++++++ .../v2/model/RetentionFilterUpdateData.java | 10 +- ...filter_returns_Bad_Request_response.freeze | 1 + ...n_filter_returns_Bad_Request_response.json | 32 +++ .../v2/api/apm_retention_filters.feature | 7 + 9 files changed, 378 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/datadog/api/client/v2/model/RetentionFilterUpdateAttributes.java create mode 100644 src/test/resources/cassettes/features/v2/Create_a_default_retention_filter_returns_Bad_Request_response.freeze create mode 100644 src/test/resources/cassettes/features/v2/Create_a_default_retention_filter_returns_Bad_Request_response.json diff --git a/.apigentools-info b/.apigentools-info index 6720eb538f5..fc19793056f 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-04-10 19:44:53.237097", - "spec_repo_commit": "3fb610b5" + "regenerated": "2024-04-11 15:35:28.968495", + "spec_repo_commit": "8ffb168c" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-04-10 19:44:53.256577", - "spec_repo_commit": "3fb610b5" + "regenerated": "2024-04-11 15:35:28.986152", + "spec_repo_commit": "8ffb168c" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 90e25751f7f..5b5588fa263 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -16072,6 +16072,7 @@ components: - spans-sampling-processor - spans-errors-sampling-processor - spans-appsec-sampling-processor + example: spans-sampling-processor type: string x-enum-varnames: - SPANS_SAMPLING_PROCESSOR @@ -16188,11 +16189,42 @@ components: type: string x-enum-varnames: - SPANS_SAMPLING_PROCESSOR + RetentionFilterUpdateAttributes: + description: The object describing the configuration of the retention filter + to create/update. + properties: + enabled: + description: Enable/Disable the retention filter. + example: true + type: boolean + filter: + $ref: '#/components/schemas/SpansFilterCreate' + filter_type: + $ref: '#/components/schemas/RetentionFilterAllType' + name: + description: The name of the retention filter. + example: my retention filter + type: string + rate: + description: 'Sample rate to apply to spans going through this retention + filter, + + a value of 1.0 keeps all spans matching the query.' + example: 1.0 + format: double + type: number + required: + - name + - filter + - enabled + - filter_type + - rate + type: object RetentionFilterUpdateData: description: The body of the retention filter to be updated. properties: attributes: - $ref: '#/components/schemas/RetentionFilterCreateAttributes' + $ref: '#/components/schemas/RetentionFilterUpdateAttributes' id: description: The ID of the retention filter. example: retention-filter-id @@ -23271,7 +23303,11 @@ paths: post: description: 'Create a retention filter to index spans in your organization. - Returns the retention filter definition when the request is successful.' + Returns the retention filter definition when the request is successful. + + + Default filters with types spans-errors-sampling-processor and spans-appsec-sampling-processor + cannot be created.' operationId: CreateApmRetentionFilter requestBody: content: @@ -23325,7 +23361,11 @@ paths: x-codegen-request-body-name: body /api/v2/apm/config/retention-filters/{filter_id}: delete: - description: Delete a specific retention filter from your organization. + description: 'Delete a specific retention filter from your organization. + + + Default filters with types spans-errors-sampling-processor and spans-appsec-sampling-processor + cannot be deleted.' operationId: DeleteApmRetentionFilter parameters: - $ref: '#/components/parameters/RetentionFilterIdParam' @@ -23363,7 +23403,11 @@ paths: tags: - APM Retention Filters put: - description: Update a retention filter from your organization. + description: 'Update a retention filter from your organization. + + + Default filters (filters with types spans-errors-sampling-processor and spans-appsec-sampling-processor) + cannot be renamed or removed.' operationId: UpdateApmRetentionFilter parameters: - $ref: '#/components/parameters/RetentionFilterIdParam' diff --git a/examples/v2/apm-retention-filters/UpdateApmRetentionFilter.java b/examples/v2/apm-retention-filters/UpdateApmRetentionFilter.java index dad498fb71a..683ea137f43 100644 --- a/examples/v2/apm-retention-filters/UpdateApmRetentionFilter.java +++ b/examples/v2/apm-retention-filters/UpdateApmRetentionFilter.java @@ -4,9 +4,9 @@ import com.datadog.api.client.ApiException; import com.datadog.api.client.v2.api.ApmRetentionFiltersApi; import com.datadog.api.client.v2.model.ApmRetentionFilterType; -import com.datadog.api.client.v2.model.RetentionFilterCreateAttributes; +import com.datadog.api.client.v2.model.RetentionFilterAllType; import com.datadog.api.client.v2.model.RetentionFilterResponse; -import com.datadog.api.client.v2.model.RetentionFilterType; +import com.datadog.api.client.v2.model.RetentionFilterUpdateAttributes; import com.datadog.api.client.v2.model.RetentionFilterUpdateData; import com.datadog.api.client.v2.model.RetentionFilterUpdateRequest; import com.datadog.api.client.v2.model.SpansFilterCreate; @@ -24,13 +24,13 @@ public static void main(String[] args) { .data( new RetentionFilterUpdateData() .attributes( - new RetentionFilterCreateAttributes() + new RetentionFilterUpdateAttributes() .name("test") .rate(0.9) .filter( new SpansFilterCreate().query("@_top_level:1 test:service-demo")) .enabled(true) - .filterType(RetentionFilterType.SPANS_SAMPLING_PROCESSOR)) + .filterType(RetentionFilterAllType.SPANS_SAMPLING_PROCESSOR)) .id("test-id") .type(ApmRetentionFilterType.apm_retention_filter)); diff --git a/src/main/java/com/datadog/api/client/v2/api/ApmRetentionFiltersApi.java b/src/main/java/com/datadog/api/client/v2/api/ApmRetentionFiltersApi.java index 816f54c90f1..82cec1a4598 100644 --- a/src/main/java/com/datadog/api/client/v2/api/ApmRetentionFiltersApi.java +++ b/src/main/java/com/datadog/api/client/v2/api/ApmRetentionFiltersApi.java @@ -82,6 +82,9 @@ public CompletableFuture createApmRetentionFilterAsync( * Create a retention filter to index spans in your organization. Returns the retention filter * definition when the request is successful. * + *

Default filters with types spans-errors-sampling-processor and + * spans-appsec-sampling-processor cannot be created. + * * @param body The definition of the new retention filter. (required) * @return ApiResponse<RetentionFilterResponse> * @throws ApiException if fails to make API call @@ -213,6 +216,9 @@ public CompletableFuture deleteApmRetentionFilterAsync(String filterId) { /** * Delete a specific retention filter from your organization. * + *

Default filters with types spans-errors-sampling-processor and + * spans-appsec-sampling-processor cannot be deleted. + * * @param filterId The ID of the retention filter. (required) * @return ApiResponse<Void> * @throws ApiException if fails to make API call @@ -731,6 +737,9 @@ public CompletableFuture updateApmRetentionFilterAsync( /** * Update a retention filter from your organization. * + *

Default filters (filters with types spans-errors-sampling-processor and + * spans-appsec-sampling-processor) cannot be renamed or removed. + * * @param filterId The ID of the retention filter. (required) * @param body The updated definition of the retention filter. (required) * @return ApiResponse<RetentionFilterResponse> diff --git a/src/main/java/com/datadog/api/client/v2/model/RetentionFilterUpdateAttributes.java b/src/main/java/com/datadog/api/client/v2/model/RetentionFilterUpdateAttributes.java new file mode 100644 index 00000000000..0e85875caed --- /dev/null +++ b/src/main/java/com/datadog/api/client/v2/model/RetentionFilterUpdateAttributes.java @@ -0,0 +1,268 @@ +/* + * 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 2019-Present Datadog, Inc. + */ + +package com.datadog.api.client.v2.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** The object describing the configuration of the retention filter to create/update. */ +@JsonPropertyOrder({ + RetentionFilterUpdateAttributes.JSON_PROPERTY_ENABLED, + RetentionFilterUpdateAttributes.JSON_PROPERTY_FILTER, + RetentionFilterUpdateAttributes.JSON_PROPERTY_FILTER_TYPE, + RetentionFilterUpdateAttributes.JSON_PROPERTY_NAME, + RetentionFilterUpdateAttributes.JSON_PROPERTY_RATE +}) +@jakarta.annotation.Generated( + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") +public class RetentionFilterUpdateAttributes { + @JsonIgnore public boolean unparsed = false; + public static final String JSON_PROPERTY_ENABLED = "enabled"; + private Boolean enabled; + + public static final String JSON_PROPERTY_FILTER = "filter"; + private SpansFilterCreate filter; + + public static final String JSON_PROPERTY_FILTER_TYPE = "filter_type"; + private RetentionFilterAllType filterType = RetentionFilterAllType.SPANS_SAMPLING_PROCESSOR; + + public static final String JSON_PROPERTY_NAME = "name"; + private String name; + + public static final String JSON_PROPERTY_RATE = "rate"; + private Double rate; + + public RetentionFilterUpdateAttributes() {} + + @JsonCreator + public RetentionFilterUpdateAttributes( + @JsonProperty(required = true, value = JSON_PROPERTY_ENABLED) Boolean enabled, + @JsonProperty(required = true, value = JSON_PROPERTY_FILTER) SpansFilterCreate filter, + @JsonProperty(required = true, value = JSON_PROPERTY_FILTER_TYPE) + RetentionFilterAllType filterType, + @JsonProperty(required = true, value = JSON_PROPERTY_NAME) String name, + @JsonProperty(required = true, value = JSON_PROPERTY_RATE) Double rate) { + this.enabled = enabled; + this.filter = filter; + this.unparsed |= filter.unparsed; + this.filterType = filterType; + this.unparsed |= !filterType.isValid(); + this.name = name; + this.rate = rate; + } + + public RetentionFilterUpdateAttributes enabled(Boolean enabled) { + this.enabled = enabled; + return this; + } + + /** + * Enable/Disable the retention filter. + * + * @return enabled + */ + @JsonProperty(JSON_PROPERTY_ENABLED) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public RetentionFilterUpdateAttributes filter(SpansFilterCreate filter) { + this.filter = filter; + this.unparsed |= filter.unparsed; + return this; + } + + /** + * The spans filter. Spans matching this filter will be indexed and stored. + * + * @return filter + */ + @JsonProperty(JSON_PROPERTY_FILTER) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public SpansFilterCreate getFilter() { + return filter; + } + + public void setFilter(SpansFilterCreate filter) { + this.filter = filter; + } + + public RetentionFilterUpdateAttributes filterType(RetentionFilterAllType filterType) { + this.filterType = filterType; + this.unparsed |= !filterType.isValid(); + return this; + } + + /** + * The type of retention filter. + * + * @return filterType + */ + @JsonProperty(JSON_PROPERTY_FILTER_TYPE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public RetentionFilterAllType getFilterType() { + return filterType; + } + + public void setFilterType(RetentionFilterAllType filterType) { + if (!filterType.isValid()) { + this.unparsed = true; + } + this.filterType = filterType; + } + + public RetentionFilterUpdateAttributes name(String name) { + this.name = name; + return this; + } + + /** + * The name of the retention filter. + * + * @return name + */ + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public RetentionFilterUpdateAttributes rate(Double rate) { + this.rate = rate; + return this; + } + + /** + * Sample rate to apply to spans going through this retention filter, a value of 1.0 keeps all + * spans matching the query. + * + * @return rate + */ + @JsonProperty(JSON_PROPERTY_RATE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public Double getRate() { + return rate; + } + + public void setRate(Double rate) { + this.rate = rate; + } + + /** + * A container for additional, undeclared properties. This is a holder for any undeclared + * properties as specified with the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. If the property + * does not already exist, create it otherwise replace it. + * + * @param key The arbitrary key to set + * @param value The associated value + * @return RetentionFilterUpdateAttributes + */ + @JsonAnySetter + public RetentionFilterUpdateAttributes putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return The additional properties + */ + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key The arbitrary key to get + * @return The specific additional property for the given key + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + /** Return true if this RetentionFilterUpdateAttributes object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RetentionFilterUpdateAttributes retentionFilterUpdateAttributes = + (RetentionFilterUpdateAttributes) o; + return Objects.equals(this.enabled, retentionFilterUpdateAttributes.enabled) + && Objects.equals(this.filter, retentionFilterUpdateAttributes.filter) + && Objects.equals(this.filterType, retentionFilterUpdateAttributes.filterType) + && Objects.equals(this.name, retentionFilterUpdateAttributes.name) + && Objects.equals(this.rate, retentionFilterUpdateAttributes.rate) + && Objects.equals( + this.additionalProperties, retentionFilterUpdateAttributes.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(enabled, filter, filterType, name, rate, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class RetentionFilterUpdateAttributes {\n"); + sb.append(" enabled: ").append(toIndentedString(enabled)).append("\n"); + sb.append(" filter: ").append(toIndentedString(filter)).append("\n"); + sb.append(" filterType: ").append(toIndentedString(filterType)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" rate: ").append(toIndentedString(rate)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append('}'); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/src/main/java/com/datadog/api/client/v2/model/RetentionFilterUpdateData.java b/src/main/java/com/datadog/api/client/v2/model/RetentionFilterUpdateData.java index faf24dd677e..5424e051ba9 100644 --- a/src/main/java/com/datadog/api/client/v2/model/RetentionFilterUpdateData.java +++ b/src/main/java/com/datadog/api/client/v2/model/RetentionFilterUpdateData.java @@ -28,7 +28,7 @@ public class RetentionFilterUpdateData { @JsonIgnore public boolean unparsed = false; public static final String JSON_PROPERTY_ATTRIBUTES = "attributes"; - private RetentionFilterCreateAttributes attributes; + private RetentionFilterUpdateAttributes attributes; public static final String JSON_PROPERTY_ID = "id"; private String id; @@ -41,7 +41,7 @@ public RetentionFilterUpdateData() {} @JsonCreator public RetentionFilterUpdateData( @JsonProperty(required = true, value = JSON_PROPERTY_ATTRIBUTES) - RetentionFilterCreateAttributes attributes, + RetentionFilterUpdateAttributes attributes, @JsonProperty(required = true, value = JSON_PROPERTY_ID) String id, @JsonProperty(required = true, value = JSON_PROPERTY_TYPE) ApmRetentionFilterType type) { this.attributes = attributes; @@ -51,7 +51,7 @@ public RetentionFilterUpdateData( this.unparsed |= !type.isValid(); } - public RetentionFilterUpdateData attributes(RetentionFilterCreateAttributes attributes) { + public RetentionFilterUpdateData attributes(RetentionFilterUpdateAttributes attributes) { this.attributes = attributes; this.unparsed |= attributes.unparsed; return this; @@ -64,11 +64,11 @@ public RetentionFilterUpdateData attributes(RetentionFilterCreateAttributes attr */ @JsonProperty(JSON_PROPERTY_ATTRIBUTES) @JsonInclude(value = JsonInclude.Include.ALWAYS) - public RetentionFilterCreateAttributes getAttributes() { + public RetentionFilterUpdateAttributes getAttributes() { return attributes; } - public void setAttributes(RetentionFilterCreateAttributes attributes) { + public void setAttributes(RetentionFilterUpdateAttributes attributes) { this.attributes = attributes; } diff --git a/src/test/resources/cassettes/features/v2/Create_a_default_retention_filter_returns_Bad_Request_response.freeze b/src/test/resources/cassettes/features/v2/Create_a_default_retention_filter_returns_Bad_Request_response.freeze new file mode 100644 index 00000000000..1e99caa9b43 --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Create_a_default_retention_filter_returns_Bad_Request_response.freeze @@ -0,0 +1 @@ +2024-04-10T12:31:19.300Z \ No newline at end of file diff --git a/src/test/resources/cassettes/features/v2/Create_a_default_retention_filter_returns_Bad_Request_response.json b/src/test/resources/cassettes/features/v2/Create_a_default_retention_filter_returns_Bad_Request_response.json new file mode 100644 index 00000000000..9101353e877 --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Create_a_default_retention_filter_returns_Bad_Request_response.json @@ -0,0 +1,32 @@ +[ + { + "httpRequest": { + "body": { + "type": "JSON", + "json": "{\"data\":{\"attributes\":{\"enabled\":true,\"filter\":{\"query\":\"@http.status_code:200 service:my-service\"},\"filter_type\":\"spans-errors-sampling-processor\",\"name\":\"my retention filter\",\"rate\":1},\"type\":\"apm_retention_filter\"}}" + }, + "headers": {}, + "method": "POST", + "path": "/api/v2/apm/config/retention-filters", + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "body": "{\"errors\":[\"Field 'filter_type' is invalid, expected value is 'spans-sampling-processor'\"]}", + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "statusCode": 400, + "reasonPhrase": "Bad Request" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "23cb9ef5-03c9-1078-cfb5-4a6f43add906" + } +] \ No newline at end of file diff --git a/src/test/resources/com/datadog/api/client/v2/api/apm_retention_filters.feature b/src/test/resources/com/datadog/api/client/v2/api/apm_retention_filters.feature index e88870c76da..e68470157dd 100644 --- a/src/test/resources/com/datadog/api/client/v2/api/apm_retention_filters.feature +++ b/src/test/resources/com/datadog/api/client/v2/api/apm_retention_filters.feature @@ -12,6 +12,13 @@ Feature: APM Retention Filters And a valid "appKeyAuth" key in the system And an instance of "APMRetentionFilters" API + @team:DataDog/apm-trace-intake + Scenario: Create a default retention filter returns "Bad Request" response + Given new "CreateApmRetentionFilter" request + And body with value {"data": {"attributes": {"enabled": true, "filter": {"query": "@http.status_code:200 service:my-service"}, "filter_type": "spans-errors-sampling-processor", "name": "my retention filter", "rate": 1.0}, "type": "apm_retention_filter"}} + When the request is sent + Then the response status is 400 Bad Request + @team:DataDog/apm-trace-intake Scenario: Create a retention filter returns "Bad Request" response Given new "CreateApmRetentionFilter" request