Skip to content

Commit

Permalink
added error handling, extracted index names as constants
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Nov 9, 2022
1 parent d622ed3 commit 89888ae
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions x-pack/plugins/fleet/server/services/agents/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,32 @@ import {

import { SO_SEARCH_LIMIT } from '../../constants';

const FILE_STORAGE_METADATA_AGENT_INDEX = '.fleet-agent-files';
const FILE_STORAGE_DATA_AGENT_INDEX = '.fleet-agent-file-data';

export async function getAgentUploads(
esClient: ElasticsearchClient,
agentId: string
): Promise<AgentDiagnostics[]> {
const getFile = async (fileId: string) => {
if (!fileId) return;
const file = await esClient.get({
index: '.fleet-agent-files',
id: fileId,
});
return {
id: file._id,
...(file._source as any)?.file,
};
try {
const file = await esClient.get({
index: FILE_STORAGE_METADATA_AGENT_INDEX,
id: fileId,
});
return {
id: file._id,
...(file._source as any)?.file,
};
} catch (err) {
if (err.statusCode === 404) {
appContextService.getLogger().debug(err);
return;
} else {
throw err;
}
}
};

const actions = await _getRequestDiagnosticsActions(esClient, agentId);
Expand Down Expand Up @@ -137,8 +149,8 @@ export async function getAgentUploadFile(
): Promise<{ body: Readable; headers: ResponseHeaders }> {
try {
const fileClient = createEsFileClient({
blobStorageIndex: '.fleet-agent-file-data',
metadataIndex: '.fleet-agent-files',
blobStorageIndex: FILE_STORAGE_DATA_AGENT_INDEX,
metadataIndex: FILE_STORAGE_METADATA_AGENT_INDEX,
elasticsearchClient: esClient,
logger: appContextService.getLogger(),
});
Expand Down

0 comments on commit 89888ae

Please sign in to comment.