Skip to content

Commit b01f33e

Browse files
Spencerspalgerkibanamachine
authored
[cli/dev] make optimizer delays more obvious and hide proxy target url (#84835)
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 3d3eb40 commit b01f33e

4 files changed

Lines changed: 64 additions & 6 deletions

File tree

src/core/server/http/base_path_proxy_server.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ export class BasePathProxyServer {
5252
return this.devConfig.basePathProxyTargetPort;
5353
}
5454

55+
public get host() {
56+
return this.httpConfig.host;
57+
}
58+
59+
public get port() {
60+
return this.httpConfig.port;
61+
}
62+
5563
constructor(
5664
private readonly log: Logger,
5765
private readonly httpConfig: HttpConfig,
@@ -92,7 +100,10 @@ export class BasePathProxyServer {
92100
await this.server.start();
93101

94102
this.log.info(
95-
`basepath proxy server running at ${this.server.info.uri}${this.httpConfig.basePath}`
103+
`basepath proxy server running at ${Url.format({
104+
host: this.server.info.uri,
105+
pathname: this.httpConfig.basePath,
106+
})}`
96107
);
97108
}
98109

src/dev/cli_dev_mode/cli_dev_mode.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ it('passes correct args to sub-classes', () => {
9595
],
9696
"gracefulTimeout": 5000,
9797
"log": <TestLog>,
98+
"mapLogLine": [Function],
9899
"script": <absolute path>/scripts/kibana,
99100
"watcher": Watcher {
100101
"serverShouldRestart$": [MockFunction],

src/dev/cli_dev_mode/cli_dev_mode.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Path from 'path';
2121

2222
import { REPO_ROOT } from '@kbn/dev-utils';
2323
import * as Rx from 'rxjs';
24-
import { mapTo, filter, take } from 'rxjs/operators';
24+
import { mapTo, filter, take, tap, distinctUntilChanged, switchMap } from 'rxjs/operators';
2525

2626
import { CliArgs } from '../../core/server/config';
2727
import { LegacyConfig } from '../../core/server/legacy';
@@ -142,6 +142,15 @@ export class CliDevMode {
142142
]
143143
: []),
144144
],
145+
mapLogLine: (line) => {
146+
if (!this.basePathProxy) {
147+
return line;
148+
}
149+
150+
return line
151+
.split(`${this.basePathProxy.host}:${this.basePathProxy.targetPort}`)
152+
.join(`${this.basePathProxy.host}:${this.basePathProxy.port}`);
153+
},
145154
});
146155

147156
this.optimizer = new Optimizer({
@@ -168,10 +177,41 @@ export class CliDevMode {
168177
this.subscription = new Rx.Subscription();
169178

170179
if (basePathProxy) {
171-
const delay$ = firstAllTrue(this.devServer.isReady$(), this.optimizer.isReady$());
180+
const serverReady$ = new Rx.BehaviorSubject(false);
181+
const optimizerReady$ = new Rx.BehaviorSubject(false);
182+
const userWaiting$ = new Rx.BehaviorSubject(false);
183+
184+
this.subscription.add(
185+
Rx.merge(
186+
this.devServer.isReady$().pipe(tap(serverReady$)),
187+
this.optimizer.isReady$().pipe(tap(optimizerReady$)),
188+
userWaiting$.pipe(
189+
distinctUntilChanged(),
190+
switchMap((waiting) =>
191+
!waiting
192+
? Rx.EMPTY
193+
: Rx.timer(1000).pipe(
194+
tap(() => {
195+
this.log.warn(
196+
'please hold',
197+
!optimizerReady$.getValue()
198+
? 'optimizer is still bundling so requests have been paused'
199+
: 'server is not ready so requests have been paused'
200+
);
201+
})
202+
)
203+
)
204+
)
205+
).subscribe(this.observer('readiness checks'))
206+
);
172207

173208
basePathProxy.start({
174-
delayUntil: () => delay$,
209+
delayUntil: () => {
210+
userWaiting$.next(true);
211+
return firstAllTrue(serverReady$, optimizerReady$).pipe(
212+
tap(() => userWaiting$.next(false))
213+
);
214+
},
175215
shouldRedirectFromOldBasePath,
176216
});
177217

src/dev/cli_dev_mode/dev_server.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface Options {
4545
processExit$?: Rx.Observable<void>;
4646
sigint$?: Rx.Observable<void>;
4747
sigterm$?: Rx.Observable<void>;
48+
mapLogLine?: DevServer['mapLogLine'];
4849
}
4950

5051
export class DevServer {
@@ -59,6 +60,7 @@ export class DevServer {
5960
private readonly script: string;
6061
private readonly argv: string[];
6162
private readonly gracefulTimeout: number;
63+
private readonly mapLogLine?: (line: string) => string | null;
6264

6365
constructor(options: Options) {
6466
this.log = options.log;
@@ -70,6 +72,7 @@ export class DevServer {
7072
this.processExit$ = options.processExit$ ?? Rx.fromEvent(process as EventEmitter, 'exit');
7173
this.sigint$ = options.sigint$ ?? Rx.fromEvent(process as EventEmitter, 'SIGINT');
7274
this.sigterm$ = options.sigterm$ ?? Rx.fromEvent(process as EventEmitter, 'SIGTERM');
75+
this.mapLogLine = options.mapLogLine;
7376
}
7477

7578
isReady$() {
@@ -124,8 +127,11 @@ export class DevServer {
124127
// observable which emits devServer states containing lines
125128
// logged to stdout/stderr, completes when stdio streams complete
126129
const log$ = Rx.merge(observeLines(proc.stdout!), observeLines(proc.stderr!)).pipe(
127-
tap((line) => {
128-
this.log.write(line);
130+
tap((observedLine) => {
131+
const line = this.mapLogLine ? this.mapLogLine(observedLine) : observedLine;
132+
if (line !== null) {
133+
this.log.write(line);
134+
}
129135
})
130136
);
131137

0 commit comments

Comments
 (0)