Skip to content

Commit ea8ea4e

Browse files
Spencerspalgerkibanamachine
authored
[dev/cli] detect worker type using env, not cluster module (#83977)
* [dev/cli] detect worker type using env, not cluster module * remove unused property * assume that if process.send is undefined we are not a child * update comment Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 0fe8a65 commit ea8ea4e

22 files changed

Lines changed: 43 additions & 72 deletions

File tree

packages/kbn-config/src/__mocks__/env.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export function getEnvOptions(options: DeepPartial<EnvOptions> = {}): EnvOptions
4242
runExamples: false,
4343
...(options.cliArgs || {}),
4444
},
45-
isDevClusterMaster:
46-
options.isDevClusterMaster !== undefined ? options.isDevClusterMaster : false,
45+
isDevCliParent: options.isDevCliParent !== undefined ? options.isDevCliParent : false,
4746
};
4847
}

packages/kbn-config/src/__snapshots__/env.test.ts.snap

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/kbn-config/src/env.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test('correctly creates default environment in dev mode.', () => {
4747
REPO_ROOT,
4848
getEnvOptions({
4949
configs: ['/test/cwd/config/kibana.yml'],
50-
isDevClusterMaster: true,
50+
isDevCliParent: true,
5151
})
5252
);
5353

packages/kbn-config/src/env.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { PackageInfo, EnvironmentMode } from './types';
2626
export interface EnvOptions {
2727
configs: string[];
2828
cliArgs: CliArgs;
29-
isDevClusterMaster: boolean;
29+
isDevCliParent: boolean;
3030
}
3131

3232
/** @internal */
@@ -101,10 +101,10 @@ export class Env {
101101
public readonly configs: readonly string[];
102102

103103
/**
104-
* Indicates that this Kibana instance is run as development Node Cluster master.
104+
* Indicates that this Kibana instance is running in the parent process of the dev cli.
105105
* @internal
106106
*/
107-
public readonly isDevClusterMaster: boolean;
107+
public readonly isDevCliParent: boolean;
108108

109109
/**
110110
* @internal
@@ -122,7 +122,7 @@ export class Env {
122122

123123
this.cliArgs = Object.freeze(options.cliArgs);
124124
this.configs = Object.freeze(options.configs);
125-
this.isDevClusterMaster = options.isDevClusterMaster;
125+
this.isDevCliParent = options.isDevCliParent;
126126

127127
const isDevMode = this.cliArgs.dev || this.cliArgs.envName === 'development';
128128
this.mode = Object.freeze<EnvironmentMode>({

packages/kbn-legacy-logging/src/log_format_string.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const type = _.memoize((t: string) => {
5454
return color(t)(_.pad(t, 7).slice(0, 7));
5555
});
5656

57-
const workerType = process.env.kbnWorkerType ? `${type(process.env.kbnWorkerType)} ` : '';
57+
const prefix = process.env.isDevCliChild ? `${type('server')} ` : '';
5858

5959
export class KbnLoggerStringFormat extends BaseLogFormat {
6060
format(data: Record<string, any>) {
@@ -71,6 +71,6 @@ export class KbnLoggerStringFormat extends BaseLogFormat {
7171
return s + `[${color(t)(t)}]`;
7272
}, '');
7373

74-
return `${workerType}${type(data.type)} [${time}] ${tags} ${msg}`;
74+
return `${prefix}${type(data.type)} [${time}] ${tags} ${msg}`;
7575
}
7676
}

packages/kbn-legacy-logging/src/rotate/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import { isMaster, isWorker } from 'cluster';
2120
import { Server } from '@hapi/hapi';
2221
import { LogRotator } from './log_rotator';
2322
import { LegacyLoggingConfig } from '../schema';
@@ -30,12 +29,6 @@ export async function setupLoggingRotate(server: Server, config: LegacyLoggingCo
3029
return;
3130
}
3231

33-
// We just want to start the logging rotate service once
34-
// and we choose to use the master (prod) or the worker server (dev)
35-
if (!isMaster && isWorker && process.env.kbnWorkerType !== 'server') {
36-
return;
37-
}
38-
3932
// We don't want to run logging rotate server if
4033
// we are not logging to a file
4134
if (config.dest === 'stdout') {

packages/kbn-legacy-logging/src/rotate/log_rotator.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
import * as chokidar from 'chokidar';
21-
import { isMaster } from 'cluster';
2221
import fs from 'fs';
2322
import { Server } from '@hapi/hapi';
2423
import { throttle } from 'lodash';
@@ -351,22 +350,14 @@ export class LogRotator {
351350
}
352351

353352
_sendReloadLogConfigSignal() {
354-
if (isMaster) {
355-
(process as NodeJS.EventEmitter).emit('SIGHUP');
353+
if (!process.env.isDevCliChild || !process.send) {
354+
process.emit('SIGHUP', 'SIGHUP');
356355
return;
357356
}
358357

359358
// Send a special message to the cluster manager
360359
// so it can forward it correctly
361360
// It will only run when we are under cluster mode (not under a production environment)
362-
if (!process.send) {
363-
this.log(
364-
['error', 'logging:rotate'],
365-
'For some unknown reason process.send is not defined, the rotation was not successful'
366-
);
367-
return;
368-
}
369-
370361
process.send(['RELOAD_LOGGING_CONFIG_FROM_SERVER_WORKER']);
371362
}
372363
}

src/apm.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ let apmConfig;
3030
const isKibanaDistributable = Boolean(build && build.distributable === true);
3131

3232
module.exports = function (serviceName = name) {
33-
if (process.env.kbnWorkerType === 'optmzr') {
34-
return;
35-
}
36-
3733
apmConfig = loadConfiguration(process.argv, ROOT_DIR, isKibanaDistributable);
3834
const conf = apmConfig.getConfig(serviceName);
3935
const apm = require('elastic-apm-node');

src/cli/cluster/cluster_manager.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import { BasePathProxyServer } from '../../core/server/http';
3333
import { Log } from './log';
3434
import { Worker } from './worker';
3535

36-
process.env.kbnWorkerType = 'managr';
37-
3836
export type SomeCliArgs = Pick<
3937
CliArgs,
4038
| 'quiet'

src/cli/cluster/worker.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export class Worker extends EventEmitter {
5656
private readonly clusterBinder: BinderFor;
5757
private readonly processBinder: BinderFor;
5858

59-
private type: string;
6059
private title: string;
6160
private log: any;
6261
private forkBinder: BinderFor | null = null;
@@ -76,7 +75,6 @@ export class Worker extends EventEmitter {
7675
super();
7776

7877
this.log = opts.log;
79-
this.type = opts.type;
8078
this.title = opts.title || opts.type;
8179
this.watch = opts.watch !== false;
8280
this.startCount = 0;
@@ -88,7 +86,7 @@ export class Worker extends EventEmitter {
8886

8987
this.env = {
9088
NODE_OPTIONS: process.env.NODE_OPTIONS || '',
91-
kbnWorkerType: this.type,
89+
isDevCliChild: 'true',
9290
kbnWorkerArgv: JSON.stringify([...(opts.baseArgv || baseArgv), ...(opts.argv || [])]),
9391
ELASTIC_APM_SERVICE_NAME: opts.apmServiceName || '',
9492
};

0 commit comments

Comments
 (0)