Skip to content

Commit

Permalink
Adjustment due to code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-tavares committed Oct 25, 2024
1 parent 06c74ca commit 89b33fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export abstract class ResponseActionsClientImpl implements ResponseActionsClient
): Promise<LogsEndpointActionResponse<TOutputContent>> {
// FIXME:PT need to ensure we use a index below that has the proper `namespace` when agent type is Endpoint
// Background: Endpoint responses require that the document be written to an index that has the
// correct `namespace` as defined by the Integration/Agent policy adn that logic is not currently implemented.
// correct `namespace` as defined by the Integration/Agent policy and that logic is not currently implemented.

const doc = this.buildActionResponseEsDoc(options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ const fetchEndpointPolicyNamespace = async ({
if (agentPolicyIdsToRetrieve.size > 0) {
const ids = Array.from(agentPolicyIdsToRetrieve);

logger.debug(() => `Retrieving agent policies from fleeet for:\n${stringify(ids)}`);
logger.debug(() => `Retrieving agent policies from fleet for:\n${stringify(ids)}`);

const agentPolicies = await agentPolicyService.getByIds(soClient, ids);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,35 @@ export const createPolicyDataStreamsIfNeeded: PolicyDataStreamsCreator = async (
return;
}

if (!(await esClient.indices.exists({ index: datastreamIndexName }).catch(catchAndWrapError))) {
await esClient.indices
.createDataStream({ name: datastreamIndexName })
.then(() => {
indexesCreated.push(datastreamIndexName);
cache.set(datastreamIndexName, true);
})
.catch((err) => {
// It's possible that between the `.exists()` check and this `.createDataStream()` that
// the index could have been created. If that's the case, then just ignore the error.
if (err.body?.error?.type === 'resource_already_exists_exception') {
cache.set(datastreamIndexName, true);
return;
}

createErrors.push(
`Attempt to create datastream [${datastreamIndexName}] failed:\n${stringify(
err.body?.error ?? err
)}`
);
});
} else {
const doesDataStreamAlreadyExist = await esClient.indices
.exists({ index: datastreamIndexName })
.catch(catchAndWrapError);

if (doesDataStreamAlreadyExist) {
cache.set(datastreamIndexName, true);
return;
}

await esClient.indices
.createDataStream({ name: datastreamIndexName })
.then(() => {
indexesCreated.push(datastreamIndexName);
cache.set(datastreamIndexName, true);
})
.catch((err) => {
// It's possible that between the `.exists()` check and this `.createDataStream()` that
// the index could have been created. If that's the case, then just ignore the error.
if (err.body?.error?.type === 'resource_already_exists_exception') {
cache.set(datastreamIndexName, true);
return;
}

createErrors.push(
`Attempt to create datastream [${datastreamIndexName}] failed:\n${stringify(
err.body?.error ?? err
)}`
);
});
};

logger.debug(
Expand Down

0 comments on commit 89b33fc

Please sign in to comment.