Skip to content

Commit 2ee6e2d

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
return 422 response code for logs indexes creation when max limit is reached (#3276)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 539c091 commit 2ee6e2d

5 files changed

Lines changed: 141 additions & 2 deletions

File tree

.generated-info

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"spec_repo_commit": "205813d",
3-
"generated": "2025-08-25 08:43:18.277"
2+
"spec_repo_commit": "c3b2b7d",
3+
"generated": "2025-08-25 10:19:56.716"
44
}

.generator/schemas/v1/openapi.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5123,6 +5123,12 @@ components:
51235123
error:
51245124
$ref: '#/components/schemas/LogsAPIError'
51255125
type: object
5126+
LogsAPILimitReachedResponse:
5127+
description: Response returned by the Logs API when the max limit has been reached.
5128+
properties:
5129+
error:
5130+
$ref: '#/components/schemas/LogsAPIError'
5131+
type: object
51265132
LogsArithmeticProcessor:
51275133
description: "Use the Arithmetic Processor to add a new attribute (without spaces
51285134
or special characters\nin the new attribute name) to a log with the result
@@ -29444,6 +29450,12 @@ paths:
2944429450
schema:
2944529451
$ref: '#/components/schemas/APIErrorResponse'
2944629452
description: Forbidden
29453+
'422':
29454+
content:
29455+
application/json:
29456+
schema:
29457+
$ref: '#/components/schemas/LogsAPILimitReachedResponse'
29458+
description: Unprocessable Entity
2944729459
'429':
2944829460
$ref: '#/components/responses/TooManyRequestsResponse'
2944929461
summary: Create an index

api/datadogV1/api_logs_indexes.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ func (a *LogsIndexesApi) CreateLogsIndex(ctx _context.Context, body LogsIndex) (
8888
return localVarReturnValue, localVarHTTPResponse, newErr
8989
}
9090
newErr.ErrorModel = v
91+
return localVarReturnValue, localVarHTTPResponse, newErr
92+
}
93+
if localVarHTTPResponse.StatusCode == 422 {
94+
var v LogsAPILimitReachedResponse
95+
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
96+
if err != nil {
97+
return localVarReturnValue, localVarHTTPResponse, newErr
98+
}
99+
newErr.ErrorModel = v
91100
}
92101
return localVarReturnValue, localVarHTTPResponse, newErr
93102
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
package datadogV1
6+
7+
import (
8+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
9+
)
10+
11+
// LogsAPILimitReachedResponse Response returned by the Logs API when the max limit has been reached.
12+
type LogsAPILimitReachedResponse struct {
13+
// Error returned by the Logs API
14+
Error *LogsAPIError `json:"error,omitempty"`
15+
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
16+
UnparsedObject map[string]interface{} `json:"-"`
17+
AdditionalProperties map[string]interface{} `json:"-"`
18+
}
19+
20+
// NewLogsAPILimitReachedResponse instantiates a new LogsAPILimitReachedResponse object.
21+
// This constructor will assign default values to properties that have it defined,
22+
// and makes sure properties required by API are set, but the set of arguments
23+
// will change when the set of required properties is changed.
24+
func NewLogsAPILimitReachedResponse() *LogsAPILimitReachedResponse {
25+
this := LogsAPILimitReachedResponse{}
26+
return &this
27+
}
28+
29+
// NewLogsAPILimitReachedResponseWithDefaults instantiates a new LogsAPILimitReachedResponse object.
30+
// This constructor will only assign default values to properties that have it defined,
31+
// but it doesn't guarantee that properties required by API are set.
32+
func NewLogsAPILimitReachedResponseWithDefaults() *LogsAPILimitReachedResponse {
33+
this := LogsAPILimitReachedResponse{}
34+
return &this
35+
}
36+
37+
// GetError returns the Error field value if set, zero value otherwise.
38+
func (o *LogsAPILimitReachedResponse) GetError() LogsAPIError {
39+
if o == nil || o.Error == nil {
40+
var ret LogsAPIError
41+
return ret
42+
}
43+
return *o.Error
44+
}
45+
46+
// GetErrorOk returns a tuple with the Error field value if set, nil otherwise
47+
// and a boolean to check if the value has been set.
48+
func (o *LogsAPILimitReachedResponse) GetErrorOk() (*LogsAPIError, bool) {
49+
if o == nil || o.Error == nil {
50+
return nil, false
51+
}
52+
return o.Error, true
53+
}
54+
55+
// HasError returns a boolean if a field has been set.
56+
func (o *LogsAPILimitReachedResponse) HasError() bool {
57+
return o != nil && o.Error != nil
58+
}
59+
60+
// SetError gets a reference to the given LogsAPIError and assigns it to the Error field.
61+
func (o *LogsAPILimitReachedResponse) SetError(v LogsAPIError) {
62+
o.Error = &v
63+
}
64+
65+
// MarshalJSON serializes the struct using spec logic.
66+
func (o LogsAPILimitReachedResponse) MarshalJSON() ([]byte, error) {
67+
toSerialize := map[string]interface{}{}
68+
if o.UnparsedObject != nil {
69+
return datadog.Marshal(o.UnparsedObject)
70+
}
71+
if o.Error != nil {
72+
toSerialize["error"] = o.Error
73+
}
74+
75+
for key, value := range o.AdditionalProperties {
76+
toSerialize[key] = value
77+
}
78+
return datadog.Marshal(toSerialize)
79+
}
80+
81+
// UnmarshalJSON deserializes the given payload.
82+
func (o *LogsAPILimitReachedResponse) UnmarshalJSON(bytes []byte) (err error) {
83+
all := struct {
84+
Error *LogsAPIError `json:"error,omitempty"`
85+
}{}
86+
if err = datadog.Unmarshal(bytes, &all); err != nil {
87+
return datadog.Unmarshal(bytes, &o.UnparsedObject)
88+
}
89+
additionalProperties := make(map[string]interface{})
90+
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
91+
datadog.DeleteKeys(additionalProperties, &[]string{"error"})
92+
} else {
93+
return err
94+
}
95+
96+
hasInvalidField := false
97+
if all.Error != nil && all.Error.UnparsedObject != nil && o.UnparsedObject == nil {
98+
hasInvalidField = true
99+
}
100+
o.Error = all.Error
101+
102+
if len(additionalProperties) > 0 {
103+
o.AdditionalProperties = additionalProperties
104+
}
105+
106+
if hasInvalidField {
107+
return datadog.Unmarshal(bytes, &o.UnparsedObject)
108+
}
109+
110+
return nil
111+
}

tests/scenarios/features/v1/logs_indexes.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ Feature: Logs Indexes
2222
When the request is sent
2323
Then the response status is 200 OK
2424

25+
@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
26+
Scenario: Create an index returns "Unprocessable Entity" response
27+
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}
29+
When the request is sent
30+
Then the response status is 422 Unprocessable Entity
31+
2532
@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
2633
Scenario: Delete an index returns "Not Found" response
2734
Given new "DeleteLogsIndex" request

0 commit comments

Comments
 (0)