Skip to content

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

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: v2
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:07:03.564"
"spec_repo_commit": "872cf6d",
"generated": "2025-08-12 14:43:04.188"
}
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
22 changes: 22 additions & 0 deletions services/logs_indexes/src/v1/LogsIndexesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { TypingInfo } from "./models/TypingInfo";
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 @@ -414,6 +415,27 @@ export class LogsIndexesApiResponseProcessor {
}
throw new ApiException<APIErrorResponse>(response.httpStatusCode, body);
}
if (response.httpStatusCode === 422) {
const bodyText = parse(await response.body.text(), contentType);
let body: LogsAPILimitReachedResponse;
try {
body = deserialize(
bodyText,
TypingInfo,
"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 services/logs_indexes/src/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export {
export { APIErrorResponse } from "./models/APIErrorResponse";
export { LogsAPIError } from "./models/LogsAPIError";
export { LogsAPIErrorResponse } from "./models/LogsAPIErrorResponse";
export { LogsAPILimitReachedResponse } from "./models/LogsAPILimitReachedResponse";
export { LogsDailyLimitReset } from "./models/LogsDailyLimitReset";
export { LogsExclusion } from "./models/LogsExclusion";
export { LogsExclusionFilter } from "./models/LogsExclusionFilter";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { AttributeTypeMap } from "@datadog/datadog-api-client";

import { LogsAPIError } from "./LogsAPIError";

/**
* 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: "{ [key: string]: any; }",
},
};

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

public constructor() {}
}
2 changes: 2 additions & 0 deletions services/logs_indexes/src/v1/models/TypingInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ModelTypingInfo } from "@datadog/datadog-api-client";
import { APIErrorResponse } from "./APIErrorResponse";
import { LogsAPIError } from "./LogsAPIError";
import { LogsAPIErrorResponse } from "./LogsAPIErrorResponse";
import { LogsAPILimitReachedResponse } from "./LogsAPILimitReachedResponse";
import { LogsDailyLimitReset } from "./LogsDailyLimitReset";
import { LogsExclusion } from "./LogsExclusion";
import { LogsExclusionFilter } from "./LogsExclusionFilter";
Expand All @@ -19,6 +20,7 @@ export const TypingInfo: ModelTypingInfo = {
APIErrorResponse: APIErrorResponse,
LogsAPIError: LogsAPIError,
LogsAPIErrorResponse: LogsAPIErrorResponse,
LogsAPILimitReachedResponse: LogsAPILimitReachedResponse,
LogsDailyLimitReset: LogsDailyLimitReset,
LogsExclusion: LogsExclusion,
LogsExclusionFilter: LogsExclusionFilter,
Expand Down