-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add performance metrics #495
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = { | ||
|
@@ -31,14 +32,19 @@ export const dismissNotification = dismissNotify; | |
|
||
export const initGuiReport = () => { | ||
return async (dispatch) => { | ||
performance?.mark?.(performanceMarks.JS_EXEC); | ||
try { | ||
const appState = await axios.get('/init'); | ||
|
||
const mainDatabaseUrl = getMainDatabaseUrl(); | ||
const db = await connectToDatabase(mainDatabaseUrl.href); | ||
|
||
performance?.mark?.(performanceMarks.DBS_LOADED); | ||
|
||
await plugins.loadAll(appState.data.config); | ||
|
||
performance?.mark?.(performanceMarks.PLUGINS_LOADED); | ||
|
||
dispatch({ | ||
type: actionNames.INIT_GUI_REPORT, | ||
payload: {...appState.data, db} | ||
|
@@ -58,6 +64,7 @@ export const initGuiReport = () => { | |
|
||
export const initStaticReport = () => { | ||
KuznetsovRoman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return async dispatch => { | ||
performance?.mark?.(performanceMarks.JS_EXEC); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь и далее использую Использую именно |
||
const dataFromStaticFile = window.data || {}; | ||
let fetchDbDetails = []; | ||
let db = null; | ||
|
@@ -66,17 +73,23 @@ export const initStaticReport = () => { | |
const mainDatabaseUrls = new URL('databaseUrls.json', window.location.href); | ||
const fetchDbResponses = await fetchDataFromDatabases([mainDatabaseUrls.href]); | ||
|
||
performance?.mark?.(performanceMarks.DBS_LOADED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Кмк в таких метриках не хватает инфы сколько мы в итоге базок загружали, сколько мерджили, сколько строк из базок выгружали и т.д. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Есть |
||
|
||
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, | ||
|
@@ -86,6 +99,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({ | ||
|
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) { | ||
|
@@ -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(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А почему эту логики выполняешь на There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Потому что пока первый |
||
if (metrika && !isEmpty(marks)) { | ||
metrika.sendVisitParams(marks); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
Comment on lines
+63
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. После There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UPD: добавил проверку, чтоб собирать данные только при There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А тесты не хочешь на этот код набросать? У нас модуль метрики покрыт тестами. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут В общем, код тестов получится намного более сложным этого кода |
||
case actionNames.RUN_ALL_TESTS: | ||
case actionNames.RUN_FAILED_TESTS: | ||
case actionNames.RETRY_SUITE: | ||
|
@@ -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: | ||
|
@@ -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; | ||
}, {}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ import {StaticTestsTreeBuilder} from 'lib/tests-tree-builder/static'; | |
import {LOCAL_DATABASE_NAME} from 'lib/constants/database'; | ||
import {DiffModes} from 'lib/constants/diff-modes'; | ||
|
||
// eslint-disable-next-line | ||
globalThis.performance = globalThis.performance; // node v14 stub | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. node v14 не умеет в |
||
|
||
describe('lib/static/modules/actions', () => { | ||
const sandbox = sinon.sandbox.create(); | ||
let dispatch, actions, notify, getSuitesTableRows, getMainDatabaseUrl, connectToDatabaseStub, pluginsStub; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужны вот эти метки, потому что они лучше отражают, на что тратится время