diff --git a/.apigentools-info b/.apigentools-info index eb99a48089e..3ab101731ee 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-04-10 19:45:03.769689", - "spec_repo_commit": "3fb610b5" + "regenerated": "2024-04-11 15:35:22.269841", + "spec_repo_commit": "8ffb168c" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-04-10 19:45:03.787823", - "spec_repo_commit": "3fb610b5" + "regenerated": "2024-04-11 15:35:22.287485", + "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/api/datadogV2/api_apm_retention_filters.go b/api/datadogV2/api_apm_retention_filters.go index 5de41d6ee9c..2c29d99c4ee 100644 --- a/api/datadogV2/api_apm_retention_filters.go +++ b/api/datadogV2/api_apm_retention_filters.go @@ -19,6 +19,8 @@ type APMRetentionFiltersApi datadog.Service // CreateApmRetentionFilter Create a retention filter. // 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. func (a *APMRetentionFiltersApi) CreateApmRetentionFilter(ctx _context.Context, body RetentionFilterCreateRequest) (RetentionFilterResponse, *_nethttp.Response, error) { var ( localVarHTTPMethod = _nethttp.MethodPost @@ -92,6 +94,8 @@ func (a *APMRetentionFiltersApi) CreateApmRetentionFilter(ctx _context.Context, // DeleteApmRetentionFilter Delete a retention filter. // Delete a specific retention filter from your organization. +// +// Default filters with types spans-errors-sampling-processor and spans-appsec-sampling-processor cannot be deleted. func (a *APMRetentionFiltersApi) DeleteApmRetentionFilter(ctx _context.Context, filterId string) (*_nethttp.Response, error) { var ( localVarHTTPMethod = _nethttp.MethodDelete @@ -357,6 +361,8 @@ func (a *APMRetentionFiltersApi) ReorderApmRetentionFilters(ctx _context.Context // UpdateApmRetentionFilter Update a retention filter. // 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. func (a *APMRetentionFiltersApi) UpdateApmRetentionFilter(ctx _context.Context, filterId string, body RetentionFilterUpdateRequest) (RetentionFilterResponse, *_nethttp.Response, error) { var ( localVarHTTPMethod = _nethttp.MethodPut diff --git a/api/datadogV2/model_retention_filter_update_attributes.go b/api/datadogV2/model_retention_filter_update_attributes.go new file mode 100644 index 00000000000..9ccb0d9e9a1 --- /dev/null +++ b/api/datadogV2/model_retention_filter_update_attributes.go @@ -0,0 +1,245 @@ +// 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 datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// RetentionFilterUpdateAttributes The object describing the configuration of the retention filter to create/update. +type RetentionFilterUpdateAttributes struct { + // Enable/Disable the retention filter. + Enabled bool `json:"enabled"` + // The spans filter. Spans matching this filter will be indexed and stored. + Filter SpansFilterCreate `json:"filter"` + // The type of retention filter. + FilterType RetentionFilterAllType `json:"filter_type"` + // The name of the retention filter. + Name string `json:"name"` + // Sample rate to apply to spans going through this retention filter, + // a value of 1.0 keeps all spans matching the query. + Rate float64 `json:"rate"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} +} + +// NewRetentionFilterUpdateAttributes instantiates a new RetentionFilterUpdateAttributes object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewRetentionFilterUpdateAttributes(enabled bool, filter SpansFilterCreate, filterType RetentionFilterAllType, name string, rate float64) *RetentionFilterUpdateAttributes { + this := RetentionFilterUpdateAttributes{} + this.Enabled = enabled + this.Filter = filter + this.FilterType = filterType + this.Name = name + this.Rate = rate + return &this +} + +// NewRetentionFilterUpdateAttributesWithDefaults instantiates a new RetentionFilterUpdateAttributes object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewRetentionFilterUpdateAttributesWithDefaults() *RetentionFilterUpdateAttributes { + this := RetentionFilterUpdateAttributes{} + var filterType RetentionFilterAllType = RETENTIONFILTERALLTYPE_SPANS_SAMPLING_PROCESSOR + this.FilterType = filterType + return &this +} + +// GetEnabled returns the Enabled field value. +func (o *RetentionFilterUpdateAttributes) GetEnabled() bool { + if o == nil { + var ret bool + return ret + } + return o.Enabled +} + +// GetEnabledOk returns a tuple with the Enabled field value +// and a boolean to check if the value has been set. +func (o *RetentionFilterUpdateAttributes) GetEnabledOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.Enabled, true +} + +// SetEnabled sets field value. +func (o *RetentionFilterUpdateAttributes) SetEnabled(v bool) { + o.Enabled = v +} + +// GetFilter returns the Filter field value. +func (o *RetentionFilterUpdateAttributes) GetFilter() SpansFilterCreate { + if o == nil { + var ret SpansFilterCreate + return ret + } + return o.Filter +} + +// GetFilterOk returns a tuple with the Filter field value +// and a boolean to check if the value has been set. +func (o *RetentionFilterUpdateAttributes) GetFilterOk() (*SpansFilterCreate, bool) { + if o == nil { + return nil, false + } + return &o.Filter, true +} + +// SetFilter sets field value. +func (o *RetentionFilterUpdateAttributes) SetFilter(v SpansFilterCreate) { + o.Filter = v +} + +// GetFilterType returns the FilterType field value. +func (o *RetentionFilterUpdateAttributes) GetFilterType() RetentionFilterAllType { + if o == nil { + var ret RetentionFilterAllType + return ret + } + return o.FilterType +} + +// GetFilterTypeOk returns a tuple with the FilterType field value +// and a boolean to check if the value has been set. +func (o *RetentionFilterUpdateAttributes) GetFilterTypeOk() (*RetentionFilterAllType, bool) { + if o == nil { + return nil, false + } + return &o.FilterType, true +} + +// SetFilterType sets field value. +func (o *RetentionFilterUpdateAttributes) SetFilterType(v RetentionFilterAllType) { + o.FilterType = v +} + +// GetName returns the Name field value. +func (o *RetentionFilterUpdateAttributes) GetName() string { + if o == nil { + var ret string + return ret + } + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *RetentionFilterUpdateAttributes) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value. +func (o *RetentionFilterUpdateAttributes) SetName(v string) { + o.Name = v +} + +// GetRate returns the Rate field value. +func (o *RetentionFilterUpdateAttributes) GetRate() float64 { + if o == nil { + var ret float64 + return ret + } + return o.Rate +} + +// GetRateOk returns a tuple with the Rate field value +// and a boolean to check if the value has been set. +func (o *RetentionFilterUpdateAttributes) GetRateOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.Rate, true +} + +// SetRate sets field value. +func (o *RetentionFilterUpdateAttributes) SetRate(v float64) { + o.Rate = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o RetentionFilterUpdateAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["enabled"] = o.Enabled + toSerialize["filter"] = o.Filter + toSerialize["filter_type"] = o.FilterType + toSerialize["name"] = o.Name + toSerialize["rate"] = o.Rate + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *RetentionFilterUpdateAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Enabled *bool `json:"enabled"` + Filter *SpansFilterCreate `json:"filter"` + FilterType *RetentionFilterAllType `json:"filter_type"` + Name *string `json:"name"` + Rate *float64 `json:"rate"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Enabled == nil { + return fmt.Errorf("required field enabled missing") + } + if all.Filter == nil { + return fmt.Errorf("required field filter missing") + } + if all.FilterType == nil { + return fmt.Errorf("required field filter_type missing") + } + if all.Name == nil { + return fmt.Errorf("required field name missing") + } + if all.Rate == nil { + return fmt.Errorf("required field rate missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"enabled", "filter", "filter_type", "name", "rate"}) + } else { + return err + } + + hasInvalidField := false + o.Enabled = *all.Enabled + if all.Filter.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Filter = *all.Filter + if !all.FilterType.IsValid() { + hasInvalidField = true + } else { + o.FilterType = *all.FilterType + } + o.Name = *all.Name + o.Rate = *all.Rate + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_retention_filter_update_data.go b/api/datadogV2/model_retention_filter_update_data.go index db33856dcdb..c3e8ed27475 100644 --- a/api/datadogV2/model_retention_filter_update_data.go +++ b/api/datadogV2/model_retention_filter_update_data.go @@ -13,7 +13,7 @@ import ( // RetentionFilterUpdateData The body of the retention filter to be updated. type RetentionFilterUpdateData struct { // The object describing the configuration of the retention filter to create/update. - Attributes RetentionFilterCreateAttributes `json:"attributes"` + Attributes RetentionFilterUpdateAttributes `json:"attributes"` // The ID of the retention filter. Id string `json:"id"` // The type of the resource. @@ -27,7 +27,7 @@ type RetentionFilterUpdateData struct { // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed. -func NewRetentionFilterUpdateData(attributes RetentionFilterCreateAttributes, id string, typeVar ApmRetentionFilterType) *RetentionFilterUpdateData { +func NewRetentionFilterUpdateData(attributes RetentionFilterUpdateAttributes, id string, typeVar ApmRetentionFilterType) *RetentionFilterUpdateData { this := RetentionFilterUpdateData{} this.Attributes = attributes this.Id = id @@ -46,9 +46,9 @@ func NewRetentionFilterUpdateDataWithDefaults() *RetentionFilterUpdateData { } // GetAttributes returns the Attributes field value. -func (o *RetentionFilterUpdateData) GetAttributes() RetentionFilterCreateAttributes { +func (o *RetentionFilterUpdateData) GetAttributes() RetentionFilterUpdateAttributes { if o == nil { - var ret RetentionFilterCreateAttributes + var ret RetentionFilterUpdateAttributes return ret } return o.Attributes @@ -56,7 +56,7 @@ func (o *RetentionFilterUpdateData) GetAttributes() RetentionFilterCreateAttribu // GetAttributesOk returns a tuple with the Attributes field value // and a boolean to check if the value has been set. -func (o *RetentionFilterUpdateData) GetAttributesOk() (*RetentionFilterCreateAttributes, bool) { +func (o *RetentionFilterUpdateData) GetAttributesOk() (*RetentionFilterUpdateAttributes, bool) { if o == nil { return nil, false } @@ -64,7 +64,7 @@ func (o *RetentionFilterUpdateData) GetAttributesOk() (*RetentionFilterCreateAtt } // SetAttributes sets field value. -func (o *RetentionFilterUpdateData) SetAttributes(v RetentionFilterCreateAttributes) { +func (o *RetentionFilterUpdateData) SetAttributes(v RetentionFilterUpdateAttributes) { o.Attributes = v } @@ -133,7 +133,7 @@ func (o RetentionFilterUpdateData) MarshalJSON() ([]byte, error) { // UnmarshalJSON deserializes the given payload. func (o *RetentionFilterUpdateData) UnmarshalJSON(bytes []byte) (err error) { all := struct { - Attributes *RetentionFilterCreateAttributes `json:"attributes"` + Attributes *RetentionFilterUpdateAttributes `json:"attributes"` Id *string `json:"id"` Type *ApmRetentionFilterType `json:"type"` }{} diff --git a/examples/v2/apm-retention-filters/UpdateApmRetentionFilter.go b/examples/v2/apm-retention-filters/UpdateApmRetentionFilter.go index 16ab45cc32b..eddcd20d4d5 100644 --- a/examples/v2/apm-retention-filters/UpdateApmRetentionFilter.go +++ b/examples/v2/apm-retention-filters/UpdateApmRetentionFilter.go @@ -18,14 +18,14 @@ func main() { body := datadogV2.RetentionFilterUpdateRequest{ Data: datadogV2.RetentionFilterUpdateData{ - Attributes: datadogV2.RetentionFilterCreateAttributes{ + Attributes: datadogV2.RetentionFilterUpdateAttributes{ Name: "test", Rate: 0.9, Filter: datadogV2.SpansFilterCreate{ Query: "@_top_level:1 test:service-demo", }, Enabled: true, - FilterType: datadogV2.RETENTIONFILTERTYPE_SPANS_SAMPLING_PROCESSOR, + FilterType: datadogV2.RETENTIONFILTERALLTYPE_SPANS_SAMPLING_PROCESSOR, }, Id: "test-id", Type: datadogV2.APMRETENTIONFILTERTYPE_apm_retention_filter, diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_APM_Retention_Filters/Scenario_Create_a_default_retention_filter_returns_Bad_Request_response.freeze b/tests/scenarios/cassettes/TestScenarios/v2/Feature_APM_Retention_Filters/Scenario_Create_a_default_retention_filter_returns_Bad_Request_response.freeze new file mode 100644 index 00000000000..1e99caa9b43 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_APM_Retention_Filters/Scenario_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/tests/scenarios/cassettes/TestScenarios/v2/Feature_APM_Retention_Filters/Scenario_Create_a_default_retention_filter_returns_Bad_Request_response.yaml b/tests/scenarios/cassettes/TestScenarios/v2/Feature_APM_Retention_Filters/Scenario_Create_a_default_retention_filter_returns_Bad_Request_response.yaml new file mode 100644 index 00000000000..4ebd66e44d1 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_APM_Retention_Filters/Scenario_Create_a_default_retention_filter_returns_Bad_Request_response.yaml @@ -0,0 +1,22 @@ +interactions: +- request: + body: | + {"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"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: POST + url: https://api.datadoghq.com/api/v2/apm/config/retention-filters + response: + body: '{"errors":["Field ''filter_type'' is invalid, expected value is ''spans-sampling-processor''"]}' + code: 400 + duration: 0ms + headers: + Content-Type: + - application/json + status: 400 Bad Request +version: 2 diff --git a/tests/scenarios/features/v2/apm_retention_filters.feature b/tests/scenarios/features/v2/apm_retention_filters.feature index e88870c76da..e68470157dd 100644 --- a/tests/scenarios/features/v2/apm_retention_filters.feature +++ b/tests/scenarios/features/v2/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