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,
|
||||
} 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 {clipboard} from 'electron';
|
||||
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 Client from './Client.js';
|
||||
import type {Store, MiddlewareAPI} from './reducers/index.js';
|
||||
|
||||
import type {MetricType} from './utils/exportMetrics.js';
|
||||
import React from 'react';
|
||||
import type {Node} from 'react';
|
||||
import BaseDevice from './devices/BaseDevice.js';
|
||||
@@ -83,9 +83,9 @@ export class FlipperBasePlugin<
|
||||
method: string,
|
||||
data: Object,
|
||||
) => $Shape<PersistedState>;
|
||||
static exportMetrics: ?(
|
||||
static metricsReducer: ?(
|
||||
persistedState: PersistedState,
|
||||
) => Promise<Map<string, number | string>>;
|
||||
) => Promise<MetricType>;
|
||||
static exportPersistedState: ?(
|
||||
callClient: (string, ?Object) => Promise<Object>,
|
||||
persistedState: ?PersistedState,
|
||||
|
||||
@@ -5,7 +5,12 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {TableHighlightedRows, TableRows, TableBodyRow} from 'flipper';
|
||||
import type {
|
||||
TableHighlightedRows,
|
||||
TableRows,
|
||||
TableBodyRow,
|
||||
MetricType,
|
||||
} from 'flipper';
|
||||
import {padStart} from 'lodash';
|
||||
|
||||
import {
|
||||
@@ -107,9 +112,9 @@ export default class extends FlipperPlugin<State, *, PersistedState> {
|
||||
responses: {},
|
||||
};
|
||||
|
||||
static exportMetrics = (
|
||||
static metricsReducer = (
|
||||
persistedState: PersistedState,
|
||||
): Promise<Map<string, number | string>> => {
|
||||
): Promise<MetricType> => {
|
||||
const failures = Object.keys(persistedState.responses).reduce(function(
|
||||
previous,
|
||||
key,
|
||||
@@ -117,7 +122,7 @@ export default class extends FlipperPlugin<State, *, PersistedState> {
|
||||
return previous + (persistedState.responses[key].status >= 400);
|
||||
},
|
||||
0);
|
||||
return Promise.resolve(new Map([['NUMBER_NETWORK_FAILURES', failures]]));
|
||||
return Promise.resolve({NUMBER_NETWORK_FAILURES: failures});
|
||||
};
|
||||
|
||||
static persistedStateReducer = (
|
||||
|
||||
@@ -4,19 +4,19 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
import type {MiddlewareAPI} from '../reducers';
|
||||
import {serialize} from './serialization.js';
|
||||
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 ExportMetricType = Map<string, MetricType>;
|
||||
export type MetricType = {[metricName: string]: number};
|
||||
type MetricPluginType = {[pluginID: string]: MetricType};
|
||||
export type ExportMetricType = {[clientID: string]: MetricPluginType};
|
||||
|
||||
export default async function exportMetrics(
|
||||
store: MiddlewareAPI,
|
||||
): Promise<string> {
|
||||
const state = store.getState();
|
||||
let metrics: ExportMetricType = new Map();
|
||||
const metrics: ExportMetricType = {};
|
||||
for (let key in state.pluginStates) {
|
||||
const pluginStateData = state.pluginStates[key];
|
||||
const arr = key.split('#');
|
||||
@@ -32,20 +32,19 @@ export default async function exportMetrics(
|
||||
state.plugins.devicePlugins.forEach((val, key) => {
|
||||
pluginsMap.set(key, val);
|
||||
});
|
||||
const exportMetrics1: ?(
|
||||
const metricsReducer: ?(
|
||||
persistedState: any,
|
||||
) => Promise<Map<string, string | number>> = pluginsMap.get(pluginName)
|
||||
?.exportMetrics;
|
||||
if (pluginsMap.has(pluginName) && exportMetrics1) {
|
||||
const metricMap = await exportMetrics1(pluginStateData);
|
||||
const pluginMap = new Map([[pluginName, metricMap]]);
|
||||
if (!metrics.get(clientID)) {
|
||||
metrics.set(clientID, pluginMap);
|
||||
) => Promise<MetricType> = pluginsMap.get(pluginName)?.metricsReducer;
|
||||
if (pluginsMap.has(pluginName) && metricsReducer) {
|
||||
const metricsObject = await metricsReducer(pluginStateData);
|
||||
const pluginObject = {};
|
||||
pluginObject[pluginName] = metricsObject;
|
||||
if (!metrics[clientID]) {
|
||||
metrics[clientID] = pluginObject;
|
||||
continue;
|
||||
}
|
||||
const prevMetricMap = metrics.get(clientID);
|
||||
// $FlowFixMe: prevMetricMap cannot be null, because clientID is added only when the pluingMetricMap is available
|
||||
metrics.set(clientID, new Map([...prevMetricMap, ...pluginMap]));
|
||||
const mergedMetrics = {...metrics[clientID], ...pluginObject};
|
||||
metrics[clientID] = mergedMetrics;
|
||||
}
|
||||
}
|
||||
return Promise.resolve(serialize(metrics));
|
||||
|
||||
Reference in New Issue
Block a user