From 1360e906f8a89dc1bd9e9420b9b1e274ba991207 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Thu, 24 Aug 2023 06:18:39 -0700 Subject: [PATCH] Centralise sessionId to a dedicated place Summary: The sessionId is just uuid() which is held by the config. This changes moves that to a single place. This achieves two goals: 1) Makes it very clear where is created and what value it holds 2) It allows us to know the sessionId even before the config is available. This becomes useful as we can start logging to Scribe earlier. Reviewed By: passy Differential Revision: D48601829 fbshipit-source-id: c54d86d76f0b58d2b59f8dd1c45d7f345c4a84c3 --- desktop/app/src/init.tsx | 4 ++-- desktop/flipper-dump/src/index.tsx | 4 ++-- desktop/flipper-server-core/src/index.tsx | 2 ++ .../src/server/startFlipperServer.tsx | 4 ++-- desktop/flipper-server-core/src/sessionId.tsx | 12 ++++++++++++ 5 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 desktop/flipper-server-core/src/sessionId.tsx diff --git a/desktop/app/src/init.tsx b/desktop/app/src/init.tsx index 3ac2a37b7..989cd73bc 100644 --- a/desktop/app/src/init.tsx +++ b/desktop/app/src/init.tsx @@ -28,6 +28,7 @@ import { loadLauncherSettings, loadProcessConfig, loadSettings, + sessionId, setupPrefetcher, startFlipperServer, startServer, @@ -39,7 +40,6 @@ import { Logger, parseEnvironmentVariables, setLoggerInstance, - uuid, wrapRequire, } from 'flipper-common'; import constants from './fb-stubs/constants'; @@ -167,7 +167,7 @@ async function getFlipperServer( const getEmbeddedServer = async () => { const server = new FlipperServerImpl( { - sessionId: uuid(), + sessionId, environmentInfo, env: parseEnvironmentVariables(env), gatekeepers: gatekeepers, diff --git a/desktop/flipper-dump/src/index.tsx b/desktop/flipper-dump/src/index.tsx index c5f8f9294..bf826c0a8 100644 --- a/desktop/flipper-dump/src/index.tsx +++ b/desktop/flipper-dump/src/index.tsx @@ -16,6 +16,7 @@ import { loadLauncherSettings, loadProcessConfig, loadSettings, + sessionId, } from 'flipper-server-core'; import { ClientDescription, @@ -23,7 +24,6 @@ import { DeviceDescription, setLoggerInstance, parseEnvironmentVariables, - uuid, } from 'flipper-common'; import path from 'path'; import {stdout} from 'process'; @@ -95,7 +95,7 @@ async function start(deviceQuery: string, appName: string, pluginId: string) { ]); const server = new FlipperServerImpl( { - sessionId: uuid(), + sessionId, environmentInfo, env: parseEnvironmentVariables(process.env), gatekeepers: {}, diff --git a/desktop/flipper-server-core/src/index.tsx b/desktop/flipper-server-core/src/index.tsx index 0edbf02fb..63d995ab3 100644 --- a/desktop/flipper-server-core/src/index.tsx +++ b/desktop/flipper-server-core/src/index.tsx @@ -28,3 +28,5 @@ export { getAuthToken, hasAuthToken, } from './app-connectivity/certificate-exchange/certificate-utils'; + +export {sessionId} from './sessionId'; diff --git a/desktop/flipper-server-core/src/server/startFlipperServer.tsx b/desktop/flipper-server-core/src/server/startFlipperServer.tsx index e6de71bee..25604ffe4 100644 --- a/desktop/flipper-server-core/src/server/startFlipperServer.tsx +++ b/desktop/flipper-server-core/src/server/startFlipperServer.tsx @@ -13,7 +13,6 @@ import { getLogger, FlipperServerType, EnvironmentInfo, - uuid, } from 'flipper-common'; import path from 'path'; import fs from 'fs-extra'; @@ -23,6 +22,7 @@ import {getGatekeepers} from '../gk'; import {loadLauncherSettings} from '../utils/launcherSettings'; import {loadProcessConfig} from '../utils/processConfig'; import {loadSettings} from '../utils/settings'; +import {sessionId} from '../sessionId'; /** * Creates an instance of FlipperServer (FlipperServerImpl). This is the @@ -59,7 +59,7 @@ export async function startFlipperServer( ]); return new FlipperServerImpl( { - sessionId: uuid(), + sessionId, environmentInfo, env: parseEnvironmentVariables(process.env), gatekeepers: getGatekeepers(environmentInfo.os.unixname), diff --git a/desktop/flipper-server-core/src/sessionId.tsx b/desktop/flipper-server-core/src/sessionId.tsx new file mode 100644 index 000000000..4df6f1020 --- /dev/null +++ b/desktop/flipper-server-core/src/sessionId.tsx @@ -0,0 +1,12 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import {uuid} from 'flipper-common'; + +export const sessionId = uuid();