Define a tracker interface and replace auth token tracking
Summary: Define the tracker interface and replace the existing authentication token verification tracking. Subsequent diffs will add analytics for remaining connectivity areas. Need to answer: - No tokens rate over time - Unable to verify tokens rate over time Reviewed By: antonk52 Differential Revision: D46219661 fbshipit-source-id: dfc41cae664bc1ef211d312990120111fca3808b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8aed5cfb9c
commit
694f6f284e
@@ -24,7 +24,7 @@ import {attachSocketServer} from './attachSocketServer';
|
|||||||
import {FlipperServerImpl} from '../FlipperServerImpl';
|
import {FlipperServerImpl} from '../FlipperServerImpl';
|
||||||
import {FlipperServerCompanionEnv} from 'flipper-server-companion';
|
import {FlipperServerCompanionEnv} from 'flipper-server-companion';
|
||||||
import {validateAuthToken} from '../utils/certificateUtils';
|
import {validateAuthToken} from '../utils/certificateUtils';
|
||||||
import {getLogger} from 'flipper-common';
|
import {tracker} from '../utils/tracker';
|
||||||
|
|
||||||
type Config = {
|
type Config = {
|
||||||
port: number;
|
port: number;
|
||||||
@@ -51,20 +51,27 @@ const verifyAuthToken = (req: http.IncomingMessage): boolean => {
|
|||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
console.warn('[conn] A token is required for authentication');
|
console.warn('[conn] A token is required for authentication');
|
||||||
getLogger().track('usage', 'client-authentication-token-not-found');
|
tracker.track('server-auth-token-verification', {
|
||||||
|
successful: false,
|
||||||
|
present: false,
|
||||||
|
error: 'No token was supplied',
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
validateAuthToken(token);
|
validateAuthToken(token);
|
||||||
console.info('[conn] Token was successfully validated');
|
console.info('[conn] Token was successfully validated');
|
||||||
getLogger().track('usage', 'client-authentication-token-validation', {
|
tracker.track('server-auth-token-verification', {
|
||||||
valid: true,
|
successful: true,
|
||||||
|
present: true,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('[conn] An invalid token was supplied for authentication');
|
console.warn('[conn] An invalid token was supplied for authentication');
|
||||||
getLogger().track('usage', 'client-authentication-token-validation', {
|
tracker.track('server-auth-token-verification', {
|
||||||
valid: false,
|
successful: false,
|
||||||
|
present: true,
|
||||||
|
error: err.toString(),
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -169,6 +176,7 @@ async function startProxyServer(
|
|||||||
console.warn(
|
console.warn(
|
||||||
`Cannot start flipper-server because socket ${socketPath} is in use.`,
|
`Cannot start flipper-server because socket ${socketPath} is in use.`,
|
||||||
);
|
);
|
||||||
|
// TODO: track socket is in use.
|
||||||
} else {
|
} else {
|
||||||
console.info(`Cleaning up stale socket ${socketPath}`);
|
console.info(`Cleaning up stale socket ${socketPath}`);
|
||||||
await fs.rm(socketPath, {force: true});
|
await fs.rm(socketPath, {force: true});
|
||||||
@@ -204,6 +212,8 @@ async function startProxyServer(
|
|||||||
res.writeHead(502, 'Failed to proxy request');
|
res.writeHead(502, 'Failed to proxy request');
|
||||||
}
|
}
|
||||||
res.end('Failed to proxy request: ' + err);
|
res.end('Failed to proxy request: ' + err);
|
||||||
|
// TODO: should exit as proxying requests will continue to fail.
|
||||||
|
// TODO: track these instances.
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@@ -215,6 +225,8 @@ async function startProxyServer(
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
proxyServer?.listen(config.port);
|
proxyServer?.listen(config.port);
|
||||||
server.listen(socketPath, undefined, () => resolve());
|
server.listen(socketPath, undefined, () => resolve());
|
||||||
|
|
||||||
|
// TODO: track server has started at this stage.
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
resolve({app, server, socket, readyForIncomingConnections});
|
resolve({app, server, socket, readyForIncomingConnections});
|
||||||
|
|||||||
29
desktop/flipper-server-core/src/utils/tracker.tsx
Normal file
29
desktop/flipper-server-core/src/utils/tracker.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* 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 {getLogger} from 'flipper-common';
|
||||||
|
|
||||||
|
type TrackerEvents = {
|
||||||
|
'server-auth-token-verification': {
|
||||||
|
successful: boolean;
|
||||||
|
present: boolean;
|
||||||
|
error?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
class ServerCoreTracker {
|
||||||
|
track<Event extends keyof TrackerEvents>(
|
||||||
|
event: Event,
|
||||||
|
payload: TrackerEvents[Event],
|
||||||
|
): void {
|
||||||
|
getLogger().track('usage', event, payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const tracker = new ServerCoreTracker();
|
||||||
Reference in New Issue
Block a user