Expose info endpoint
Summary: Expose an endpoint to retrieve server environment information. We can use version information and process number to aid engineers with troubleshooting Flipper. Reviewed By: antonk52 Differential Revision: D49537325 fbshipit-source-id: 511fe4441638f91cd35f13706ceeeb515051416b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
db07297e2d
commit
bdf5065f10
@@ -154,11 +154,14 @@ async function getFlipperServer(
|
|||||||
|
|
||||||
console.info('[flipper-server] Not running/listening, start');
|
console.info('[flipper-server] Not running/listening, start');
|
||||||
|
|
||||||
const {readyForIncomingConnections} = await startServer({
|
const {readyForIncomingConnections} = await startServer(
|
||||||
|
{
|
||||||
staticPath,
|
staticPath,
|
||||||
entry: 'index.web.dev.html',
|
entry: 'index.web.dev.html',
|
||||||
port,
|
port,
|
||||||
});
|
},
|
||||||
|
environmentInfo,
|
||||||
|
);
|
||||||
|
|
||||||
const server = await startFlipperServer(
|
const server = await startFlipperServer(
|
||||||
appPath,
|
appPath,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {FlipperServerImpl} from '../FlipperServerImpl';
|
|||||||
import {FlipperServerCompanionEnv} from 'flipper-server-companion';
|
import {FlipperServerCompanionEnv} from 'flipper-server-companion';
|
||||||
import {validateAuthToken} from '../app-connectivity/certificate-exchange/certificate-utils';
|
import {validateAuthToken} from '../app-connectivity/certificate-exchange/certificate-utils';
|
||||||
import {tracker} from '../tracker';
|
import {tracker} from '../tracker';
|
||||||
|
import {EnvironmentInfo} from 'flipper-common';
|
||||||
|
|
||||||
type Config = {
|
type Config = {
|
||||||
port: number;
|
port: number;
|
||||||
@@ -89,13 +90,16 @@ let isReadyWaitable: Promise<void> | undefined;
|
|||||||
* @param config Server configuration.
|
* @param config Server configuration.
|
||||||
* @returns Returns a promise to the created server, proxy and WS server.
|
* @returns Returns a promise to the created server, proxy and WS server.
|
||||||
*/
|
*/
|
||||||
export async function startServer(config: Config): Promise<{
|
export async function startServer(
|
||||||
|
config: Config,
|
||||||
|
environmentInfo: EnvironmentInfo,
|
||||||
|
): Promise<{
|
||||||
app: Express;
|
app: Express;
|
||||||
server: http.Server;
|
server: http.Server;
|
||||||
socket: WebSocketServer;
|
socket: WebSocketServer;
|
||||||
readyForIncomingConnections: ReadyForConnections;
|
readyForIncomingConnections: ReadyForConnections;
|
||||||
}> {
|
}> {
|
||||||
return await startHTTPServer(config);
|
return await startHTTPServer(config, environmentInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +108,10 @@ export async function startServer(config: Config): Promise<{
|
|||||||
* @param config Server configuration.
|
* @param config Server configuration.
|
||||||
* @returns A promise to both app and HTTP server.
|
* @returns A promise to both app and HTTP server.
|
||||||
*/
|
*/
|
||||||
async function startHTTPServer(config: Config): Promise<{
|
async function startHTTPServer(
|
||||||
|
config: Config,
|
||||||
|
environmentInfo: EnvironmentInfo,
|
||||||
|
): Promise<{
|
||||||
app: Express;
|
app: Express;
|
||||||
server: http.Server;
|
server: http.Server;
|
||||||
socket: WebSocketServer;
|
socket: WebSocketServer;
|
||||||
@@ -133,6 +140,11 @@ async function startHTTPServer(config: Config): Promise<{
|
|||||||
res.end(JSON.stringify({isReady}));
|
res.end(JSON.stringify({isReady}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/info', (_req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.end(JSON.stringify(environmentInfo));
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/shutdown', (_req, res) => {
|
app.get('/shutdown', (_req, res) => {
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.end(JSON.stringify({success: true}));
|
res.end(JSON.stringify({success: true}));
|
||||||
|
|||||||
@@ -175,11 +175,14 @@ async function start() {
|
|||||||
`[flipper-server][bootstrap] Check for running instances completed (${runningInstanceShutdownMS} ms)`,
|
`[flipper-server][bootstrap] Check for running instances completed (${runningInstanceShutdownMS} ms)`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const {app, server, socket, readyForIncomingConnections} = await startServer({
|
const {app, server, socket, readyForIncomingConnections} = await startServer(
|
||||||
|
{
|
||||||
staticPath,
|
staticPath,
|
||||||
entry: `index.web${argv.bundler ? '.dev' : ''}.html`,
|
entry: `index.web${argv.bundler ? '.dev' : ''}.html`,
|
||||||
port: argv.port,
|
port: argv.port,
|
||||||
});
|
},
|
||||||
|
environmentInfo,
|
||||||
|
);
|
||||||
|
|
||||||
const t4 = performance.now();
|
const t4 = performance.now();
|
||||||
const httpServerStartedMS = t4 - t3;
|
const httpServerStartedMS = t4 - t3;
|
||||||
|
|||||||
Reference in New Issue
Block a user