Skip to content

Commit

Permalink
Revert "[core/server/plugins] don't run discovery in dev server paren…
Browse files Browse the repository at this point in the history
…t process (#79235)"

This reverts commit 9021c83.
  • Loading branch information
spalger committed Oct 2, 2020
1 parent 1310ac6 commit 66878b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 69 deletions.
81 changes: 24 additions & 57 deletions src/core/server/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,42 +102,35 @@ const createPlugin = (
});
};

async function testSetup(options: { isDevClusterMaster?: boolean } = {}) {
mockPackage.raw = {
branch: 'feature-v1',
version: 'v1',
build: {
distributable: true,
number: 100,
sha: 'feature-v1-build-sha',
},
};

coreId = Symbol('core');
env = Env.createDefault(REPO_ROOT, {
...getEnvOptions(),
isDevClusterMaster: options.isDevClusterMaster ?? false,
});
describe('PluginsService', () => {
beforeEach(async () => {
mockPackage.raw = {
branch: 'feature-v1',
version: 'v1',
build: {
distributable: true,
number: 100,
sha: 'feature-v1-build-sha',
},
};

config$ = new BehaviorSubject<Record<string, any>>({ plugins: { initialize: true } });
const rawConfigService = rawConfigServiceMock.create({ rawConfig$: config$ });
configService = new ConfigService(rawConfigService, env, logger);
await configService.setSchema(config.path, config.schema);
pluginsService = new PluginsService({ coreId, env, logger, configService });
coreId = Symbol('core');
env = Env.createDefault(REPO_ROOT, getEnvOptions());

[mockPluginSystem] = MockPluginsSystem.mock.instances as any;
mockPluginSystem.uiPlugins.mockReturnValue(new Map());
config$ = new BehaviorSubject<Record<string, any>>({ plugins: { initialize: true } });
const rawConfigService = rawConfigServiceMock.create({ rawConfig$: config$ });
configService = new ConfigService(rawConfigService, env, logger);
await configService.setSchema(config.path, config.schema);
pluginsService = new PluginsService({ coreId, env, logger, configService });

environmentSetup = environmentServiceMock.createSetupContract();
}
[mockPluginSystem] = MockPluginsSystem.mock.instances as any;
mockPluginSystem.uiPlugins.mockReturnValue(new Map());

afterEach(() => {
jest.clearAllMocks();
});
environmentSetup = environmentServiceMock.createSetupContract();
});

describe('PluginsService', () => {
beforeEach(async () => {
await testSetup();
afterEach(() => {
jest.clearAllMocks();
});

describe('#discover()', () => {
Expand Down Expand Up @@ -620,29 +613,3 @@ describe('PluginsService', () => {
});
});
});

describe('PluginService when isDevClusterMaster is true', () => {
beforeEach(async () => {
await testSetup({
isDevClusterMaster: true,
});
});

describe('#discover()', () => {
it('does not try to run discovery', async () => {
await expect(pluginsService.discover({ environment: environmentSetup })).resolves
.toMatchInlineSnapshot(`
Object {
"pluginTree": undefined,
"uiPlugins": Object {
"browserConfigs": Map {},
"internal": Map {},
"public": Map {},
},
}
`);

expect(mockDiscover).not.toHaveBeenCalled();
});
});
});
18 changes: 6 additions & 12 deletions src/core/server/plugins/plugins_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import Path from 'path';
import { Observable, EMPTY } from 'rxjs';
import { Observable } from 'rxjs';
import { filter, first, map, mergeMap, tap, toArray } from 'rxjs/operators';
import { pick } from '@kbn/std';

Expand Down Expand Up @@ -86,11 +86,9 @@ export class PluginsService implements CoreService<PluginsServiceSetup, PluginsS
private readonly config$: Observable<PluginsConfig>;
private readonly pluginConfigDescriptors = new Map<PluginName, PluginConfigDescriptor>();
private readonly uiPluginInternalInfo = new Map<PluginName, InternalPluginInfo>();
private readonly discoveryDisabled: boolean;

constructor(private readonly coreContext: CoreContext) {
this.log = coreContext.logger.get('plugins-service');
this.discoveryDisabled = coreContext.env.isDevClusterMaster;
this.pluginsSystem = new PluginsSystem(coreContext);
this.configService = coreContext.configService;
this.config$ = coreContext.configService
Expand All @@ -99,17 +97,13 @@ export class PluginsService implements CoreService<PluginsServiceSetup, PluginsS
}

public async discover({ environment }: PluginsServiceDiscoverDeps) {
const config = await this.config$.pipe(first()).toPromise();
this.log.debug('Discovering plugins');

const { error$, plugin$ } = this.discoveryDisabled
? {
error$: EMPTY,
plugin$: EMPTY,
}
: discover(config, this.coreContext, {
uuid: environment.instanceUuid,
});
const config = await this.config$.pipe(first()).toPromise();

const { error$, plugin$ } = discover(config, this.coreContext, {
uuid: environment.instanceUuid,
});
await this.handleDiscoveryErrors(error$);
await this.handleDiscoveredPlugins(plugin$);

Expand Down

0 comments on commit 66878b4

Please sign in to comment.