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: instrument time insights are marked as loading #11222
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ca04f42
chore: instrument time insights are marked as loading
pauldambra 6440a13
instrument manual dashboard card refresh
pauldambra 5995883
report on dashboard loading time
pauldambra 0c03b3e
just dashboards
pauldambra 1aa0f11
just dashboards
pauldambra ebf2bc8
pass args down to satisfy kea signature
pauldambra 71a7cc6
use date not dayjs
pauldambra f195fd3
fix test
pauldambra File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,7 @@ import { isBreakpoint, kea } from 'kea' | |||||||||||
import api from 'lib/api' | ||||||||||||
import { dashboardsModel } from '~/models/dashboardsModel' | ||||||||||||
import { router } from 'kea-router' | ||||||||||||
import { dayjs, now } from 'lib/dayjs' | ||||||||||||
import { Dayjs, dayjs, now } from 'lib/dayjs' | ||||||||||||
import { clearDOMTextSelection, isUserLoggedIn, toParams } from 'lib/utils' | ||||||||||||
import { insightsModel } from '~/models/insightsModel' | ||||||||||||
import { DashboardPrivilegeLevel, OrganizationMembershipLevel } from 'lib/constants' | ||||||||||||
|
@@ -44,6 +44,13 @@ export interface DashboardLogicProps { | |||||||||||
placement?: DashboardPlacement | ||||||||||||
} | ||||||||||||
|
||||||||||||
export interface RefreshStatus { | ||||||||||||
loading?: boolean | ||||||||||||
refreshed?: boolean | ||||||||||||
error?: boolean | ||||||||||||
timer?: Dayjs | null | ||||||||||||
} | ||||||||||||
|
||||||||||||
export const AUTO_REFRESH_INITIAL_INTERVAL_SECONDS = 300 | ||||||||||||
|
||||||||||||
export const dashboardLogic = kea<dashboardLogicType>({ | ||||||||||||
|
@@ -252,34 +259,28 @@ export const dashboardLogic = kea<dashboardLogicType>({ | |||||||||||
}, | ||||||||||||
}, | ||||||||||||
], | ||||||||||||
loadTimer: [null as Dayjs | null, { loadDashboardItems: () => now() }], | ||||||||||||
refreshStatus: [ | ||||||||||||
{} as Record< | ||||||||||||
string, | ||||||||||||
{ | ||||||||||||
loading?: boolean | ||||||||||||
refreshed?: boolean | ||||||||||||
error?: boolean | ||||||||||||
} | ||||||||||||
>, | ||||||||||||
{} as Record<string, RefreshStatus>, | ||||||||||||
{ | ||||||||||||
setRefreshStatus: (state, { shortId, loading }) => ({ | ||||||||||||
...state, | ||||||||||||
[shortId]: loading ? { loading: true } : { refreshed: true }, | ||||||||||||
[shortId]: loading | ||||||||||||
? { loading: true, timer: now() } | ||||||||||||
: { refreshed: true, timer: state[shortId]?.timer || null }, | ||||||||||||
}), | ||||||||||||
setRefreshStatuses: (_, { shortIds, loading }) => | ||||||||||||
setRefreshStatuses: (state, { shortIds, loading }) => | ||||||||||||
Object.fromEntries( | ||||||||||||
shortIds.map((shortId) => [shortId, loading ? { loading: true } : { refreshed: true }]) | ||||||||||||
) as Record< | ||||||||||||
string, | ||||||||||||
{ | ||||||||||||
loading?: boolean | ||||||||||||
refreshed?: boolean | ||||||||||||
error?: boolean | ||||||||||||
} | ||||||||||||
>, | ||||||||||||
shortIds.map((shortId) => [ | ||||||||||||
shortId, | ||||||||||||
loading | ||||||||||||
? { loading: true, timer: now() } | ||||||||||||
: { refreshed: true, timer: state[shortId]?.timer || null }, | ||||||||||||
]) | ||||||||||||
) as Record<string, RefreshStatus>, | ||||||||||||
setRefreshError: (state, { shortId }) => ({ | ||||||||||||
...state, | ||||||||||||
[shortId]: { error: true }, | ||||||||||||
[shortId]: { error: true, timer: state[shortId]?.timer || null }, | ||||||||||||
}), | ||||||||||||
refreshAllDashboardItems: () => ({}), | ||||||||||||
}, | ||||||||||||
|
@@ -562,7 +563,29 @@ export const dashboardLogic = kea<dashboardLogicType>({ | |||||||||||
} | ||||||||||||
}, | ||||||||||||
}), | ||||||||||||
listeners: ({ actions, values, cache, props }) => ({ | ||||||||||||
sharedListeners: ({ values, props }) => ({ | ||||||||||||
reportRefreshTiming: ({ shortId }) => { | ||||||||||||
const refreshStatus = values.refreshStatus[shortId] | ||||||||||||
|
||||||||||||
if (refreshStatus?.timer) { | ||||||||||||
const loadingMilliseconds = now().diff(refreshStatus.timer) | ||||||||||||
eventUsageLogic.actions.reportInsightRefreshTime(loadingMilliseconds, shortId) | ||||||||||||
} | ||||||||||||
}, | ||||||||||||
reportLoadTiming: () => { | ||||||||||||
if (!props.id) { | ||||||||||||
// what even is loading?! | ||||||||||||
return | ||||||||||||
} | ||||||||||||
const loadingMilliseconds = now().diff(values.loadTimer) | ||||||||||||
eventUsageLogic.actions.reportDashboardLoadingTime(loadingMilliseconds, props.id) | ||||||||||||
}, | ||||||||||||
}), | ||||||||||||
listeners: ({ actions, values, cache, props, sharedListeners }) => ({ | ||||||||||||
setRefreshError: sharedListeners.reportRefreshTiming, | ||||||||||||
setRefreshStatuses: sharedListeners.reportRefreshTiming, | ||||||||||||
setRefreshStatus: sharedListeners.reportRefreshTiming, | ||||||||||||
loadDashboardItemsFailure: sharedListeners.reportLoadTiming, | ||||||||||||
triggerDashboardUpdate: ({ payload }) => { | ||||||||||||
if (values.dashboard) { | ||||||||||||
dashboardsModel.actions.updateDashboard({ id: values.dashboard.id, ...payload }) | ||||||||||||
|
@@ -730,6 +753,9 @@ export const dashboardLogic = kea<dashboardLogicType>({ | |||||||||||
} | ||||||||||||
}, | ||||||||||||
loadDashboardItemsSuccess: () => { | ||||||||||||
// I didn't want any parameters but kea does :) | ||||||||||||
sharedListeners.reportLoadTiming(null, async () => {}, {} as { type: string; payload: any }, null) | ||||||||||||
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. I think you can do something like this instead:
Suggested change
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. Ah, cool 🙌 |
||||||||||||
|
||||||||||||
// Initial load of actual data for dashboard items after general dashboard is fetched | ||||||||||||
if (values.lastRefreshed && values.lastRefreshed.isBefore(now().subtract(3, 'hours'))) { | ||||||||||||
actions.refreshAllDashboardItems() | ||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
kea-typegen
gets confused because ofDayjs
being imported for some reason… But also Day.js seems overkill for this, Date should be able to do the job too