Skip to content

Commit b0b19ca

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add sample_attribute to log exclusion filter (#3861)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent a74ee2c commit b0b19ca

6 files changed

Lines changed: 58 additions & 14 deletions

File tree

.generator/schemas/v1/openapi.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5931,6 +5931,12 @@ components:
59315931
Scope down exclusion filter to only a subset of logs with a log query.
59325932
example: "*"
59335933
type: string
5934+
sample_attribute:
5935+
description: |-
5936+
Sample attribute to use for the sampling of logs going through this exclusion filter.
5937+
When set, only the logs with the specified attribute are sampled.
5938+
example: "@ci.job_id"
5939+
type: string
59345940
sample_rate:
59355941
description: |-
59365942
Sample rate to apply to logs going through this exclusion filter,
@@ -29896,7 +29902,7 @@ paths:
2989629902
Update an index as identified by its name.
2989729903
Returns the Index object passed in the request body when the request is successful.
2989829904

29899-
Using the `PUT` method updates your indexs configuration by **replacing**
29905+
Using the `PUT` method updates your index's configuration by **replacing**
2990029906
your current configuration with the new one sent to your Datadog organization.
2990129907
operationId: UpdateLogsIndex
2990229908
parameters:

api/datadogV1/api_logs_indexes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (a *LogsIndexesApi) ListLogIndexes(ctx _context.Context) (LogsIndexListResp
437437
// Update an index as identified by its name.
438438
// Returns the Index object passed in the request body when the request is successful.
439439
//
440-
// Using the `PUT` method updates your indexs configuration by **replacing**
440+
// Using the `PUT` method updates your index's configuration by **replacing**
441441
// your current configuration with the new one sent to your Datadog organization.
442442
func (a *LogsIndexesApi) UpdateLogsIndex(ctx _context.Context, name string, body LogsIndexUpdateRequest) (LogsIndex, *_nethttp.Response, error) {
443443
var (

api/datadogV1/model_logs_exclusion_filter.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ type LogsExclusionFilter struct {
1515
// Default query is `*`, meaning all logs flowing in the index would be excluded.
1616
// Scope down exclusion filter to only a subset of logs with a log query.
1717
Query *string `json:"query,omitempty"`
18+
// Sample attribute to use for the sampling of logs going through this exclusion filter.
19+
// When set, only the logs with the specified attribute are sampled.
20+
SampleAttribute *string `json:"sample_attribute,omitempty"`
1821
// Sample rate to apply to logs going through this exclusion filter,
1922
// a value of 1.0 excludes all logs matching the query.
2023
SampleRate float64 `json:"sample_rate"`
@@ -69,6 +72,34 @@ func (o *LogsExclusionFilter) SetQuery(v string) {
6972
o.Query = &v
7073
}
7174

75+
// GetSampleAttribute returns the SampleAttribute field value if set, zero value otherwise.
76+
func (o *LogsExclusionFilter) GetSampleAttribute() string {
77+
if o == nil || o.SampleAttribute == nil {
78+
var ret string
79+
return ret
80+
}
81+
return *o.SampleAttribute
82+
}
83+
84+
// GetSampleAttributeOk returns a tuple with the SampleAttribute field value if set, nil otherwise
85+
// and a boolean to check if the value has been set.
86+
func (o *LogsExclusionFilter) GetSampleAttributeOk() (*string, bool) {
87+
if o == nil || o.SampleAttribute == nil {
88+
return nil, false
89+
}
90+
return o.SampleAttribute, true
91+
}
92+
93+
// HasSampleAttribute returns a boolean if a field has been set.
94+
func (o *LogsExclusionFilter) HasSampleAttribute() bool {
95+
return o != nil && o.SampleAttribute != nil
96+
}
97+
98+
// SetSampleAttribute gets a reference to the given string and assigns it to the SampleAttribute field.
99+
func (o *LogsExclusionFilter) SetSampleAttribute(v string) {
100+
o.SampleAttribute = &v
101+
}
102+
72103
// GetSampleRate returns the SampleRate field value.
73104
func (o *LogsExclusionFilter) GetSampleRate() float64 {
74105
if o == nil {
@@ -101,6 +132,9 @@ func (o LogsExclusionFilter) MarshalJSON() ([]byte, error) {
101132
if o.Query != nil {
102133
toSerialize["query"] = o.Query
103134
}
135+
if o.SampleAttribute != nil {
136+
toSerialize["sample_attribute"] = o.SampleAttribute
137+
}
104138
toSerialize["sample_rate"] = o.SampleRate
105139

106140
for key, value := range o.AdditionalProperties {
@@ -112,8 +146,9 @@ func (o LogsExclusionFilter) MarshalJSON() ([]byte, error) {
112146
// UnmarshalJSON deserializes the given payload.
113147
func (o *LogsExclusionFilter) UnmarshalJSON(bytes []byte) (err error) {
114148
all := struct {
115-
Query *string `json:"query,omitempty"`
116-
SampleRate *float64 `json:"sample_rate"`
149+
Query *string `json:"query,omitempty"`
150+
SampleAttribute *string `json:"sample_attribute,omitempty"`
151+
SampleRate *float64 `json:"sample_rate"`
117152
}{}
118153
if err = datadog.Unmarshal(bytes, &all); err != nil {
119154
return datadog.Unmarshal(bytes, &o.UnparsedObject)
@@ -123,11 +158,12 @@ func (o *LogsExclusionFilter) UnmarshalJSON(bytes []byte) (err error) {
123158
}
124159
additionalProperties := make(map[string]interface{})
125160
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
126-
datadog.DeleteKeys(additionalProperties, &[]string{"query", "sample_rate"})
161+
datadog.DeleteKeys(additionalProperties, &[]string{"query", "sample_attribute", "sample_rate"})
127162
} else {
128163
return err
129164
}
130165
o.Query = all.Query
166+
o.SampleAttribute = all.SampleAttribute
131167
o.SampleRate = *all.SampleRate
132168

133169
if len(additionalProperties) > 0 {

examples/v1/logs-indexes/CreateLogsIndex.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ func main() {
2323
ExclusionFilters: []datadogV1.LogsExclusion{
2424
{
2525
Filter: &datadogV1.LogsExclusionFilter{
26-
Query: datadog.PtrString("*"),
27-
SampleRate: 1.0,
26+
Query: datadog.PtrString("*"),
27+
SampleAttribute: datadog.PtrString("@ci.job_id"),
28+
SampleRate: 1.0,
2829
},
2930
Name: "payment",
3031
},

examples/v1/logs-indexes/UpdateLogsIndex.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ func main() {
2424
ExclusionFilters: []datadogV1.LogsExclusion{
2525
{
2626
Filter: &datadogV1.LogsExclusionFilter{
27-
Query: datadog.PtrString("*"),
28-
SampleRate: 1.0,
27+
Query: datadog.PtrString("*"),
28+
SampleAttribute: datadog.PtrString("@ci.job_id"),
29+
SampleRate: 1.0,
2930
},
3031
Name: "payment",
3132
},

tests/scenarios/features/v1/logs_indexes.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ Feature: Logs Indexes
1111
@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
1212
Scenario: Create an index returns "Invalid Parameter Error" response
1313
Given new "CreateLogsIndex" request
14-
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "exclusion_filters": [{"filter": {"query": "*", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "name": "main", "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
14+
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "exclusion_filters": [{"filter": {"query": "*", "sample_attribute": "@ci.job_id", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "name": "main", "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
1515
When the request is sent
1616
Then the response status is 400 Invalid Parameter Error
1717

1818
@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
1919
Scenario: Create an index returns "OK" response
2020
Given new "CreateLogsIndex" request
21-
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "exclusion_filters": [{"filter": {"query": "*", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "name": "main", "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
21+
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "exclusion_filters": [{"filter": {"query": "*", "sample_attribute": "@ci.job_id", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "name": "main", "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
2222
When the request is sent
2323
Then the response status is 200 OK
2424

2525
@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
2626
Scenario: Create an index returns "Unprocessable Entity" response
2727
Given new "CreateLogsIndex" request
28-
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "exclusion_filters": [{"filter": {"query": "*", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "name": "main", "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
28+
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "exclusion_filters": [{"filter": {"query": "*", "sample_attribute": "@ci.job_id", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "name": "main", "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
2929
When the request is sent
3030
Then the response status is 422 Unprocessable Entity
3131

@@ -73,15 +73,15 @@ Feature: Logs Indexes
7373
Scenario: Update an index returns "Invalid Parameter Error" response
7474
Given new "UpdateLogsIndex" request
7575
And request contains "name" parameter from "REPLACE.ME"
76-
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "disable_daily_limit": false, "exclusion_filters": [{"filter": {"query": "*", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
76+
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "disable_daily_limit": false, "exclusion_filters": [{"filter": {"query": "*", "sample_attribute": "@ci.job_id", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
7777
When the request is sent
7878
Then the response status is 400 Invalid Parameter Error
7979

8080
@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
8181
Scenario: Update an index returns "OK" response
8282
Given new "UpdateLogsIndex" request
8383
And request contains "name" parameter from "REPLACE.ME"
84-
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "disable_daily_limit": false, "exclusion_filters": [{"filter": {"query": "*", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
84+
And body with value {"daily_limit": 300000000, "daily_limit_reset": {"reset_time": "14:00", "reset_utc_offset": "+02:00"}, "daily_limit_warning_threshold_percentage": 70, "disable_daily_limit": false, "exclusion_filters": [{"filter": {"query": "*", "sample_attribute": "@ci.job_id", "sample_rate": 1.0}, "name": "payment"}], "filter": {"query": "source:python"}, "num_flex_logs_retention_days": 360, "num_retention_days": 15, "tags": ["team:backend", "env:production"]}
8585
When the request is sent
8686
Then the response status is 200 OK
8787

0 commit comments

Comments
 (0)