Add reportPluginFailures in client.call method

Summary:
Adds an optional "plugin" field to the tracked metrics. The idea is to be able to see failures in plugins.

Added it around all desktop -> sdk "call"s, so it won't require any effort from developers but we'll get lots of immediate data. E.g. How often layout -> getNodes fails. I think we can go modify the existing pipeline to take both platform and plugin data so we can get session roll-ups too.

Corresponding change to the puma app: D13882629, adds a plugin field to all tables so we can filter by plugin, or null for platform failures.

I'm thinking it will be worthwhile to expose some method to plugin developers, that lets them explicitly track failures. It would be better if it encapsulated their plugin id etc, so they just need to say what failed. But that can be done any time, I don't have any particular use cases in mind yet.

Reviewed By: passy

Differential Revision: D13878379

fbshipit-source-id: 2e2ef6b98f763e6edcfe937741d6988dae4b92d1
This commit is contained in:
John Knox
2019-01-31 03:17:13 -08:00
committed by Facebook Github Bot
parent 6d50843eed
commit 77811c66d2
3 changed files with 33 additions and 2 deletions

View File

@@ -16,6 +16,7 @@ import {setPluginState} from './reducers/pluginStates.js';
import {ReactiveSocket, PartialResponder} from 'rsocket-core';
// $FlowFixMe perf_hooks is a new API in node
import {performance} from 'perf_hooks';
import {reportPluginFailures} from './utils/metrics';
const EventEmitter = (require('events'): any);
const invariant = require('invariant');
@@ -368,7 +369,11 @@ export default class Client extends EventEmitter {
}
call(api: string, method: string, params?: Object): Promise<Object> {
return this.rawCall('execute', {api, method, params});
return reportPluginFailures(
this.rawCall('execute', {api, method, params}),
`Call-${method}`,
api,
);
}
send(api: string, method: string, params?: Object): void {

View File

@@ -18,7 +18,7 @@ export default class LogManager {
scribeLogger: ScribeLogger;
track(type: TrackType, event: string, data: ?any) {}
track(type: TrackType, event: string, data: ?any, plugin?: string) {}
trackTimeSince(mark: string, eventName: ?string) {}

View File

@@ -11,6 +11,8 @@ import {getInstance} from '../fb-stubs/Logger';
* Wraps a Promise, preserving it's functionality but logging the success or
failure state of it, with a given name, based on whether it's fulfilled or
rejected.
Use this variant to report failures in core platform (Flipper) code.
*/
export function reportPlatformFailures(
promise: Promise<*>,
@@ -27,3 +29,27 @@ export function reportPlatformFailures(
},
);
}
/*
* Wraps a Promise, preserving it's functionality but logging the success or
failure state of it, with a given name, based on whether it's fulfilled or
rejected.
Use this variant to report failures in plugin code.
*/
export function reportPluginFailures(
promise: Promise<*>,
name: string,
plugin: string,
): Promise<*> {
return promise.then(
fulfilledValue => {
getInstance().track('success-rate', name, 1, plugin);
return fulfilledValue;
},
rejectionReason => {
getInstance().track('success-rate', name, 0, plugin);
return Promise.reject(rejectionReason);
},
);
}