Skip to content

Commit

Permalink
remove 'spaceId' from entity APIs (#187502)
Browse files Browse the repository at this point in the history
remove 'spaceId' from entity APIs
  • Loading branch information
tommyers-elastic authored Jul 4, 2024
1 parent c9e6e7e commit 6ca9fec
Show file tree
Hide file tree
Showing 18 changed files with 20 additions and 77 deletions.
1 change: 0 additions & 1 deletion x-pack/packages/kbn-entities-schema/src/schema/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const entitySchema = z.object({
id: z.string(),
identityFields: arrayOfStringsSchema,
displayName: z.string(),
spaceId: z.string(),
metrics: z.record(z.string(), z.number()),
}),
});
Expand Down
16 changes: 3 additions & 13 deletions x-pack/plugins/observability_solution/entity_manager/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@
"description": "Entity manager plugin for entity assets (inventory, topology, etc)",
"plugin": {
"id": "entityManager",
"configPath": [
"xpack",
"entityManager"
],
"optionalPlugins": [
"spaces"
],
"requiredPlugins": [
"security",
"encryptedSavedObjects",
],
"configPath": ["xpack", "entityManager"],
"requiredPlugins": ["security", "encryptedSavedObjects"],
"browser": true,
"server": true,
"requiredBundles": [
]
"requiredBundles": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import { generateHistoryIngestPipelineId } from './ingest_pipeline/generate_hist
export async function createAndInstallHistoryIngestPipeline(
esClient: ElasticsearchClient,
definition: EntityDefinition,
logger: Logger,
spaceId: string
logger: Logger
) {
try {
const historyProcessors = generateHistoryProcessors(definition, spaceId);
const historyProcessors = generateHistoryProcessors(definition);
const historyId = generateHistoryIngestPipelineId(definition);
await retryTransientEsErrors(
() =>
Expand All @@ -40,11 +39,10 @@ export async function createAndInstallHistoryIngestPipeline(
export async function createAndInstallLatestIngestPipeline(
esClient: ElasticsearchClient,
definition: EntityDefinition,
logger: Logger,
spaceId: string
logger: Logger
) {
try {
const latestProcessors = generateLatestProcessors(definition, spaceId);
const latestProcessors = generateLatestProcessors(definition);
const latestId = generateLatestIngestPipelineId(definition);
await retryTransientEsErrors(
() =>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { generateHistoryProcessors } from './generate_history_processors';

describe('generateHistoryProcessors(definition)', () => {
it('should genearte a valid pipeline', () => {
const processors = generateHistoryProcessors(entityDefinition, 'default');
const processors = generateHistoryProcessors(entityDefinition);
expect(processors).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function createMetadataPainlessScript(definition: EntityDefinition) {
}, '');
}

export function generateHistoryProcessors(definition: EntityDefinition, spaceId: string) {
export function generateHistoryProcessors(definition: EntityDefinition) {
return [
{
set: {
Expand All @@ -57,12 +57,6 @@ export function generateHistoryProcessors(definition: EntityDefinition, spaceId:
value: definition.type,
},
},
{
set: {
field: 'entity.spaceId',
value: spaceId,
},
},
{
set: {
field: 'entity.definitionId',
Expand Down Expand Up @@ -141,7 +135,7 @@ export function generateHistoryProcessors(definition: EntityDefinition, spaceId:
{
date_index_name: {
field: '@timestamp',
index_name_prefix: `${generateHistoryIndexName(definition)}.${spaceId}.`,
index_name_prefix: `${generateHistoryIndexName(definition)}.`,
date_rounding: 'M',
date_formats: ['UNIX_MS', 'ISO8601', "yyyy-MM-dd'T'HH:mm:ss.SSSXX"],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { generateLatestProcessors } from './generate_latest_processors';

describe('generateLatestProcessors(definition)', () => {
it('should genearte a valid pipeline', () => {
const processors = generateLatestProcessors(entityDefinition, 'default');
const processors = generateLatestProcessors(entityDefinition);
expect(processors).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function createMetadataPainlessScript(definition: EntityDefinition) {
}, '');
}

export function generateLatestProcessors(definition: EntityDefinition, spaceId: string) {
export function generateLatestProcessors(definition: EntityDefinition) {
return [
{
set: {
Expand All @@ -51,12 +51,6 @@ export function generateLatestProcessors(definition: EntityDefinition, spaceId:
value: definition.type,
},
},
{
set: {
field: 'entity.spaceId',
value: spaceId,
},
},
{
set: {
field: 'entity.definitionId',
Expand All @@ -80,7 +74,7 @@ export function generateLatestProcessors(definition: EntityDefinition, spaceId:
{
set: {
field: '_index',
value: `${generateLatestIndexName(definition)}.${spaceId}`,
value: `${generateLatestIndexName(definition)}`,
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ describe('install_entity_definition', () => {
soClient,
builtInDefinitions,
logger: loggerMock.create(),
spaceId: 'default',
});

assertHasCreatedDefinition(builtInServicesEntityDefinition, soClient, esClient);
Expand Down Expand Up @@ -159,7 +158,6 @@ describe('install_entity_definition', () => {
soClient,
builtInDefinitions,
logger: loggerMock.create(),
spaceId: 'default',
});

assertHasUninstalledDefinition(builtInServicesEntityDefinition, soClient, esClient);
Expand Down Expand Up @@ -200,7 +198,6 @@ describe('install_entity_definition', () => {
soClient,
builtInDefinitions,
logger: loggerMock.create(),
spaceId: 'default',
});

expect(soClient.create).toHaveBeenCalledTimes(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ export interface InstallDefinitionParams {
soClient: SavedObjectsClientContract;
definition: EntityDefinition;
logger: Logger;
spaceId: string;
}

export async function installEntityDefinition({
esClient,
soClient,
definition,
logger,
spaceId,
}: InstallDefinitionParams): Promise<EntityDefinition> {
const installState = {
ingestPipelines: {
Expand All @@ -66,9 +64,9 @@ export async function installEntityDefinition({

// install ingest pipelines
logger.debug(`Installing ingest pipelines for definition ${definition.id}`);
await createAndInstallHistoryIngestPipeline(esClient, entityDefinition, logger, spaceId);
await createAndInstallHistoryIngestPipeline(esClient, entityDefinition, logger);
installState.ingestPipelines.history = true;
await createAndInstallLatestIngestPipeline(esClient, entityDefinition, logger, spaceId);
await createAndInstallLatestIngestPipeline(esClient, entityDefinition, logger);
installState.ingestPipelines.latest = true;

// install transforms
Expand Down Expand Up @@ -110,7 +108,6 @@ export async function installBuiltInEntityDefinitions({
soClient,
logger,
builtInDefinitions,
spaceId,
}: Omit<InstallDefinitionParams, 'definition'> & {
builtInDefinitions: EntityDefinition[];
}): Promise<EntityDefinition[]> {
Expand All @@ -130,7 +127,6 @@ export async function installBuiltInEntityDefinitions({
esClient,
soClient,
logger,
spaceId,
});
}

Expand All @@ -144,7 +140,6 @@ export async function installBuiltInEntityDefinitions({
esClient,
soClient,
logger,
spaceId,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export class EntityManagerServerPlugin
setupRoutes<RequestHandlerContext>({
router,
logger: this.logger,
spaces: plugins.spaces,
server: this.server,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export function enableEntityDiscoveryRoute<T extends RequestHandlerContext>({
await installBuiltInEntityDefinitions({
logger,
builtInDefinitions,
spaceId: 'default',
esClient: scopedEsClient,
soClient: scopedSoClient,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { installEntityDefinition } from '../../lib/entities/install_entity_defin
export function createEntityDefinitionRoute<T extends RequestHandlerContext>({
router,
server,
spaces,
}: SetupRouteOptions<T>) {
router.post<unknown, unknown, EntityDefinition>(
{
Expand All @@ -39,12 +38,10 @@ export function createEntityDefinitionRoute<T extends RequestHandlerContext>({
const core = await context.core;
const soClient = core.savedObjects.client;
const esClient = core.elasticsearch.client.asCurrentUser;
const spaceId = spaces?.spacesService.getSpaceId(req) ?? 'default';
try {
const definition = await installEntityDefinition({
soClient,
esClient,
spaceId,
logger,
definition: req.body,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { ENTITY_INTERNAL_API_PREFIX } from '../../../common/constants_entities';
export function resetEntityDefinitionRoute<T extends RequestHandlerContext>({
router,
logger,
spaces,
}: SetupRouteOptions<T>) {
router.post<{ id: string }, unknown, unknown>(
{
Expand All @@ -50,7 +49,6 @@ export function resetEntityDefinitionRoute<T extends RequestHandlerContext>({
try {
const soClient = (await context.core).savedObjects.client;
const esClient = (await context.core).elasticsearch.client.asCurrentUser;
const spaceId = spaces?.spacesService.getSpaceId(req) ?? 'default';

const definition = await readEntityDefinition(soClient, req.params.id, logger);

Expand All @@ -62,8 +60,8 @@ export function resetEntityDefinitionRoute<T extends RequestHandlerContext>({
await deleteIndices(esClient, definition, logger);

// Recreate everything
await createAndInstallHistoryIngestPipeline(esClient, definition, logger, spaceId);
await createAndInstallLatestIngestPipeline(esClient, definition, logger, spaceId);
await createAndInstallHistoryIngestPipeline(esClient, definition, logger);
await createAndInstallLatestIngestPipeline(esClient, definition, logger);
await createAndInstallHistoryTransform(esClient, definition, logger);
await createAndInstallLatestTransform(esClient, definition, logger);
await startTransform(esClient, definition, logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

import { IRouter, RequestHandlerContextBase } from '@kbn/core-http-server';
import { Logger } from '@kbn/core/server';
import { SpacesPluginSetup } from '@kbn/spaces-plugin/server';
import { EntityManagerServerSetup } from '../types';

export interface SetupRouteOptions<T extends RequestHandlerContextBase> {
router: IRouter<T>;
server: EntityManagerServerSetup;
logger: Logger;
spaces?: SpacesPluginSetup;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
EncryptedSavedObjectsPluginSetup,
EncryptedSavedObjectsPluginStart,
} from '@kbn/encrypted-saved-objects-plugin/server';
import { SpacesPluginSetup } from '@kbn/spaces-plugin/server';
import { EntityManagerConfig } from '../common/config';

export interface EntityManagerServerSetup {
Expand All @@ -29,7 +28,6 @@ export interface ElasticsearchAccessorOptions {

export interface EntityManagerPluginSetupDependencies {
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup;
spaces?: SpacesPluginSetup;
}

export interface EntityManagerPluginStartDependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@kbn/zod-helpers",
"@kbn/security-plugin",
"@kbn/encrypted-saved-objects-plugin",
"@kbn/spaces-plugin",
"@kbn/logging-mocks",
"@kbn/logging-mocks"
]
}

0 comments on commit 6ca9fec

Please sign in to comment.