Skip to content

Commit

Permalink
[DataUsage][Serverless] Fix AutoOps error message to drop "agent" ref…
Browse files Browse the repository at this point in the history
…erence (elastic#202996)

## Summary

This removes the references to "autoops agent" in the error message if
the request fails, as it has nothing to do with any agent.

### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

No. None of the error messages are exported, so they cannot be misused
in other places.
  • Loading branch information
pickypg authored and mykolaharmash committed Dec 11, 2024
1 parent b9be672 commit 01bfa28
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions x-pack/plugins/data_usage/server/services/autoops_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import { AutoOpsConfig } from '../types';
import { AutoOpsError } from './errors';
import { appContextService } from './app_context';

const AGENT_CREATION_FAILED_ERROR = 'AutoOps API could not create the autoops agent';
const AUTO_OPS_AGENT_CREATION_PREFIX = '[AutoOps API] Creating autoops agent failed';
const AUTO_OPS_REQUEST_FAILED_PREFIX = '[AutoOps API] Request failed';
const AUTO_OPS_MISSING_CONFIG_ERROR = 'Missing autoops configuration';

const getAutoOpsAPIRequestUrl = (url?: string, projectId?: string): string =>
Expand Down Expand Up @@ -120,7 +119,7 @@ export class AutoOpsAPIService {
(error: Error | AxiosError) => {
if (!axios.isAxiosError(error)) {
this.logger.error(
`${AUTO_OPS_AGENT_CREATION_PREFIX} with an error ${error} ${requestConfigDebugStatus}`,
`${AUTO_OPS_REQUEST_FAILED_PREFIX} with an error ${error}, request config: ${requestConfigDebugStatus}`,
errorMetadataWithRequestConfig
);
throw new AutoOpsError(withRequestIdMessage(error.message));
Expand All @@ -131,9 +130,11 @@ export class AutoOpsAPIService {
if (error.response) {
// The request was made and the server responded with a status code and error data
this.logger.error(
`${AUTO_OPS_AGENT_CREATION_PREFIX} because the AutoOps API responded with a status code that falls out of the range of 2xx: ${JSON.stringify(
`${AUTO_OPS_REQUEST_FAILED_PREFIX} because the AutoOps API responded with a status code that falls out of the range of 2xx: ${JSON.stringify(
error.response.status
)}} ${JSON.stringify(error.response.data)}} ${requestConfigDebugStatus}`,
)}} ${JSON.stringify(
error.response.data
)}}, request config: ${requestConfigDebugStatus}`,
{
...errorMetadataWithRequestConfig,
http: {
Expand All @@ -145,22 +146,22 @@ export class AutoOpsAPIService {
},
}
);
throw new AutoOpsError(withRequestIdMessage(AGENT_CREATION_FAILED_ERROR));
throw new AutoOpsError(withRequestIdMessage(AUTO_OPS_REQUEST_FAILED_PREFIX));
} else if (error.request) {
// The request was made but no response was received
this.logger.error(
`${AUTO_OPS_AGENT_CREATION_PREFIX} while sending the request to the AutoOps API: ${errorLogCodeCause} ${requestConfigDebugStatus}`,
`${AUTO_OPS_REQUEST_FAILED_PREFIX} while sending the request to the AutoOps API: ${errorLogCodeCause}, request config: ${requestConfigDebugStatus}`,
errorMetadataWithRequestConfig
);
throw new AutoOpsError(withRequestIdMessage(`no response received from the AutoOps API`));
} else {
// Something happened in setting up the request that triggered an Error
this.logger.error(
`${AUTO_OPS_AGENT_CREATION_PREFIX} to be created ${errorLogCodeCause} ${requestConfigDebugStatus} ${error.toJSON()}`,
`${AUTO_OPS_REQUEST_FAILED_PREFIX} with ${errorLogCodeCause}, request config: ${requestConfigDebugStatus}, error: ${error.toJSON()}`,
errorMetadataWithRequestConfig
);
throw new AutoOpsError(
withRequestIdMessage(`${AGENT_CREATION_FAILED_ERROR}, ${error.message}`)
withRequestIdMessage(`${AUTO_OPS_REQUEST_FAILED_PREFIX}, ${error.message}`)
);
}
}
Expand Down

0 comments on commit 01bfa28

Please sign in to comment.