Skip to content

Commit

Permalink
[8.x] [Cloud Security] Refactoring the limit error message for agentl…
Browse files Browse the repository at this point in the history
…ess agent (#203257) (#203330)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Cloud Security] Refactoring the limit error message for agentless
agent (#203257)](#203257)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"seanrathier","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-06T19:20:33Z","message":"[Cloud
Security] Refactoring the limit error message for agentless agent
(#203257)","sha":"1d3bf85d19985f99d9d582ffad0353747cd5c60b","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","Team:Cloud
Security","backport:prev-minor","8.18 candidate"],"title":"[Cloud
Security] Refactoring the limit error message for agentless
agent","number":203257,"url":"https://github.com/elastic/kibana/pull/203257","mergeCommit":{"message":"[Cloud
Security] Refactoring the limit error message for agentless agent
(#203257)","sha":"1d3bf85d19985f99d9d582ffad0353747cd5c60b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203257","number":203257,"mergeCommit":{"message":"[Cloud
Security] Refactoring the limit error message for agentless agent
(#203257)","sha":"1d3bf85d19985f99d9d582ffad0353747cd5c60b"}}]}]
BACKPORT-->

Co-authored-by: seanrathier <[email protected]>
  • Loading branch information
kibanamachine and seanrathier authored Dec 6, 2024
1 parent e843309 commit d1701ca
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions x-pack/plugins/fleet/server/services/agents/agentless_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ import { listFleetServerHosts } from '../fleet_server_host';
import type { AgentlessConfig } from '../utils/agentless';
import { prependAgentlessApiBasePathToEndpoint, isAgentlessEnabled } from '../utils/agentless';

interface AgentlessAgentErrorHandlingMessages {
[key: string]: {
[key: string]: {
log: string;
message: string;
};
};
}

class AgentlessAgentService {
public async createAgentlessAgent(
esClient: ElasticsearchClient,
Expand Down Expand Up @@ -326,14 +335,12 @@ class AgentlessAgentService {
throw this.getAgentlessAgentError(action, error.message, traceId);
}

const ERROR_HANDLING_MESSAGES = this.getErrorHandlingMessages(agentlessPolicyId);
const ERROR_HANDLING_MESSAGES: AgentlessAgentErrorHandlingMessages =
this.getErrorHandlingMessages(agentlessPolicyId);

if (error.response) {
if (error.response.status in ERROR_HANDLING_MESSAGES) {
const handledResponseErrorMessage =
ERROR_HANDLING_MESSAGES[error.response.status as keyof typeof ERROR_HANDLING_MESSAGES][
action
];
const handledResponseErrorMessage = ERROR_HANDLING_MESSAGES[error.response.status][action];
this.handleResponseError(
action,
error.response,
Expand Down Expand Up @@ -426,7 +433,7 @@ class AgentlessAgentService {
: new AgentlessAgentDeleteError(this.withRequestIdMessage(userMessage, traceId));
}

private getErrorHandlingMessages(agentlessPolicyId: string) {
private getErrorHandlingMessages(agentlessPolicyId: string): AgentlessAgentErrorHandlingMessages {
return {
400: {
create: {
Expand Down Expand Up @@ -483,13 +490,7 @@ class AgentlessAgentService {
create: {
log: '[Agentless API] Creating the agentless agent failed with a status 429 for agentless policy, agentless agent limit has been reached for this deployment or project.',
message:
'the Agentless API could not create the agentless agent, you have reached the limit of agentless agents provisioned for this deployment or project. Consider removing some agentless agents and try again or use agent-based agents for this integration.',
},
// this is likely to happen when deleting agentless agents, but covering it in case
delete: {
log: '[Agentless API] Deleting the agentless deployment failed with a status 429 for agentless policy, agentless agent limit has been reached for this deployment or project.',
message:
'the Agentless API could not delete the agentless deployment, you have reached the limit of agentless agents provisioned for this deployment or project. Consider removing some agentless agents and try again or use agent-based agents for this integration.',
'you have reached the limit for agentless provisioning. Please remove some or switch to agent-based integration.',
},
},
500: {
Expand Down

0 comments on commit d1701ca

Please sign in to comment.