Do not log the cancelled flipper export as a failure

Summary: Currently cancelling the flipper export logs the event as a failure. This diff introduces one more event log type called cancelled.

Reviewed By: jknoxville

Differential Revision: D16711110

fbshipit-source-id: 308b7e64974610dbb17bd14b2425f6d939c99313
This commit is contained in:
Pritesh Nandgaonkar
2019-08-12 08:07:09 -07:00
committed by Facebook Github Bot
parent c4a89da960
commit 3401d1ef3c
4 changed files with 44 additions and 12 deletions

View File

@@ -6,7 +6,12 @@
*/
export type LogTypes = 'error' | 'warn' | 'info' | 'debug';
export type TrackType = 'duration' | 'usage' | 'performance' | 'success-rate';
export type TrackType =
| 'duration'
| 'usage'
| 'performance'
| 'success-rate'
| 'operation-cancelled';
export interface Logger {
track(type: TrackType, event: string, data: ?any, plugin?: string): void;

View File

@@ -4,6 +4,9 @@
* LICENSE file in the root directory of this source tree.
* @format
*/
import {CancelledPromiseError} from './errors.tsx';
export class Idler {
lastIdle: number;
interval: number;
@@ -17,7 +20,7 @@ export class Idler {
idle(): Promise<void> {
if (this.kill) {
throw new Error('Idler got killed');
throw new CancelledPromiseError('Idler got killed');
}
const now = performance.now();
if (now - this.lastIdle > this.interval) {

View File

@@ -5,6 +5,12 @@
* @format
*/
export class CancelledPromiseError extends Error {
constructor(msg: string) {
super(msg);
this.name = 'CancelledPromiseError';
}
}
export function getStringFromErrorLike(e: any) {
if (typeof e == 'string') {
return e;

View File

@@ -6,6 +6,7 @@
*/
import {getInstance} from '../fb-stubs/Logger.tsx';
import {CancelledPromiseError} from './errors.tsx';
export class UnsupportedError extends Error {
constructor(message: string) {
@@ -30,11 +31,17 @@ export function reportPlatformFailures<T>(
return fulfilledValue;
},
rejectionReason => {
if (rejectionReason instanceof CancelledPromiseError) {
logPlatformSuccessRate(name, {
isCancelled: true,
});
} else {
logPlatformSuccessRate(name, {
isSuccess: false,
supportedOperation: !(rejectionReason instanceof UnsupportedError),
error: rejectionReason,
});
}
return Promise.reject(rejectionReason);
},
);
@@ -58,11 +65,17 @@ export function reportPluginFailures<T>(
return fulfilledValue;
},
rejectionReason => {
if (rejectionReason instanceof CancelledPromiseError) {
logPluginSuccessRate(name, plugin, {
isCancelled: true,
});
} else {
logPluginSuccessRate(name, plugin, {
isSuccess: false,
supportedOperation: !(rejectionReason instanceof UnsupportedError),
error: rejectionReason,
});
}
return Promise.reject(rejectionReason);
},
);
@@ -92,11 +105,14 @@ export function tryCatchReportPlatformFailures<T>(
type Result =
| {isSuccess: true}
| {isCancelled: true}
| {isSuccess: false, supportedOperation: boolean, error: any};
function logPlatformSuccessRate(name: string, result: Result) {
if (result.isSuccess) {
getInstance().track('success-rate', name, {value: 1});
} else if (result.isCancelled) {
getInstance().track('operation-cancelled', name);
} else {
getInstance().track('success-rate', name, {
value: 0,
@@ -109,6 +125,8 @@ function logPlatformSuccessRate(name: string, result: Result) {
function logPluginSuccessRate(name: string, plugin: string, result: Result) {
if (result.isSuccess) {
getInstance().track('success-rate', name, {value: 1}, plugin);
} else if (result.isCancelled) {
getInstance().track('operation-cancelled', name, undefined, plugin);
} else {
getInstance().track(
'success-rate',