Fix the export metrics format
Summary: Fix the format of the export. Due to unknown reason the changes done in the D14933499 was [reverted back](https://our.intern.facebook.com/intern/diff/D14933499/?src_number=80619316) on the same diff. Thus this diff fixes the format of the metrics export Reviewed By: passy Differential Revision: D15239653 fbshipit-source-id: b9416f89e1b0022000d6201eb08ca1f456d5ed2e
This commit is contained in:
committed by
Facebook Github Bot
parent
a89b732765
commit
38f3132b66
@@ -17,6 +17,7 @@ export {
|
|||||||
callClient,
|
callClient,
|
||||||
} from './plugin.js';
|
} from './plugin.js';
|
||||||
export type {PluginClient, Props} from './plugin.js';
|
export type {PluginClient, Props} from './plugin.js';
|
||||||
|
export type {MetricType} from './utils/exportMetrics.js';
|
||||||
export {default as Client} from './Client.js';
|
export {default as Client} from './Client.js';
|
||||||
export {clipboard} from 'electron';
|
export {clipboard} from 'electron';
|
||||||
export * from './fb-stubs/constants.js';
|
export * from './fb-stubs/constants.js';
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import type {App} from './App.js';
|
|||||||
import type {Logger} from './fb-interfaces/Logger.js';
|
import type {Logger} from './fb-interfaces/Logger.js';
|
||||||
import type Client from './Client.js';
|
import type Client from './Client.js';
|
||||||
import type {Store, MiddlewareAPI} from './reducers/index.js';
|
import type {Store, MiddlewareAPI} from './reducers/index.js';
|
||||||
|
import type {MetricType} from './utils/exportMetrics.js';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import type {Node} from 'react';
|
import type {Node} from 'react';
|
||||||
import BaseDevice from './devices/BaseDevice.js';
|
import BaseDevice from './devices/BaseDevice.js';
|
||||||
@@ -83,9 +83,9 @@ export class FlipperBasePlugin<
|
|||||||
method: string,
|
method: string,
|
||||||
data: Object,
|
data: Object,
|
||||||
) => $Shape<PersistedState>;
|
) => $Shape<PersistedState>;
|
||||||
static exportMetrics: ?(
|
static metricsReducer: ?(
|
||||||
persistedState: PersistedState,
|
persistedState: PersistedState,
|
||||||
) => Promise<Map<string, number | string>>;
|
) => Promise<MetricType>;
|
||||||
static exportPersistedState: ?(
|
static exportPersistedState: ?(
|
||||||
callClient: (string, ?Object) => Promise<Object>,
|
callClient: (string, ?Object) => Promise<Object>,
|
||||||
persistedState: ?PersistedState,
|
persistedState: ?PersistedState,
|
||||||
|
|||||||
@@ -5,7 +5,12 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {TableHighlightedRows, TableRows, TableBodyRow} from 'flipper';
|
import type {
|
||||||
|
TableHighlightedRows,
|
||||||
|
TableRows,
|
||||||
|
TableBodyRow,
|
||||||
|
MetricType,
|
||||||
|
} from 'flipper';
|
||||||
import {padStart} from 'lodash';
|
import {padStart} from 'lodash';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -107,9 +112,9 @@ export default class extends FlipperPlugin<State, *, PersistedState> {
|
|||||||
responses: {},
|
responses: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
static exportMetrics = (
|
static metricsReducer = (
|
||||||
persistedState: PersistedState,
|
persistedState: PersistedState,
|
||||||
): Promise<Map<string, number | string>> => {
|
): Promise<MetricType> => {
|
||||||
const failures = Object.keys(persistedState.responses).reduce(function(
|
const failures = Object.keys(persistedState.responses).reduce(function(
|
||||||
previous,
|
previous,
|
||||||
key,
|
key,
|
||||||
@@ -117,7 +122,7 @@ export default class extends FlipperPlugin<State, *, PersistedState> {
|
|||||||
return previous + (persistedState.responses[key].status >= 400);
|
return previous + (persistedState.responses[key].status >= 400);
|
||||||
},
|
},
|
||||||
0);
|
0);
|
||||||
return Promise.resolve(new Map([['NUMBER_NETWORK_FAILURES', failures]]));
|
return Promise.resolve({NUMBER_NETWORK_FAILURES: failures});
|
||||||
};
|
};
|
||||||
|
|
||||||
static persistedStateReducer = (
|
static persistedStateReducer = (
|
||||||
|
|||||||
@@ -4,19 +4,19 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
import type {MiddlewareAPI} from '../reducers';
|
|
||||||
import {serialize} from './serialization.js';
|
|
||||||
import type {FlipperPlugin, FlipperDevicePlugin} from 'flipper';
|
import type {FlipperPlugin, FlipperDevicePlugin} from 'flipper';
|
||||||
|
import {serialize} from './serialization';
|
||||||
|
import type {MiddlewareAPI} from '../reducers';
|
||||||
|
|
||||||
type MetricType = Map<string, Map<string, string | number>>;
|
export type MetricType = {[metricName: string]: number};
|
||||||
|
type MetricPluginType = {[pluginID: string]: MetricType};
|
||||||
export type ExportMetricType = Map<string, MetricType>;
|
export type ExportMetricType = {[clientID: string]: MetricPluginType};
|
||||||
|
|
||||||
export default async function exportMetrics(
|
export default async function exportMetrics(
|
||||||
store: MiddlewareAPI,
|
store: MiddlewareAPI,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const state = store.getState();
|
const state = store.getState();
|
||||||
let metrics: ExportMetricType = new Map();
|
const metrics: ExportMetricType = {};
|
||||||
for (let key in state.pluginStates) {
|
for (let key in state.pluginStates) {
|
||||||
const pluginStateData = state.pluginStates[key];
|
const pluginStateData = state.pluginStates[key];
|
||||||
const arr = key.split('#');
|
const arr = key.split('#');
|
||||||
@@ -32,20 +32,19 @@ export default async function exportMetrics(
|
|||||||
state.plugins.devicePlugins.forEach((val, key) => {
|
state.plugins.devicePlugins.forEach((val, key) => {
|
||||||
pluginsMap.set(key, val);
|
pluginsMap.set(key, val);
|
||||||
});
|
});
|
||||||
const exportMetrics1: ?(
|
const metricsReducer: ?(
|
||||||
persistedState: any,
|
persistedState: any,
|
||||||
) => Promise<Map<string, string | number>> = pluginsMap.get(pluginName)
|
) => Promise<MetricType> = pluginsMap.get(pluginName)?.metricsReducer;
|
||||||
?.exportMetrics;
|
if (pluginsMap.has(pluginName) && metricsReducer) {
|
||||||
if (pluginsMap.has(pluginName) && exportMetrics1) {
|
const metricsObject = await metricsReducer(pluginStateData);
|
||||||
const metricMap = await exportMetrics1(pluginStateData);
|
const pluginObject = {};
|
||||||
const pluginMap = new Map([[pluginName, metricMap]]);
|
pluginObject[pluginName] = metricsObject;
|
||||||
if (!metrics.get(clientID)) {
|
if (!metrics[clientID]) {
|
||||||
metrics.set(clientID, pluginMap);
|
metrics[clientID] = pluginObject;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const prevMetricMap = metrics.get(clientID);
|
const mergedMetrics = {...metrics[clientID], ...pluginObject};
|
||||||
// $FlowFixMe: prevMetricMap cannot be null, because clientID is added only when the pluingMetricMap is available
|
metrics[clientID] = mergedMetrics;
|
||||||
metrics.set(clientID, new Map([...prevMetricMap, ...pluginMap]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Promise.resolve(serialize(metrics));
|
return Promise.resolve(serialize(metrics));
|
||||||
|
|||||||
Reference in New Issue
Block a user