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 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 { export interface Logger {
track(type: TrackType, event: string, data: ?any, plugin?: string): void; 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. * LICENSE file in the root directory of this source tree.
* @format * @format
*/ */
import {CancelledPromiseError} from './errors.tsx';
export class Idler { export class Idler {
lastIdle: number; lastIdle: number;
interval: number; interval: number;
@@ -17,7 +20,7 @@ export class Idler {
idle(): Promise<void> { idle(): Promise<void> {
if (this.kill) { if (this.kill) {
throw new Error('Idler got killed'); throw new CancelledPromiseError('Idler got killed');
} }
const now = performance.now(); const now = performance.now();
if (now - this.lastIdle > this.interval) { if (now - this.lastIdle > this.interval) {

View File

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

View File

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