Skip to content

Commit

Permalink
fix: artificial lag (#22353)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored May 19, 2024
1 parent b951858 commit 946a7e3
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { actionToUrl, router, urlToAction } from 'kea-router'
import { subscriptions } from 'kea-subscriptions'
import api from 'lib/api'
import { FEATURE_FLAGS } from 'lib/constants'
import { now } from 'lib/dayjs'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { objectClean, objectsEqual } from 'lib/utils'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
Expand Down Expand Up @@ -220,7 +221,11 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic
}

if (values.artificialLag) {
params['date_to'] = values.artificialLag
// values.artificalLag is a number of seconds to delay the recordings by
// convert it to an absolute UTC timestamp as the relative date parsing in the backend
// can't cope with seconds as a relative date
const absoluteLag = now().subtract(values.artificialLag, 'second')
params['date_to'] = absoluteLag.toISOString()
}

if (values.orderBy === 'start_time') {
Expand Down Expand Up @@ -493,10 +498,12 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic
selectors({
artificialLag: [
(s) => [s.featureFlags],
(featureFlags): string | null => {
(featureFlags) => {
const lag = featureFlags[FEATURE_FLAGS.SESSION_REPLAY_ARTIFICIAL_LAG]
// you can't edit variants right now, and I didn't put minus on the variant name 🤷
return lag === undefined || lag === 'control' ? null : '-' + lag
// lag needs to match `\d+` when present it is a number of seconds delay
// relative_date parsing in the backend can't cope with seconds
// so it will be converted to an absolute date when added to API call
return typeof lag === 'string' && /^\d+$/.test(lag) ? Number.parseInt(lag) : null
},
],
useHogQLFiltering: [
Expand Down

0 comments on commit 946a7e3

Please sign in to comment.