mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Endpoint,Ingest]EMT-357: Move Exported Ingest Manager Services to plugin Start (#64138)
[Endpoint,Ingest]EMT-357: Move Exported Ingest Manager Services to plugin Start
This commit is contained in:
parent
5f269b7ee6
commit
51479fda9b
23 changed files with 207 additions and 108 deletions
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { EndpointAppContextService } from './endpoint_app_context_services';
|
||||
|
||||
describe('test endpoint app context services', () => {
|
||||
it('should throw error if start is not called', async () => {
|
||||
const endpointAppContextService = new EndpointAppContextService();
|
||||
expect(() => endpointAppContextService.getIndexPatternRetriever()).toThrow(Error);
|
||||
expect(() => endpointAppContextService.getAgentService()).toThrow(Error);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { IndexPatternRetriever } from './index_pattern';
|
||||
import { AgentService } from '../../ingest_manager/common/types';
|
||||
|
||||
/**
|
||||
* A singleton that holds shared services that are initialized during the start up phase
|
||||
* of the plugin lifecycle. And stop during the stop phase, if needed.
|
||||
*/
|
||||
export class EndpointAppContextService {
|
||||
private indexPatternRetriever: IndexPatternRetriever | undefined;
|
||||
private agentService: AgentService | undefined;
|
||||
|
||||
public start(dependencies: {
|
||||
indexPatternRetriever: IndexPatternRetriever;
|
||||
agentService: AgentService;
|
||||
}) {
|
||||
this.indexPatternRetriever = dependencies.indexPatternRetriever;
|
||||
this.agentService = dependencies.agentService;
|
||||
}
|
||||
|
||||
public stop() {}
|
||||
|
||||
public getAgentService(): AgentService {
|
||||
if (!this.agentService) {
|
||||
throw new Error(`must call start on ${EndpointAppContextService.name} to call getter`);
|
||||
}
|
||||
return this.agentService;
|
||||
}
|
||||
|
||||
public getIndexPatternRetriever(): IndexPatternRetriever {
|
||||
if (!this.indexPatternRetriever) {
|
||||
throw new Error(`must call start on ${EndpointAppContextService.name} to call getter`);
|
||||
}
|
||||
return this.indexPatternRetriever;
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { Logger, LoggerFactory, RequestHandlerContext } from 'kibana/server';
|
||||
import { ESIndexPatternService } from '../../ingest_manager/server';
|
||||
import { EndpointAppConstants } from '../common/types';
|
||||
import { ESIndexPatternService } from '../../ingest_manager/common/types';
|
||||
|
||||
export interface IndexPatternRetriever {
|
||||
getIndexPattern(ctx: RequestHandlerContext, datasetPath: string): Promise<string>;
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { IngestManagerSetupContract } from '../../ingest_manager/server';
|
||||
import { AgentService } from '../../ingest_manager/common/types';
|
||||
import { AgentService, IngestManagerStartupContract } from '../../ingest_manager/common/types';
|
||||
|
||||
/**
|
||||
* Creates a mock IndexPatternRetriever for use in tests.
|
||||
|
@ -47,9 +46,9 @@ export const createMockAgentService = (): jest.Mocked<AgentService> => {
|
|||
* @param indexPattern a string index pattern to return when called by a test
|
||||
* @returns the same value as `indexPattern` parameter
|
||||
*/
|
||||
export const createMockIngestManagerSetupContract = (
|
||||
export const createMockIngestManagerStartupContract = (
|
||||
indexPattern: string
|
||||
): IngestManagerSetupContract => {
|
||||
): IngestManagerStartupContract => {
|
||||
return {
|
||||
esIndexPatternService: {
|
||||
getESIndexPattern: jest.fn().mockResolvedValue(indexPattern),
|
||||
|
|
|
@ -4,15 +4,21 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { EndpointPlugin, EndpointPluginSetupDependencies } from './plugin';
|
||||
import {
|
||||
EndpointPlugin,
|
||||
EndpointPluginSetupDependencies,
|
||||
EndpointPluginStartDependencies,
|
||||
} from './plugin';
|
||||
import { coreMock } from '../../../../src/core/server/mocks';
|
||||
import { PluginSetupContract } from '../../features/server';
|
||||
import { createMockIngestManagerSetupContract } from './mocks';
|
||||
import { createMockIngestManagerStartupContract } from './mocks';
|
||||
|
||||
describe('test endpoint plugin', () => {
|
||||
let plugin: EndpointPlugin;
|
||||
let mockCoreSetup: ReturnType<typeof coreMock.createSetup>;
|
||||
let mockCoreStart: ReturnType<typeof coreMock.createStart>;
|
||||
let mockedEndpointPluginSetupDependencies: jest.Mocked<EndpointPluginSetupDependencies>;
|
||||
let mockedEndpointPluginStartDependencies: jest.Mocked<EndpointPluginStartDependencies>;
|
||||
let mockedPluginSetupContract: jest.Mocked<PluginSetupContract>;
|
||||
beforeEach(() => {
|
||||
plugin = new EndpointPlugin(
|
||||
|
@ -23,21 +29,32 @@ describe('test endpoint plugin', () => {
|
|||
);
|
||||
|
||||
mockCoreSetup = coreMock.createSetup();
|
||||
mockCoreStart = coreMock.createStart();
|
||||
mockedPluginSetupContract = {
|
||||
registerFeature: jest.fn(),
|
||||
getFeatures: jest.fn(),
|
||||
getFeaturesUICapabilities: jest.fn(),
|
||||
registerLegacyAPI: jest.fn(),
|
||||
};
|
||||
mockedEndpointPluginSetupDependencies = {
|
||||
features: mockedPluginSetupContract,
|
||||
ingestManager: createMockIngestManagerSetupContract(''),
|
||||
};
|
||||
});
|
||||
|
||||
it('test properly setup plugin', async () => {
|
||||
mockedEndpointPluginSetupDependencies = {
|
||||
features: mockedPluginSetupContract,
|
||||
};
|
||||
await plugin.setup(mockCoreSetup, mockedEndpointPluginSetupDependencies);
|
||||
expect(mockedPluginSetupContract.registerFeature).toBeCalledTimes(1);
|
||||
expect(mockCoreSetup.http.createRouter).toBeCalledTimes(1);
|
||||
expect(() => plugin.getEndpointAppContextService().getIndexPatternRetriever()).toThrow(Error);
|
||||
expect(() => plugin.getEndpointAppContextService().getAgentService()).toThrow(Error);
|
||||
});
|
||||
|
||||
it('test properly start plugin', async () => {
|
||||
mockedEndpointPluginStartDependencies = {
|
||||
ingestManager: createMockIngestManagerStartupContract(''),
|
||||
};
|
||||
await plugin.start(mockCoreStart, mockedEndpointPluginStartDependencies);
|
||||
expect(plugin.getEndpointAppContextService().getAgentService()).toBeTruthy();
|
||||
expect(plugin.getEndpointAppContextService().getIndexPatternRetriever()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,10 +3,9 @@
|
|||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { Plugin, CoreSetup, PluginInitializerContext, Logger } from 'kibana/server';
|
||||
import { Plugin, CoreSetup, PluginInitializerContext, Logger, CoreStart } from 'kibana/server';
|
||||
import { first } from 'rxjs/operators';
|
||||
import { PluginSetupContract as FeaturesPluginSetupContract } from '../../features/server';
|
||||
import { IngestManagerSetupContract } from '../../ingest_manager/server';
|
||||
import { createConfig$, EndpointConfigType } from './config';
|
||||
import { EndpointAppContext } from './types';
|
||||
|
||||
|
@ -15,14 +14,17 @@ import { registerResolverRoutes } from './routes/resolver';
|
|||
import { registerIndexPatternRoute } from './routes/index_pattern';
|
||||
import { registerEndpointRoutes } from './routes/metadata';
|
||||
import { IngestIndexPatternRetriever } from './index_pattern';
|
||||
import { IngestManagerStartupContract } from '../../ingest_manager/common/types';
|
||||
import { EndpointAppContextService } from './endpoint_app_context_services';
|
||||
|
||||
export type EndpointPluginStart = void;
|
||||
export type EndpointPluginSetup = void;
|
||||
export interface EndpointPluginStartDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface
|
||||
export interface EndpointPluginStartDependencies {
|
||||
ingestManager: IngestManagerStartupContract;
|
||||
}
|
||||
|
||||
export interface EndpointPluginSetupDependencies {
|
||||
features: FeaturesPluginSetupContract;
|
||||
ingestManager: IngestManagerSetupContract;
|
||||
}
|
||||
|
||||
export class EndpointPlugin
|
||||
|
@ -34,9 +36,15 @@ export class EndpointPlugin
|
|||
EndpointPluginStartDependencies
|
||||
> {
|
||||
private readonly logger: Logger;
|
||||
private readonly endpointAppContextService: EndpointAppContextService = new EndpointAppContextService();
|
||||
constructor(private readonly initializerContext: PluginInitializerContext) {
|
||||
this.logger = this.initializerContext.logger.get('endpoint');
|
||||
}
|
||||
|
||||
public getEndpointAppContextService(): EndpointAppContextService {
|
||||
return this.endpointAppContextService;
|
||||
}
|
||||
|
||||
public setup(core: CoreSetup, plugins: EndpointPluginSetupDependencies) {
|
||||
plugins.features.registerFeature({
|
||||
id: 'endpoint',
|
||||
|
@ -66,12 +74,8 @@ export class EndpointPlugin
|
|||
},
|
||||
});
|
||||
const endpointContext = {
|
||||
indexPatternRetriever: new IngestIndexPatternRetriever(
|
||||
plugins.ingestManager.esIndexPatternService,
|
||||
this.initializerContext.logger
|
||||
),
|
||||
agentService: plugins.ingestManager.agentService,
|
||||
logFactory: this.initializerContext.logger,
|
||||
service: this.endpointAppContextService,
|
||||
config: (): Promise<EndpointConfigType> => {
|
||||
return createConfig$(this.initializerContext)
|
||||
.pipe(first())
|
||||
|
@ -85,10 +89,18 @@ export class EndpointPlugin
|
|||
registerIndexPatternRoute(router, endpointContext);
|
||||
}
|
||||
|
||||
public start() {
|
||||
public start(core: CoreStart, plugins: EndpointPluginStartDependencies) {
|
||||
this.logger.debug('Starting plugin');
|
||||
this.endpointAppContextService.start({
|
||||
indexPatternRetriever: new IngestIndexPatternRetriever(
|
||||
plugins.ingestManager.esIndexPatternService,
|
||||
this.initializerContext.logger
|
||||
),
|
||||
agentService: plugins.ingestManager.agentService,
|
||||
});
|
||||
}
|
||||
public stop() {
|
||||
this.logger.debug('Stopping plugin');
|
||||
this.endpointAppContextService.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,25 +13,35 @@ import { registerAlertRoutes } from './index';
|
|||
import { EndpointConfigSchema } from '../../config';
|
||||
import { alertingIndexGetQuerySchema } from '../../../common/schema/alert_index';
|
||||
import { createMockAgentService, createMockIndexPatternRetriever } from '../../mocks';
|
||||
import { EndpointAppContextService } from '../../endpoint_app_context_services';
|
||||
|
||||
describe('test alerts route', () => {
|
||||
let routerMock: jest.Mocked<IRouter>;
|
||||
let mockClusterClient: jest.Mocked<IClusterClient>;
|
||||
let mockScopedClient: jest.Mocked<IScopedClusterClient>;
|
||||
let endpointAppContextService: EndpointAppContextService;
|
||||
|
||||
beforeEach(() => {
|
||||
mockClusterClient = elasticsearchServiceMock.createClusterClient();
|
||||
mockScopedClient = elasticsearchServiceMock.createScopedClusterClient();
|
||||
mockClusterClient.asScoped.mockReturnValue(mockScopedClient);
|
||||
routerMock = httpServiceMock.createRouter();
|
||||
registerAlertRoutes(routerMock, {
|
||||
|
||||
endpointAppContextService = new EndpointAppContextService();
|
||||
endpointAppContextService.start({
|
||||
indexPatternRetriever: createMockIndexPatternRetriever('events-endpoint-*'),
|
||||
agentService: createMockAgentService(),
|
||||
});
|
||||
|
||||
registerAlertRoutes(routerMock, {
|
||||
logFactory: loggingServiceMock.create(),
|
||||
service: endpointAppContextService,
|
||||
config: () => Promise.resolve(EndpointConfigSchema.validate({})),
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => endpointAppContextService.stop());
|
||||
|
||||
it('should fail to validate when `page_size` is not a number', async () => {
|
||||
const validate = () => {
|
||||
alertingIndexGetQuerySchema.validate({
|
||||
|
|
|
@ -26,7 +26,9 @@ export const alertDetailsHandlerWrapper = function(
|
|||
id: alertId,
|
||||
})) as GetResponse<AlertEvent>;
|
||||
|
||||
const indexPattern = await endpointAppContext.indexPatternRetriever.getEventIndexPattern(ctx);
|
||||
const indexPattern = await endpointAppContext.service
|
||||
.getIndexPatternRetriever()
|
||||
.getEventIndexPattern(ctx);
|
||||
|
||||
const config = await endpointAppContext.config();
|
||||
const pagination: AlertDetailsPagination = new AlertDetailsPagination(
|
||||
|
|
|
@ -18,7 +18,9 @@ export const alertListHandlerWrapper = function(
|
|||
res
|
||||
) => {
|
||||
try {
|
||||
const indexPattern = await endpointAppContext.indexPatternRetriever.getEventIndexPattern(ctx);
|
||||
const indexPattern = await endpointAppContext.service
|
||||
.getIndexPatternRetriever()
|
||||
.getEventIndexPattern(ctx);
|
||||
const reqData = await getRequestData(req, endpointAppContext);
|
||||
const response = await searchESForAlerts(
|
||||
ctx.core.elasticsearch.dataClient,
|
||||
|
|
|
@ -8,14 +8,14 @@ import { IRouter, Logger, RequestHandler } from 'kibana/server';
|
|||
import { EndpointAppContext } from '../types';
|
||||
import { IndexPatternGetParamsResult, EndpointAppConstants } from '../../common/types';
|
||||
import { indexPatternGetParamsSchema } from '../../common/schema/index_pattern';
|
||||
import { IndexPatternRetriever } from '../index_pattern';
|
||||
|
||||
function handleIndexPattern(
|
||||
log: Logger,
|
||||
indexRetriever: IndexPatternRetriever
|
||||
endpointAppContext: EndpointAppContext
|
||||
): RequestHandler<IndexPatternGetParamsResult> {
|
||||
return async (context, req, res) => {
|
||||
try {
|
||||
const indexRetriever = endpointAppContext.service.getIndexPatternRetriever();
|
||||
return res.ok({
|
||||
body: {
|
||||
indexPattern: await indexRetriever.getIndexPattern(context, req.params.datasetPath),
|
||||
|
@ -37,6 +37,6 @@ export function registerIndexPatternRoute(router: IRouter, endpointAppContext: E
|
|||
validate: { params: indexPatternGetParamsSchema },
|
||||
options: { authRequired: true },
|
||||
},
|
||||
handleIndexPattern(log, endpointAppContext.indexPatternRetriever)
|
||||
handleIndexPattern(log, endpointAppContext)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -61,9 +61,9 @@ export function registerEndpointRoutes(router: IRouter, endpointAppContext: Endp
|
|||
},
|
||||
async (context, req, res) => {
|
||||
try {
|
||||
const index = await endpointAppContext.indexPatternRetriever.getMetadataIndexPattern(
|
||||
context
|
||||
);
|
||||
const index = await endpointAppContext.service
|
||||
.getIndexPatternRetriever()
|
||||
.getMetadataIndexPattern(context);
|
||||
const queryParams = await kibanaRequestToMetadataListESQuery(
|
||||
req,
|
||||
endpointAppContext,
|
||||
|
@ -117,9 +117,9 @@ export async function getHostData(
|
|||
metadataRequestContext: MetadataRequestContext,
|
||||
id: string
|
||||
): Promise<HostInfo | undefined> {
|
||||
const index = await metadataRequestContext.endpointAppContext.indexPatternRetriever.getMetadataIndexPattern(
|
||||
metadataRequestContext.requestHandlerContext
|
||||
);
|
||||
const index = await metadataRequestContext.endpointAppContext.service
|
||||
.getIndexPatternRetriever()
|
||||
.getMetadataIndexPattern(metadataRequestContext.requestHandlerContext);
|
||||
const query = getESQueryHostMetadataByID(id, index);
|
||||
const response = (await metadataRequestContext.requestHandlerContext.core.elasticsearch.dataClient.callAsCurrentUser(
|
||||
'search',
|
||||
|
@ -179,10 +179,12 @@ async function enrichHostMetadata(
|
|||
log.warn(`Missing elastic agent id, using host id instead ${elasticAgentId}`);
|
||||
}
|
||||
|
||||
const status = await metadataRequestContext.endpointAppContext.agentService.getAgentStatusById(
|
||||
metadataRequestContext.requestHandlerContext.core.savedObjects.client,
|
||||
elasticAgentId
|
||||
);
|
||||
const status = await metadataRequestContext.endpointAppContext.service
|
||||
.getAgentService()
|
||||
.getAgentStatusById(
|
||||
metadataRequestContext.requestHandlerContext.core.savedObjects.client,
|
||||
elasticAgentId
|
||||
);
|
||||
hostStatus = HOST_STATUS_MAPPING.get(status) || HostStatus.ERROR;
|
||||
} catch (e) {
|
||||
if (e.isBoom && e.output.statusCode === 404) {
|
||||
|
|
|
@ -28,6 +28,7 @@ import * as data from '../../test_data/all_metadata_data.json';
|
|||
import { createMockAgentService, createMockMetadataIndexPatternRetriever } from '../../mocks';
|
||||
import { AgentService } from '../../../../ingest_manager/common/types';
|
||||
import Boom from 'boom';
|
||||
import { EndpointAppContextService } from '../../endpoint_app_context_services';
|
||||
|
||||
describe('test endpoint route', () => {
|
||||
let routerMock: jest.Mocked<IRouter>;
|
||||
|
@ -38,6 +39,7 @@ describe('test endpoint route', () => {
|
|||
let routeHandler: RequestHandler<any, any, any>;
|
||||
let routeConfig: RouteConfig<any, any, any, any>;
|
||||
let mockAgentService: jest.Mocked<AgentService>;
|
||||
let endpointAppContextService: EndpointAppContextService;
|
||||
|
||||
beforeEach(() => {
|
||||
mockClusterClient = elasticsearchServiceMock.createClusterClient() as jest.Mocked<
|
||||
|
@ -49,14 +51,21 @@ describe('test endpoint route', () => {
|
|||
routerMock = httpServiceMock.createRouter();
|
||||
mockResponse = httpServerMock.createResponseFactory();
|
||||
mockAgentService = createMockAgentService();
|
||||
registerEndpointRoutes(routerMock, {
|
||||
endpointAppContextService = new EndpointAppContextService();
|
||||
endpointAppContextService.start({
|
||||
indexPatternRetriever: createMockMetadataIndexPatternRetriever(),
|
||||
agentService: mockAgentService,
|
||||
});
|
||||
|
||||
registerEndpointRoutes(routerMock, {
|
||||
logFactory: loggingServiceMock.create(),
|
||||
service: endpointAppContextService,
|
||||
config: () => Promise.resolve(EndpointConfigSchema.validate({})),
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => endpointAppContextService.stop());
|
||||
|
||||
function createRouteHandlerContext(
|
||||
dataClient: jest.Mocked<IScopedClusterClient>,
|
||||
savedObjectsClient: jest.Mocked<SavedObjectsClientContract>
|
||||
|
|
|
@ -6,11 +6,8 @@
|
|||
import { httpServerMock, loggingServiceMock } from '../../../../../../src/core/server/mocks';
|
||||
import { EndpointConfigSchema } from '../../config';
|
||||
import { kibanaRequestToMetadataListESQuery, getESQueryHostMetadataByID } from './query_builders';
|
||||
import {
|
||||
createMockAgentService,
|
||||
createMockMetadataIndexPatternRetriever,
|
||||
MetadataIndexPattern,
|
||||
} from '../../mocks';
|
||||
import { MetadataIndexPattern } from '../../mocks';
|
||||
import { EndpointAppContextService } from '../../endpoint_app_context_services';
|
||||
|
||||
describe('query builder', () => {
|
||||
describe('MetadataListESQuery', () => {
|
||||
|
@ -21,9 +18,8 @@ describe('query builder', () => {
|
|||
const query = await kibanaRequestToMetadataListESQuery(
|
||||
mockRequest,
|
||||
{
|
||||
indexPatternRetriever: createMockMetadataIndexPatternRetriever(),
|
||||
agentService: createMockAgentService(),
|
||||
logFactory: loggingServiceMock.create(),
|
||||
service: new EndpointAppContextService(),
|
||||
config: () => Promise.resolve(EndpointConfigSchema.validate({})),
|
||||
},
|
||||
MetadataIndexPattern
|
||||
|
@ -73,9 +69,8 @@ describe('query builder', () => {
|
|||
const query = await kibanaRequestToMetadataListESQuery(
|
||||
mockRequest,
|
||||
{
|
||||
indexPatternRetriever: createMockMetadataIndexPatternRetriever(),
|
||||
agentService: createMockAgentService(),
|
||||
logFactory: loggingServiceMock.create(),
|
||||
service: new EndpointAppContextService(),
|
||||
config: () => Promise.resolve(EndpointConfigSchema.validate({})),
|
||||
},
|
||||
MetadataIndexPattern
|
||||
|
|
|
@ -12,7 +12,6 @@ import { handleLifecycle, validateLifecycle } from './resolver/lifecycle';
|
|||
|
||||
export function registerResolverRoutes(router: IRouter, endpointAppContext: EndpointAppContext) {
|
||||
const log = endpointAppContext.logFactory.get('resolver');
|
||||
const indexPatternService = endpointAppContext.indexPatternRetriever;
|
||||
|
||||
router.get(
|
||||
{
|
||||
|
@ -20,7 +19,7 @@ export function registerResolverRoutes(router: IRouter, endpointAppContext: Endp
|
|||
validate: validateRelatedEvents,
|
||||
options: { authRequired: true },
|
||||
},
|
||||
handleRelatedEvents(log, indexPatternService)
|
||||
handleRelatedEvents(log, endpointAppContext)
|
||||
);
|
||||
|
||||
router.get(
|
||||
|
@ -29,7 +28,7 @@ export function registerResolverRoutes(router: IRouter, endpointAppContext: Endp
|
|||
validate: validateChildren,
|
||||
options: { authRequired: true },
|
||||
},
|
||||
handleChildren(log, indexPatternService)
|
||||
handleChildren(log, endpointAppContext)
|
||||
);
|
||||
|
||||
router.get(
|
||||
|
@ -38,6 +37,6 @@ export function registerResolverRoutes(router: IRouter, endpointAppContext: Endp
|
|||
validate: validateLifecycle,
|
||||
options: { authRequired: true },
|
||||
},
|
||||
handleLifecycle(log, indexPatternService)
|
||||
handleLifecycle(log, endpointAppContext)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import { extractEntityID } from './utils/normalize';
|
|||
import { getPaginationParams } from './utils/pagination';
|
||||
import { LifecycleQuery } from './queries/lifecycle';
|
||||
import { ChildrenQuery } from './queries/children';
|
||||
import { IndexPatternRetriever } from '../../index_pattern';
|
||||
import { EndpointAppContext } from '../../types';
|
||||
|
||||
interface ChildrenQueryParams {
|
||||
after?: string;
|
||||
|
@ -47,7 +47,7 @@ export const validateChildren = {
|
|||
|
||||
export function handleChildren(
|
||||
log: Logger,
|
||||
indexRetriever: IndexPatternRetriever
|
||||
endpointAppContext: EndpointAppContext
|
||||
): RequestHandler<ChildrenPathParams, ChildrenQueryParams> {
|
||||
return async (context, req, res) => {
|
||||
const {
|
||||
|
@ -55,6 +55,7 @@ export function handleChildren(
|
|||
query: { limit, after, legacyEndpointID },
|
||||
} = req;
|
||||
try {
|
||||
const indexRetriever = endpointAppContext.service.getIndexPatternRetriever();
|
||||
const pagination = getPaginationParams(limit, after);
|
||||
const indexPattern = await indexRetriever.getEventIndexPattern(context);
|
||||
|
||||
|
|
|
@ -4,13 +4,12 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { RequestHandler, Logger } from 'kibana/server';
|
||||
import { extractParentEntityID } from './utils/normalize';
|
||||
import { LifecycleQuery } from './queries/lifecycle';
|
||||
import { ResolverEvent } from '../../../common/types';
|
||||
import { IndexPatternRetriever } from '../../index_pattern';
|
||||
import { EndpointAppContext } from '../../types';
|
||||
|
||||
interface LifecycleQueryParams {
|
||||
ancestors: number;
|
||||
|
@ -48,7 +47,7 @@ function getParentEntityID(results: ResolverEvent[]) {
|
|||
|
||||
export function handleLifecycle(
|
||||
log: Logger,
|
||||
indexRetriever: IndexPatternRetriever
|
||||
endpointAppContext: EndpointAppContext
|
||||
): RequestHandler<LifecyclePathParams, LifecycleQueryParams> {
|
||||
return async (context, req, res) => {
|
||||
const {
|
||||
|
@ -56,6 +55,7 @@ export function handleLifecycle(
|
|||
query: { ancestors, legacyEndpointID },
|
||||
} = req;
|
||||
try {
|
||||
const indexRetriever = endpointAppContext.service.getIndexPatternRetriever();
|
||||
const ancestorLifecycles = [];
|
||||
const client = context.core.elasticsearch.dataClient;
|
||||
const indexPattern = await indexRetriever.getEventIndexPattern(context);
|
||||
|
|
|
@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema';
|
|||
import { RequestHandler, Logger } from 'kibana/server';
|
||||
import { getPaginationParams } from './utils/pagination';
|
||||
import { RelatedEventsQuery } from './queries/related_events';
|
||||
import { IndexPatternRetriever } from '../../index_pattern';
|
||||
import { EndpointAppContext } from '../../types';
|
||||
|
||||
interface RelatedEventsQueryParams {
|
||||
after?: string;
|
||||
|
@ -44,7 +44,7 @@ export const validateRelatedEvents = {
|
|||
|
||||
export function handleRelatedEvents(
|
||||
log: Logger,
|
||||
indexRetriever: IndexPatternRetriever
|
||||
endpointAppContext: EndpointAppContext
|
||||
): RequestHandler<RelatedEventsPathParams, RelatedEventsQueryParams> {
|
||||
return async (context, req, res) => {
|
||||
const {
|
||||
|
@ -52,6 +52,7 @@ export function handleRelatedEvents(
|
|||
query: { limit, after, legacyEndpointID },
|
||||
} = req;
|
||||
try {
|
||||
const indexRetriever = endpointAppContext.service.getIndexPatternRetriever();
|
||||
const pagination = getPaginationParams(limit, after);
|
||||
|
||||
const client = context.core.elasticsearch.dataClient;
|
||||
|
|
|
@ -5,15 +5,17 @@
|
|||
*/
|
||||
import { LoggerFactory } from 'kibana/server';
|
||||
import { EndpointConfigType } from './config';
|
||||
import { IndexPatternRetriever } from './index_pattern';
|
||||
import { AgentService } from '../../ingest_manager/common/types';
|
||||
import { EndpointAppContextService } from './endpoint_app_context_services';
|
||||
|
||||
/**
|
||||
* The context for Endpoint apps.
|
||||
*/
|
||||
export interface EndpointAppContext {
|
||||
indexPatternRetriever: IndexPatternRetriever;
|
||||
agentService: AgentService;
|
||||
logFactory: LoggerFactory;
|
||||
config(): Promise<EndpointConfigType>;
|
||||
|
||||
/**
|
||||
* Object readiness is tied to plugin start method
|
||||
*/
|
||||
service: EndpointAppContextService;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,25 @@ import { AgentStatus } from './models';
|
|||
export * from './models';
|
||||
export * from './rest_spec';
|
||||
|
||||
/**
|
||||
* Service to return the index pattern of EPM packages
|
||||
*/
|
||||
export interface ESIndexPatternService {
|
||||
getESIndexPattern(
|
||||
savedObjectsClient: SavedObjectsClientContract,
|
||||
pkgName: string,
|
||||
datasetPath: string
|
||||
): Promise<string | undefined>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes public IngestManager plugin contract returned at the `startup` stage.
|
||||
*/
|
||||
export interface IngestManagerStartupContract {
|
||||
esIndexPatternService: ESIndexPatternService;
|
||||
agentService: AgentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* A service that provides exported functions that return information about an Agent
|
||||
*/
|
||||
|
|
|
@ -7,9 +7,6 @@ import { schema, TypeOf } from '@kbn/config-schema';
|
|||
import { PluginInitializerContext } from 'src/core/server';
|
||||
import { IngestManagerPlugin } from './plugin';
|
||||
|
||||
export { ESIndexPatternService } from './services';
|
||||
export { IngestManagerSetupContract } from './plugin';
|
||||
|
||||
export const config = {
|
||||
exposeToBrowser: {
|
||||
epm: true,
|
||||
|
|
|
@ -39,22 +39,10 @@ import {
|
|||
registerInstallScriptRoutes,
|
||||
} from './routes';
|
||||
|
||||
import { AgentService, IngestManagerConfigType } from '../common';
|
||||
import {
|
||||
appContextService,
|
||||
ESIndexPatternService,
|
||||
ESIndexPatternSavedObjectService,
|
||||
} from './services';
|
||||
import { IngestManagerConfigType, IngestManagerStartupContract } from '../common';
|
||||
import { appContextService, ESIndexPatternSavedObjectService } from './services';
|
||||
import { getAgentStatusById } from './services/agents';
|
||||
|
||||
/**
|
||||
* Describes public IngestManager plugin contract returned at the `setup` stage.
|
||||
*/
|
||||
export interface IngestManagerSetupContract {
|
||||
esIndexPatternService: ESIndexPatternService;
|
||||
agentService: AgentService;
|
||||
}
|
||||
|
||||
export interface IngestManagerSetupDeps {
|
||||
licensing: LicensingPluginSetup;
|
||||
security?: SecurityPluginSetup;
|
||||
|
@ -78,7 +66,7 @@ const allSavedObjectTypes = [
|
|||
ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
|
||||
];
|
||||
|
||||
export class IngestManagerPlugin implements Plugin<IngestManagerSetupContract> {
|
||||
export class IngestManagerPlugin implements Plugin<void, IngestManagerStartupContract> {
|
||||
private config$: Observable<IngestManagerConfigType>;
|
||||
private security: SecurityPluginSetup | undefined;
|
||||
|
||||
|
@ -86,10 +74,7 @@ export class IngestManagerPlugin implements Plugin<IngestManagerSetupContract> {
|
|||
this.config$ = this.initializerContext.config.create<IngestManagerConfigType>();
|
||||
}
|
||||
|
||||
public async setup(
|
||||
core: CoreSetup,
|
||||
deps: IngestManagerSetupDeps
|
||||
): Promise<RecursiveReadonly<IngestManagerSetupContract>> {
|
||||
public async setup(core: CoreSetup, deps: IngestManagerSetupDeps) {
|
||||
if (deps.security) {
|
||||
this.security = deps.security;
|
||||
}
|
||||
|
@ -148,6 +133,20 @@ export class IngestManagerPlugin implements Plugin<IngestManagerSetupContract> {
|
|||
basePath: core.http.basePath,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async start(
|
||||
core: CoreStart,
|
||||
plugins: {
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
|
||||
}
|
||||
): Promise<RecursiveReadonly<IngestManagerStartupContract>> {
|
||||
appContextService.start({
|
||||
encryptedSavedObjects: plugins.encryptedSavedObjects,
|
||||
security: this.security,
|
||||
config$: this.config$,
|
||||
savedObjects: core.savedObjects,
|
||||
});
|
||||
return deepFreeze({
|
||||
esIndexPatternService: new ESIndexPatternSavedObjectService(),
|
||||
agentService: {
|
||||
|
@ -156,20 +155,6 @@ export class IngestManagerPlugin implements Plugin<IngestManagerSetupContract> {
|
|||
});
|
||||
}
|
||||
|
||||
public async start(
|
||||
core: CoreStart,
|
||||
plugins: {
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
|
||||
}
|
||||
) {
|
||||
appContextService.start({
|
||||
encryptedSavedObjects: plugins.encryptedSavedObjects,
|
||||
security: this.security,
|
||||
config$: this.config$,
|
||||
savedObjects: core.savedObjects,
|
||||
});
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
appContextService.stop();
|
||||
}
|
||||
|
|
|
@ -4,15 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { SavedObjectsClientContract } from 'kibana/server';
|
||||
import { getInstallation } from './epm/packages/get';
|
||||
|
||||
export interface ESIndexPatternService {
|
||||
getESIndexPattern(
|
||||
savedObjectsClient: SavedObjectsClientContract,
|
||||
pkgName: string,
|
||||
datasetPath: string
|
||||
): Promise<string | undefined>;
|
||||
}
|
||||
import { getInstallation } from './epm/packages';
|
||||
import { ESIndexPatternService } from '../../common/types';
|
||||
|
||||
export class ESIndexPatternSavedObjectService implements ESIndexPatternService {
|
||||
public async getESIndexPattern(
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
export { appContextService } from './app_context';
|
||||
export { ESIndexPatternService, ESIndexPatternSavedObjectService } from './es_index_pattern';
|
||||
export { ESIndexPatternSavedObjectService } from './es_index_pattern';
|
||||
|
||||
// Saved object services
|
||||
export { datasourceService } from './datasource';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue