Skip to content

Commit

Permalink
Delete EntityStoreResource const in favout of OpenAPi enum
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Nov 26, 2024
1 parent 6d6ce5a commit ae45c47
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,3 @@ export const ENTITY_STORE_REQUIRED_ES_CLUSTER_PRIVILEGES = [

// The index pattern for the entity store has to support '.entities.v1.latest.noop' index
export const ENTITY_STORE_INDEX_PATTERN = '.entities.v1.latest.*';

export const EntityStoreResource = {
ENTITY_ENGINE: 'entity_engine',
ENTITY_DEFINITION: 'entity_definition',
INDEX: 'index',
COMPONENT_TEMPLATE: 'component_template',
INDEX_TEMPLATE: 'index_template',
INGEST_PIPELINE: 'ingest_pipeline',
ENRICH_POLICY: 'enrich_policy',
TASK: 'task',
TRANSFORM: 'transform',
} as const;

export type EntityStoreResource = (typeof EntityStoreResource)[keyof typeof EntityStoreResource];
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/

import type { ElasticsearchClient } from '@kbn/core/server';
import type { EngineComponentStatus } from '../../../../../common/api/entity_analytics';
import { EntityStoreResource } from '../../../../../common/entity_analytics/entity_store/constants';
import {
EngineComponentResourceEnum,
type EngineComponentStatus,
} from '../../../../../common/api/entity_analytics';
import type { UnitedEntityDefinition } from '../united_entity_definitions';

const getComponentTemplateName = (definitionId: string) => `${definitionId}-latest@platform`;
Expand Down Expand Up @@ -61,6 +63,6 @@ export const getEntityIndexComponentTemplateStatus = async ({
return {
id: name,
installed: componentTemplate?.component_templates?.length > 0,
resource: EntityStoreResource.COMPONENT_TEMPLATE,
resource: EngineComponentResourceEnum.component_template,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { ElasticsearchClient, Logger } from '@kbn/core/server';
import type { EnrichPutPolicyRequest } from '@elastic/elasticsearch/lib/api/types';
import { EntityStoreResource } from '../../../../../common/entity_analytics/entity_store/constants';
import { EngineComponentResourceEnum } from '../../../../../common/api/entity_analytics';
import { getEntitiesIndexName } from '../utils';
import type { UnitedEntityDefinition } from '../united_entity_definitions';

Expand Down Expand Up @@ -121,6 +121,6 @@ export const getFieldRetentionEnrichPolicyStatus = async ({
return {
installed: policies.length > 0,
id: name,
resource: EntityStoreResource.ENRICH_POLICY,
resource: EngineComponentResourceEnum.enrich_policy,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
*/

import type { ElasticsearchClient, Logger } from '@kbn/core/server';
import { EntityStoreResource } from '../../../../../common/entity_analytics/entity_store/constants';
import type { EngineComponentStatus, EntityType } from '../../../../../common/api/entity_analytics';
import {
EngineComponentResourceEnum,
type EngineComponentStatus,
type EntityType,
} from '../../../../../common/api/entity_analytics';
import { getEntitiesIndexName } from '../utils';
import { createOrUpdateIndex } from '../../utils/create_or_update_index';

Expand Down Expand Up @@ -53,5 +56,5 @@ export const getEntityIndexStatus = async ({
}
);

return { id: index, installed: exists, resource: EntityStoreResource.INDEX };
return { id: index, installed: exists, resource: EngineComponentResourceEnum.index };
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { ElasticsearchClient, Logger } from '@kbn/core/server';
import type { IngestProcessorContainer } from '@elastic/elasticsearch/lib/api/types';
import type { EntityDefinition } from '@kbn/entities-schema';
import { EntityStoreResource } from '../../../../../common/entity_analytics/entity_store/constants';
import { EngineComponentResourceEnum } from '../../../../../common/api/entity_analytics';
import { type FieldRetentionDefinition } from '../field_retention_definition';
import {
debugDeepCopyContextStep,
Expand Down Expand Up @@ -183,6 +183,6 @@ export const getPlatformPipelineStatus = async ({
return {
id: pipelineId,
installed: !!pipeline[pipelineId],
resource: EntityStoreResource.INGEST_PIPELINE,
resource: EngineComponentResourceEnum.ingest_pipeline,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ import type {
InitEntityStoreRequestBody,
InitEntityStoreResponse,
} from '../../../../common/api/entity_analytics/entity_store/enable.gen';
import { EntityStoreResource } from '../../../../common/entity_analytics/entity_store/constants';
import type { AppClient } from '../../..';
import { EntityType } from '../../../../common/api/entity_analytics';
import { EngineComponentResourceEnum, EntityType } from '../../../../common/api/entity_analytics';
import type {
Entity,
EngineDataviewUpdateResult,
Expand All @@ -42,6 +41,7 @@ import type {
InspectQuery,
ListEntityEnginesResponse,
EngineComponentStatus,
EngineComponentResource,
} from '../../../../common/api/entity_analytics';
import { EngineDescriptorClient } from './saved_object/engine_descriptor';
import { ENGINE_STATUS, ENTITY_STORE_STATUS, MAX_SEARCH_RESPONSE_SIZE } from './constants';
Expand Down Expand Up @@ -299,7 +299,7 @@ export class EntityStoreDataClient {
this.log('info', entityType, `Initializing entity store`);
this.audit(
EntityEngineActions.INIT,
EntityStoreResource.ENTITY_ENGINE,
EngineComponentResourceEnum.entity_engine,
entityType,
'Initializing entity engine'
);
Expand Down Expand Up @@ -428,7 +428,7 @@ export class EntityStoreDataClient {

this.audit(
EntityEngineActions.INIT,
EntityStoreResource.ENTITY_ENGINE,
EngineComponentResourceEnum.entity_engine,
entityType,
'Failed to initialize entity engine resources',
err
Expand Down Expand Up @@ -460,7 +460,7 @@ export class EntityStoreDataClient {
{
id,
installed: false,
resource: EntityStoreResource.ENTITY_DEFINITION,
resource: EngineComponentResourceEnum.entity_definition,
},
];
}
Expand All @@ -470,25 +470,25 @@ export class EntityStoreDataClient {
{
id: definition.id,
installed: definition.state.installed,
resource: EntityStoreResource.ENTITY_DEFINITION,
resource: EngineComponentResourceEnum.entity_definition,
},
...definition.state.components.transforms.map(({ installed, running, stats }) => ({
id,
resource: EntityStoreResource.TRANSFORM,
resource: EngineComponentResourceEnum.transform,
installed,
errors: (stats?.health as TransformHealth)?.issues?.map(({ issue, details }) => ({
title: issue,
message: details,
})),
})),
...definition.state.components.ingestPipelines.map((pipeline) => ({
resource: EntityStoreResource.INGEST_PIPELINE,
resource: EngineComponentResourceEnum.ingest_pipeline,
...pipeline,
})),
...definition.state.components.indexTemplates.map(({ installed }) => ({
id,
installed,
resource: EntityStoreResource.INDEX_TEMPLATE,
resource: EngineComponentResourceEnum.index_template,
})),
];
}
Expand Down Expand Up @@ -527,7 +527,7 @@ export class EntityStoreDataClient {
const fullEntityDefinition = await this.getExistingEntityDefinition(entityType);
this.audit(
EntityEngineActions.START,
EntityStoreResource.ENTITY_DEFINITION,
EngineComponentResourceEnum.entity_definition,
entityType,
'Starting entity definition'
);
Expand All @@ -554,7 +554,7 @@ export class EntityStoreDataClient {
const fullEntityDefinition = await this.getExistingEntityDefinition(entityType);
this.audit(
EntityEngineActions.STOP,
EntityStoreResource.ENTITY_DEFINITION,
EngineComponentResourceEnum.entity_definition,
entityType,
'Stopping entity definition'
);
Expand Down Expand Up @@ -597,7 +597,7 @@ export class EntityStoreDataClient {
this.log('info', entityType, `Deleting entity store`);
this.audit(
EntityEngineActions.DELETE,
EntityStoreResource.ENTITY_ENGINE,
EngineComponentResourceEnum.entity_engine,
entityType,
'Deleting entity engine'
);
Expand Down Expand Up @@ -665,7 +665,7 @@ export class EntityStoreDataClient {

this.audit(
EntityEngineActions.DELETE,
EntityStoreResource.ENTITY_ENGINE,
EngineComponentResourceEnum.entity_engine,
entityType,
'Failed to delete entity engine',
err
Expand Down Expand Up @@ -812,7 +812,7 @@ export class EntityStoreDataClient {

private audit(
action: EntityEngineActions,
resource: EntityStoreResource,
resource: EngineComponentResource,
entityType: EntityType,
msg: string,
error?: Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import type {
TaskManagerSetupContract,
TaskManagerStartContract,
} from '@kbn/task-manager-plugin/server';
import { EntityStoreResource } from '../../../../../common/entity_analytics/entity_store/constants';
import type { EntityType } from '../../../../../common/api/entity_analytics/entity_store';
import {
EngineComponentResourceEnum,
type EntityType,
} from '../../../../../common/api/entity_analytics/entity_store';
import {
defaultState,
stateSchemaByVersion,
Expand Down Expand Up @@ -290,7 +292,7 @@ export const getEntityStoreFieldRetentionEnrichTaskState = async ({

return {
id: taskState.id,
resource: EntityStoreResource.TASK,
resource: EngineComponentResourceEnum.task,
installed: true,
enabled: taskState.enabled,
status: taskState.status,
Expand All @@ -304,7 +306,7 @@ export const getEntityStoreFieldRetentionEnrichTaskState = async ({
return {
id: taskId,
installed: false,
resource: EntityStoreResource.TASK,
resource: EngineComponentResourceEnum.task,
};
}
throw e;
Expand Down

0 comments on commit ae45c47

Please sign in to comment.