Skip to content

Commit 542bfdf

Browse files
cdamusmartin-fleck-at
authored andcommitted
Suppress file dropping and non-errors
- implement a mechanism to suppress the built-in handling of trace file drop - support injection of a customizer of the HTTP RPC engine that will be used to not re-throw the error reported on close of the HTTP RPC websocket
1 parent cf14701 commit 542bfdf

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

ui/src/common/http_rpc_engine.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ export interface HttpRpcState {
2929
failure?: string;
3030
}
3131

32+
/** A call-back to customize a newly created HTTP+RPC engine. */
33+
export type HttpRcpEngineCustomizer = (engine: HttpRpcEngine) => unknown;
34+
3235
export class HttpRpcEngine extends Engine {
3336
readonly id: string;
3437
errorHandler: (err: string) => void = () => {};
38+
closeHandler: (code: number, reason: string) => void = (code, reason) => this.errorHandler(`Websocket closed (${code}: ${reason})`);
3539
private requestQueue = new Array<Uint8Array>();
3640
private websocket?: WebSocket;
3741
private connected = false;
@@ -47,7 +51,7 @@ export class HttpRpcEngine extends Engine {
4751
this.websocket.onopen = () => this.onWebsocketConnected();
4852
this.websocket.onmessage = (e) => this.onWebsocketMessage(e);
4953
this.websocket.onclose = (e) =>
50-
this.errorHandler(`Websocket closed (${e.code}: ${e.reason})`);
54+
this.closeHandler(e.code, e.reason);
5155
this.websocket.onerror = (e) =>
5256
this.errorHandler(`WebSocket error: ${e}`);
5357
}

ui/src/controller/trace_controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ export class TraceController extends Controller<States> {
342342
Actions.setEngineFailed({mode: 'HTTP_RPC', failure: `${err}`}));
343343
throw err;
344344
};
345+
globals.httpRpcEngineCustomizer?.(engine);
345346
} else {
346347
console.log('Opening trace using built-in WASM engine');
347348
engineMode = 'WASM';

ui/src/frontend/globals.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import { HttpRcpEngineCustomizer } from '../common/http_rpc_engine';
1516
import { assertExists } from '../base/logging';
1617
import { Actions, DeferredAction } from '../common/actions';
1718
import { AggregateData } from '../common/aggregation_data';
@@ -253,6 +254,8 @@ class Globals {
253254
private _cachePrefix: string = '';
254255

255256
private _viewOpener?: ViewOpener = undefined;
257+
private _allowFileDrop = true;
258+
private _httpRpcEngineCustomizer?: HttpRcpEngineCustomizer;
256259

257260
// Init from session storage since correct value may be required very early on
258261
private _relaxContentSecurity: boolean = window.sessionStorage.getItem(RELAX_CONTENT_SECURITY) === 'true';
@@ -632,6 +635,22 @@ class Globals {
632635
this._viewOpener = viewOpener;
633636
}
634637

638+
get allowFileDrop(): boolean {
639+
return this._allowFileDrop;
640+
}
641+
642+
set allowFileDrop(allowFileDrop: boolean) {
643+
this._allowFileDrop = allowFileDrop;
644+
}
645+
646+
get httpRpcEngineCustomizer(): HttpRcpEngineCustomizer | undefined {
647+
return this._httpRpcEngineCustomizer;
648+
}
649+
650+
set httpRpcEngineCustomizer(httpRpcEngineCustomizer: HttpRcpEngineCustomizer | undefined) {
651+
this._httpRpcEngineCustomizer = httpRpcEngineCustomizer;
652+
}
653+
635654
makeSelection(action: DeferredAction<{}>, tabToOpen = 'current_selection') {
636655
// A new selection should cancel the current search selection.
637656
globals.dispatch(Actions.setSearchIndex({index: -1}));

ui/src/frontend/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ function onCssLoaded() {
355355
// accidentially clober the state of an open trace processor instance
356356
// otherwise.
357357
CheckHttpRpcConnection().then(() => {
358-
if (!globals.embeddedMode) {
358+
if (!globals.embeddedMode && globals.allowFileDrop) {
359359
installFileDropHandler();
360360
}
361361

0 commit comments

Comments
 (0)