Skip to content

Commit

Permalink
Fix plugin lifecycle log to only include server plugins (#68686)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
joshdover and elasticmachine authored Jun 15, 2020
1 parent 4d02eab commit a7900d0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
32 changes: 32 additions & 0 deletions src/core/server/plugins/plugins_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { PluginWrapper } from './plugin';
import { PluginName } from './types';
import { PluginsSystem } from './plugins_system';
import { coreMock } from '../mocks';
import { Logger } from '../logging';

const logger = loggingServiceMock.create();
function createPlugin(
Expand Down Expand Up @@ -435,6 +436,21 @@ describe('setup', () => {
`[Error: Setup lifecycle of "timeout-setup" plugin wasn't completed in 30sec. Consider disabling the plugin and re-start.]`
);
});

it('logs only server-side plugins', async () => {
[
createPlugin('order-0'),
createPlugin('order-not-run', { server: false }),
createPlugin('order-1'),
].forEach((plugin, index) => {
jest.spyOn(plugin, 'setup').mockResolvedValue(`setup-as-${index}`);
jest.spyOn(plugin, 'start').mockResolvedValue(`started-as-${index}`);
pluginsSystem.addPlugin(plugin);
});
await pluginsSystem.setupPlugins(setupDeps);
const log = logger.get.mock.results[0].value as jest.Mocked<Logger>;
expect(log.info).toHaveBeenCalledWith(`Setting up [2] plugins: [order-1,order-0]`);
});
});

describe('start', () => {
Expand All @@ -461,4 +477,20 @@ describe('start', () => {
`[Error: Start lifecycle of "timeout-start" plugin wasn't completed in 30sec. Consider disabling the plugin and re-start.]`
);
});

it('logs only server-side plugins', async () => {
[
createPlugin('order-0'),
createPlugin('order-not-run', { server: false }),
createPlugin('order-1'),
].forEach((plugin, index) => {
jest.spyOn(plugin, 'setup').mockResolvedValue(`setup-as-${index}`);
jest.spyOn(plugin, 'start').mockResolvedValue(`started-as-${index}`);
pluginsSystem.addPlugin(plugin);
});
await pluginsSystem.setupPlugins(setupDeps);
await pluginsSystem.startPlugins(startDeps);
const log = logger.get.mock.results[0].value as jest.Mocked<Logger>;
expect(log.info).toHaveBeenCalledWith(`Starting [2] plugins: [order-1,order-0]`);
});
});
17 changes: 9 additions & 8 deletions src/core/server/plugins/plugins_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ export class PluginsSystem {
return contracts;
}

const sortedPlugins = this.getTopologicallySortedPluginNames();
this.log.info(`Setting up [${this.plugins.size}] plugins: [${[...sortedPlugins]}]`);

for (const pluginName of sortedPlugins) {
const plugin = this.plugins.get(pluginName)!;
if (!plugin.includesServerPlugin) {
continue;
}
const sortedPlugins = new Map(
[...this.getTopologicallySortedPluginNames()]
.map((pluginName) => [pluginName, this.plugins.get(pluginName)!] as [string, PluginWrapper])
.filter(([pluginName, plugin]) => plugin.includesServerPlugin)
);
this.log.info(
`Setting up [${sortedPlugins.size}] plugins: [${[...sortedPlugins.keys()].join(',')}]`
);

for (const [pluginName, plugin] of sortedPlugins) {
this.log.debug(`Setting up plugin "${pluginName}"...`);
const pluginDeps = new Set([...plugin.requiredPlugins, ...plugin.optionalPlugins]);
const pluginDepContracts = Array.from(pluginDeps).reduce((depContracts, dependencyName) => {
Expand Down

0 comments on commit a7900d0

Please sign in to comment.