Skip to content

return 422 response code for logs indexes creation when max limit is reached #2642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .generated-info
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"spec_repo_commit": "d02c8a3",
"generated": "2025-08-08 12:08:19.964"
"spec_repo_commit": "872cf6d",
"generated": "2025-08-12 14:44:28.112"
}
12 changes: 12 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5123,6 +5123,12 @@ components:
error:
$ref: '#/components/schemas/LogsAPIError'
type: object
LogsAPILimitReachedResponse:
description: Response returned by the Logs API when the max limit has been reached.
properties:
error:
$ref: '#/components/schemas/LogsAPIError'
type: object
LogsArithmeticProcessor:
description: "Use the Arithmetic Processor to add a new attribute (without spaces
or special characters\nin the new attribute name) to a log with the result
Expand Down Expand Up @@ -29444,6 +29450,12 @@ paths:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Forbidden
'422':
content:
application/json:
schema:
$ref: '#/components/schemas/LogsAPILimitReachedResponse'
description: Unprocessable Entity
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
summary: Create an index
Expand Down
7 changes: 7 additions & 0 deletions features/v1/logs_indexes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Feature: Logs Indexes
When the request is sent
Then the response status is 200 OK

@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
Scenario: Create an index returns "Unprocessable Entity" response
Given new "CreateLogsIndex" request
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}
When the request is sent
Then the response status is 422 Unprocessable Entity

@generated @skip @team:DataDog/logs-backend @team:DataDog/logs-core
Scenario: Delete an index returns "Not Found" response
Given new "DeleteLogsIndex" request
Expand Down
24 changes: 24 additions & 0 deletions packages/datadog-api-client-v1/apis/LogsIndexesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ApiException } from "../../datadog-api-client-common/exception";

import { APIErrorResponse } from "../models/APIErrorResponse";
import { LogsAPIErrorResponse } from "../models/LogsAPIErrorResponse";
import { LogsAPILimitReachedResponse } from "../models/LogsAPILimitReachedResponse";
import { LogsIndex } from "../models/LogsIndex";
import { LogsIndexesOrder } from "../models/LogsIndexesOrder";
import { LogsIndexListResponse } from "../models/LogsIndexListResponse";
Expand Down Expand Up @@ -333,6 +334,29 @@ export class LogsIndexesApiResponseProcessor {
}
throw new ApiException<APIErrorResponse>(response.httpStatusCode, body);
}
if (response.httpStatusCode === 422) {
const bodyText = ObjectSerializer.parse(
await response.body.text(),
contentType
);
let body: LogsAPILimitReachedResponse;
try {
body = ObjectSerializer.deserialize(
bodyText,
"LogsAPILimitReachedResponse"
) as LogsAPILimitReachedResponse;
} catch (error) {
logger.debug(`Got error deserializing error: ${error}`);
throw new ApiException<LogsAPILimitReachedResponse>(
response.httpStatusCode,
bodyText
);
}
throw new ApiException<LogsAPILimitReachedResponse>(
response.httpStatusCode,
body
);
}

// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
Expand Down
1 change: 1 addition & 0 deletions packages/datadog-api-client-v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ export { LogQueryDefinitionGroupBySort } from "./models/LogQueryDefinitionGroupB
export { LogQueryDefinitionSearch } from "./models/LogQueryDefinitionSearch";
export { LogsAPIError } from "./models/LogsAPIError";
export { LogsAPIErrorResponse } from "./models/LogsAPIErrorResponse";
export { LogsAPILimitReachedResponse } from "./models/LogsAPILimitReachedResponse";
export { LogsArithmeticProcessor } from "./models/LogsArithmeticProcessor";
export { LogsArithmeticProcessorType } from "./models/LogsArithmeticProcessorType";
export { LogsArrayProcessor } from "./models/LogsArrayProcessor";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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 2020-Present Datadog, Inc.
*/
import { LogsAPIError } from "./LogsAPIError";

import { AttributeTypeMap } from "../../datadog-api-client-common/util";

/**
* Response returned by the Logs API when the max limit has been reached.
*/
export class LogsAPILimitReachedResponse {
/**
* Error returned by the Logs API
*/
"error"?: LogsAPIError;

/**
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
* the 'additionalProperties' keyword in the OAS document.
*/
"additionalProperties"?: { [key: string]: any };

/**
* @ignore
*/
"_unparsed"?: boolean;

/**
* @ignore
*/
static readonly attributeTypeMap: AttributeTypeMap = {
error: {
baseName: "error",
type: "LogsAPIError",
},
additionalProperties: {
baseName: "additionalProperties",
type: "any",
},
};

/**
* @ignore
*/
static getAttributeTypeMap(): AttributeTypeMap {
return LogsAPILimitReachedResponse.attributeTypeMap;
}

public constructor() {}
}
2 changes: 2 additions & 0 deletions packages/datadog-api-client-v1/models/ObjectSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ import { LogQueryDefinitionSearch } from "./LogQueryDefinitionSearch";
import { LogStreamWidgetDefinition } from "./LogStreamWidgetDefinition";
import { LogsAPIError } from "./LogsAPIError";
import { LogsAPIErrorResponse } from "./LogsAPIErrorResponse";
import { LogsAPILimitReachedResponse } from "./LogsAPILimitReachedResponse";
import { LogsArithmeticProcessor } from "./LogsArithmeticProcessor";
import { LogsArrayProcessor } from "./LogsArrayProcessor";
import { LogsArrayProcessorOperationAppend } from "./LogsArrayProcessorOperationAppend";
Expand Down Expand Up @@ -1870,6 +1871,7 @@ const typeMap: { [index: string]: any } = {
LogStreamWidgetDefinition: LogStreamWidgetDefinition,
LogsAPIError: LogsAPIError,
LogsAPIErrorResponse: LogsAPIErrorResponse,
LogsAPILimitReachedResponse: LogsAPILimitReachedResponse,
LogsArithmeticProcessor: LogsArithmeticProcessor,
LogsArrayProcessor: LogsArrayProcessor,
LogsArrayProcessorOperationAppend: LogsArrayProcessorOperationAppend,
Expand Down