From 4832d6275ba8c715443d3b1f96f275953185b4a2 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 9 Dec 2020 05:31:13 -0800 Subject: [PATCH] Fix `activatePlugin` measurements not completing Summary: `activatePlugin` events where not recorded correctly for Sandy plugins. Although the starting measuerments is fired the `connections` reducer, the completing event fires from `PluginContainer`. Since this is done as part of a ref-update (!!), see [here](https://www.internalfb.com/intern/diffusion/FBS/browse/master/xplat/sonar/desktop/app/src/PluginContainer.tsx?commit=65a625ea9941&lines=155), and the ref to the corresponding element is not set for Sandy plugins, the event was never marked as completed. Fixed this by making it part of the `activate` life-cycle event of Sandy plugins. Reviewed By: passy Differential Revision: D25421537 fbshipit-source-id: 5cbfeb91cc12e4520fa271bab24034094d7ddb39 --- desktop/app/src/utils/flipperLibImplementation.tsx | 2 ++ desktop/flipper-plugin/src/plugin/FlipperLib.tsx | 2 ++ desktop/flipper-plugin/src/plugin/PluginBase.tsx | 3 +++ desktop/flipper-plugin/src/test-utils/test-utils.tsx | 2 ++ desktop/flipper-plugin/src/utils/Logger.tsx | 6 ++++-- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/desktop/app/src/utils/flipperLibImplementation.tsx b/desktop/app/src/utils/flipperLibImplementation.tsx index 0028685ef..838c3da8a 100644 --- a/desktop/app/src/utils/flipperLibImplementation.tsx +++ b/desktop/app/src/utils/flipperLibImplementation.tsx @@ -12,6 +12,7 @@ import type {Logger} from '../fb-interfaces/Logger'; import type {Store} from '../reducers'; import createPaste from '../fb-stubs/createPaste'; import GK from '../fb-stubs/GK'; +import {getInstance} from '../fb-stubs/Logger'; let flipperLibInstance: FlipperLib | undefined; @@ -22,6 +23,7 @@ export function initializeFlipperLibImplementation( // late require to avoid cyclic dependency const {addSandyPluginEntries} = require('../MenuBar'); flipperLibInstance = { + logger: getInstance(), enableMenuEntries(entries) { addSandyPluginEntries(entries); }, diff --git a/desktop/flipper-plugin/src/plugin/FlipperLib.tsx b/desktop/flipper-plugin/src/plugin/FlipperLib.tsx index 485fdfb3b..9e49c9215 100644 --- a/desktop/flipper-plugin/src/plugin/FlipperLib.tsx +++ b/desktop/flipper-plugin/src/plugin/FlipperLib.tsx @@ -7,12 +7,14 @@ * @format */ +import {Logger} from '../utils/Logger'; import {NormalizedMenuEntry} from './MenuEntry'; /** * This interface exposes all global methods for which an implementation will be provided by Flipper itself */ export interface FlipperLib { + logger: Logger; enableMenuEntries(menuEntries: NormalizedMenuEntry[]): void; createPaste(input: string): Promise; GK(gatekeeper: string): boolean; diff --git a/desktop/flipper-plugin/src/plugin/PluginBase.tsx b/desktop/flipper-plugin/src/plugin/PluginBase.tsx index 97481ca53..ad0ba53d6 100644 --- a/desktop/flipper-plugin/src/plugin/PluginBase.tsx +++ b/desktop/flipper-plugin/src/plugin/PluginBase.tsx @@ -172,6 +172,9 @@ export abstract class BasePluginInstance { this.activated = true; this.flipperLib.enableMenuEntries(this.menuEntries); this.events.emit('activate'); + this.flipperLib.logger.trackTimeSince( + `activePlugin-${this.definition.id}`, + ); } } diff --git a/desktop/flipper-plugin/src/test-utils/test-utils.tsx b/desktop/flipper-plugin/src/test-utils/test-utils.tsx index 1b43662b3..2f3bd7dfc 100644 --- a/desktop/flipper-plugin/src/test-utils/test-utils.tsx +++ b/desktop/flipper-plugin/src/test-utils/test-utils.tsx @@ -36,6 +36,7 @@ import { } from '../plugin/DevicePlugin'; import {BasePluginInstance} from '../plugin/PluginBase'; import {FlipperLib} from '../plugin/FlipperLib'; +import {stubLogger} from '../utils/Logger'; type Renderer = RenderResult; @@ -346,6 +347,7 @@ export function renderDevicePlugin( export function createMockFlipperLib(options?: StartPluginOptions): FlipperLib { return { + logger: stubLogger, enableMenuEntries: jest.fn(), createPaste: jest.fn(), GK(gk: string) { diff --git a/desktop/flipper-plugin/src/utils/Logger.tsx b/desktop/flipper-plugin/src/utils/Logger.tsx index 7a9a3e51a..c23350973 100644 --- a/desktop/flipper-plugin/src/utils/Logger.tsx +++ b/desktop/flipper-plugin/src/utils/Logger.tsx @@ -35,7 +35,7 @@ export interface Logger { debug(data: any, category: string): void; } -export const _LoggerContext = createContext({ +export const stubLogger: Logger = { track() {}, trackTimeSince() {}, info() { @@ -54,7 +54,9 @@ export const _LoggerContext = createContext({ // eslint-disable-next-line console.debug.apply(console, arguments as any); }, -}); +}; + +export const _LoggerContext = createContext(stubLogger); /** * Provides the default logger that can be used for console logging,