Skip to content

Commit

Permalink
chore: add performance metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovRoman committed Sep 6, 2023
1 parent 854c9f0 commit 060a56e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/constants/performance-marks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
JS_EXEC: 'js exec',
DBS_LOADED: 'dbs loaded',
DBS_MERGED: 'dbs merged',
PLUGINS_LOADED: 'plugins loaded',
DB_EXTRACTED_ROWS: 'db extracted rows',
FULLY_LOADED: 'fully loaded'
} as const;
11 changes: 11 additions & 0 deletions lib/static/modules/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {getHttpErrorMessage} from './utils';
import {fetchDataFromDatabases, mergeDatabases, connectToDatabase, getMainDatabaseUrl, getSuitesTableRows} from '../../db-utils/client';
import {setFilteredBrowsers} from './query-params';
import plugins from './plugins';
import performanceMarks from '../../constants/performance-marks';

export const createNotification = (id, status, message, props = {}) => {
const notificationProps = {
Expand Down Expand Up @@ -58,6 +59,7 @@ export const initGuiReport = () => {

export const initStaticReport = () => {
return async dispatch => {
performance?.mark?.(performanceMarks.JS_EXEC);
const dataFromStaticFile = window.data || {};
let fetchDbDetails = [];
let db = null;
Expand All @@ -66,17 +68,23 @@ export const initStaticReport = () => {
const mainDatabaseUrls = new URL('databaseUrls.json', window.location.href);
const fetchDbResponses = await fetchDataFromDatabases([mainDatabaseUrls.href]);

performance?.mark?.(performanceMarks.DBS_LOADED);

fetchDbDetails = fetchDbResponses.map(({url, status, data}) => ({url, status, success: !!data}));

const dataForDbs = fetchDbResponses.map(({data}) => data).filter(data => data);

db = await mergeDatabases(dataForDbs);

performance?.mark?.(performanceMarks.DBS_MERGED);
} catch (e) {
dispatch(createNotificationError('initStaticReport', e));
}

await plugins.loadAll(dataFromStaticFile.config);

performance?.mark?.(performanceMarks.PLUGINS_LOADED);

if (!db || isEmpty(fetchDbDetails)) {
return dispatch({
type: actionNames.INIT_STATIC_REPORT,
Expand All @@ -86,6 +94,9 @@ export const initStaticReport = () => {

const testsTreeBuilder = StaticTestsTreeBuilder.create();
const suitesRows = getSuitesTableRows(db);

performance?.mark?.(performanceMarks.DB_EXTRACTED_ROWS);

const {tree, stats, skips, browsers} = testsTreeBuilder.build(suitesRows);

dispatch({
Expand Down
37 changes: 35 additions & 2 deletions lib/static/modules/middlewares/metrika.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {get} from 'lodash';
import {get, isEmpty} from 'lodash';
import actionNames from '../action-names';

import {measurePerformance} from '../web-vitals';
import performanceMarks from '../../../constants/performance-marks';

let metrika;
let reportFullyLoaded = false;

export default metrikaClass => store => next => action => {
switch (action.type) {
Expand Down Expand Up @@ -58,6 +60,28 @@ export default metrikaClass => store => next => action => {
return next(action);
}

case actionNames.BROWSERS_SELECTED: {
execOnMetrikaEnabled(() => {
sendCounterId(action.type);
});

const result = next(action);

if (!reportFullyLoaded) {
reportFullyLoaded = true;

performance?.mark?.(performanceMarks.FULLY_LOADED);

const marks = extractPerformanceMarks();

if (metrika && !isEmpty(marks)) {
metrika.sendVisitParams(marks);
}
}

return result;
}

case actionNames.RUN_ALL_TESTS:
case actionNames.RUN_FAILED_TESTS:
case actionNames.RETRY_SUITE:
Expand All @@ -75,7 +99,6 @@ export default metrikaClass => store => next => action => {
case actionNames.VIEW_SWITCH_DIFF:
case actionNames.VIEW_SWIPE_DIFF:
case actionNames.VIEW_ONION_SKIN_DIFF:
case actionNames.BROWSERS_SELECTED:
case actionNames.VIEW_UPDATE_FILTER_BY_NAME:
case actionNames.VIEW_SET_STRICT_MATCH_FILTER:
case actionNames.RUN_CUSTOM_GUI_ACTION:
Expand Down Expand Up @@ -119,3 +142,13 @@ function execOnMetrikaEnabled(cb) {
function sendCounterId(counterId) {
metrika.sendVisitParams({counterId});
}

function extractPerformanceMarks() {
const marks = performance?.getEntriesByType?.('mark') || [];

return marks.reduce((acc, {name, startTime}) => {
acc[name] = Math.round(startTime);

return acc;
}, {});
}

0 comments on commit 060a56e

Please sign in to comment.