Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
tiansivive committed Oct 30, 2024
1 parent 7276d9b commit 29b6fea
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@ const EntityStoreDashboardPanelsComponent = () => {

const { mutate: initRiskEngine } = useInitRiskEngineMutation();

const callouts = entityStore.errors
.filter((_, i) => !hiddenToasts.includes(i))
.map((err, i) => (
<EuiCallOut
title={'An error occurred during entity store resource initialization'}
color="danger"
iconType="error"
>
<p>{err?.message}</p>
</EuiCallOut>
));
const callouts = entityStore.errors.map((err, i) => (
<EuiCallOut
title={
<FormattedMessage
id="xpack.securitySolution.entityAnalytics.entityStore.enablement.errors.title"
defaultMessage={'An error occurred during entity store resource initialization'}
/>
}
color="danger"
iconType="error"
>
<p>{err?.message}</p>
</EuiCallOut>
));

const enableEntityStore = (enable: Enablements) => () => {
setModalState({ visible: false });
Expand All @@ -91,7 +94,12 @@ const EntityStoreDashboardPanelsComponent = () => {
return (
<>
<EuiCallOut
title={'There was a problem initializing the entity store'}
title={
<FormattedMessage
id="xpack.securitySolution.entityAnalytics.entityStore.enablement.errors.queryErrorTitle"
defaultMessage={'There was a problem initializing the entity store'}
/>
}
color="danger"
iconType="error"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,6 @@ export class EntityStoreDataClient {
// clean up any existing entity store
await this.delete(entityType, taskManager, { deleteData: false, deleteEngine: false });

await new Promise((resolve, reject) =>
setTimeout(() => {
reject(new Error('timeout test error'));
}, 2000)
);

// set up the entity manager definition
await this.entityClient.createEntityDefinition({
definition: {
Expand Down Expand Up @@ -326,7 +320,7 @@ export class EntityStoreDataClient {
const fullEntityDefinition = await this.getExistingEntityDefinition(entityType);
await this.entityClient.startEntityDefinition(fullEntityDefinition);

return this.engineClient.setStatus(entityType, ENGINE_STATUS.STARTED);
return this.engineClient.updateStatus(entityType, ENGINE_STATUS.STARTED);
}

public async stop(entityType: EntityType) {
Expand All @@ -346,7 +340,7 @@ export class EntityStoreDataClient {
const fullEntityDefinition = await this.getExistingEntityDefinition(entityType);
await this.entityClient.stopEntityDefinition(fullEntityDefinition);

return this.engineClient.setStatus(entityType, ENGINE_STATUS.STOPPED);
return this.engineClient.updateStatus(entityType, ENGINE_STATUS.STOPPED);
}

public async get(entityType: EntityType) {
Expand Down Expand Up @@ -513,7 +507,7 @@ export class EntityStoreDataClient {
}

// Update savedObject status
await this.engineClient.setStatus(engine.type, ENGINE_STATUS.UPDATING);
await this.engineClient.updateStatus(engine.type, ENGINE_STATUS.UPDATING);

try {
// Update entity manager definition
Expand All @@ -526,12 +520,12 @@ export class EntityStoreDataClient {
});

// Restore the savedObject status and set the new index pattern
await this.engineClient.setStatus(engine.type, originalStatus);
await this.engineClient.updateStatus(engine.type, originalStatus);

return { type: engine.type, changes: { indexPatterns } };
} catch (error) {
// Rollback the engine initial status when the update fails
await this.engineClient.setStatus(engine.type, originalStatus);
await this.engineClient.updateStatus(engine.type, originalStatus);

throw error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,8 @@ export class EngineDescriptorClient {
return attributes;
}

async setStatus(entityType: EntityType, status: EngineStatus) {
const id = this.getSavedObjectId(entityType);
const { attributes } = await this.deps.soClient.update<EngineDescriptor>(
entityEngineDescriptorTypeName,
id,
{ status },
{ refresh: 'wait_for' }
);
return attributes;
async updateStatus(entityType: EntityType, status: EngineStatus) {
return this.update(entityType, { status });
}

async find(entityType: EntityType): Promise<SavedObjectsFindResponse<EngineDescriptor>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export const entityEngineDescriptorTypeMappings: SavedObjectsType['mappings'] =
type: 'integer',
index: false,
},
error: {
type: 'object',
},
},
};

Expand All @@ -58,33 +55,11 @@ const version1: SavedObjectsModelVersion = {
],
};

const version2: SavedObjectsModelVersion = {
changes: [
{
type: 'mappings_addition',
addedMappings: {
error: { type: 'object' },
},
},
{
type: 'data_backfill',
backfillFn: (document) => {
return {
attributes: {
...document.attributes,
error: null,
},
};
},
},
],
};

export const entityEngineDescriptorType: SavedObjectsType = {
name: entityEngineDescriptorTypeName,
indexPattern: SECURITY_SOLUTION_SAVED_OBJECT_INDEX,
hidden: false,
namespaceType: 'multiple-isolated',
mappings: entityEngineDescriptorTypeMappings,
modelVersions: { 1: version1, 2: version2 },
modelVersions: { 1: version1 },
};

0 comments on commit 29b6fea

Please sign in to comment.