Skip to content
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

✨ [RUMF-1029] remove the limit on view.loading_time #1054

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { RumEvent } from '../../../../../rum/src'
import { setup, TestSetupBuilder } from '../../../../test/specHelper'
import { RumEventType, ActionType } from '../../../rawRumEvent.types'
import { LifeCycleEventType } from '../../lifeCycle'
import { PAGE_ACTIVITY_MAX_DURATION, PAGE_ACTIVITY_VALIDATION_DELAY } from '../../trackPageActivities'
import { AutoAction, trackActions } from './trackActions'
import { PAGE_ACTIVITY_VALIDATION_DELAY } from '../../trackPageActivities'
import { AutoAction, AUTO_ACTION_MAX_DURATION, trackActions } from './trackActions'

// Used to wait some time after the creation of a action
const BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY = PAGE_ACTIVITY_VALIDATION_DELAY * 0.8
// Used to wait some time but it doesn't matter how much.
const SOME_ARBITRARY_DELAY = 50
// A long delay used to wait after any action is finished.
const EXPIRE_DELAY = PAGE_ACTIVITY_MAX_DURATION * 10
const EXPIRE_DELAY = AUTO_ACTION_MAX_DURATION * 10

function eventsCollector<T>() {
const events: T[] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
clocksNow,
TimeStamp,
Configuration,
ONE_SECOND,
} from '@datadog/browser-core'
import { ActionType } from '../../../rawRumEvent.types'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'
Expand Down Expand Up @@ -47,12 +48,15 @@ export interface AutoActionCreatedEvent {
startClocks: ClocksState
}

// Maximum duration for automatic actions
export const AUTO_ACTION_MAX_DURATION = 10 * ONE_SECOND

export function trackActions(
lifeCycle: LifeCycle,
domMutationObservable: DOMMutationObservable,
configuration: Configuration
{ actionNameAttribute }: Configuration
) {
const action = startActionManagement(lifeCycle, domMutationObservable, configuration)
const action = startActionManagement(lifeCycle, domMutationObservable)

// New views trigger the discard of the current pending Action
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, () => {
Expand All @@ -66,7 +70,7 @@ export function trackActions(
if (!(event.target instanceof Element)) {
return
}
const name = getActionNameFromElement(event.target, configuration.actionNameAttribute)
const name = getActionNameFromElement(event.target, actionNameAttribute)
if (!name) {
return
}
Expand All @@ -84,11 +88,7 @@ export function trackActions(
}
}

function startActionManagement(
lifeCycle: LifeCycle,
domMutationObservable: DOMMutationObservable,
configuration: Configuration
) {
function startActionManagement(lifeCycle: LifeCycle, domMutationObservable: DOMMutationObservable) {
let currentAction: PendingAutoAction | undefined
let currentIdlePageActivitySubscription: { stop: () => void }

Expand All @@ -104,15 +104,15 @@ function startActionManagement(
currentIdlePageActivitySubscription = waitIdlePageActivity(
lifeCycle,
domMutationObservable,
configuration,
(params) => {
if (params.hadActivity) {
pendingAutoAction.complete(params.endTime)
} else {
pendingAutoAction.discard()
}
currentAction = undefined
}
},
AUTO_ACTION_MAX_DURATION
)
},
discardCurrent: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@ import { TestSetupBuilder, setup, setupViewTest, ViewTest } from '../../../../te
import { RumPerformanceNavigationTiming } from '../../../browser/performanceCollection'
import { RumEventType } from '../../../rawRumEvent.types'
import { LifeCycle } from '../../lifeCycle'
import {
PAGE_ACTIVITY_END_DELAY,
PAGE_ACTIVITY_MAX_DURATION,
PAGE_ACTIVITY_VALIDATION_DELAY,
} from '../../trackPageActivities'
import { PAGE_ACTIVITY_END_DELAY, PAGE_ACTIVITY_VALIDATION_DELAY } from '../../trackPageActivities'
import { THROTTLE_VIEW_UPDATE_PERIOD } from './trackViews'

const BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY = (PAGE_ACTIVITY_VALIDATION_DELAY * 0.8) as Duration

const AFTER_PAGE_ACTIVITY_MAX_DURATION = PAGE_ACTIVITY_MAX_DURATION * 1.1

const AFTER_PAGE_ACTIVITY_END_DELAY = PAGE_ACTIVITY_END_DELAY * 1.1

const FAKE_NAVIGATION_ENTRY: RumPerformanceNavigationTiming = {
Expand Down Expand Up @@ -68,7 +62,6 @@ describe('rum track view metrics', () => {
const { getViewUpdate, getViewUpdateCount, startView } = viewTest

startView()
clock.tick(AFTER_PAGE_ACTIVITY_MAX_DURATION)
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD)

expect(getViewUpdateCount()).toEqual(3)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
Duration,
noop,
elapsed,
round,
timeStampNow,
Configuration,
RelativeTime,
ONE_SECOND,
} from '@datadog/browser-core'
import { Duration, noop, elapsed, round, timeStampNow, RelativeTime, ONE_SECOND } from '@datadog/browser-core'
import { RumLayoutShiftTiming, supportPerformanceTimingEvent } from '../../../browser/performanceCollection'
import { ViewLoadingType } from '../../../rawRumEvent.types'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'
Expand All @@ -25,8 +16,7 @@ export function trackViewMetrics(
lifeCycle: LifeCycle,
domMutationObservable: DOMMutationObservable,
scheduleViewUpdate: () => void,
loadingType: ViewLoadingType,
configuration: Configuration
loadingType: ViewLoadingType
) {
const viewMetrics: ViewMetrics = {
eventCounts: {
Expand All @@ -49,7 +39,6 @@ export function trackViewMetrics(
const { stop: stopActivityLoadingTimeTracking } = trackActivityLoadingTime(
lifeCycle,
domMutationObservable,
configuration,
setActivityLoadingTime
)

Expand Down Expand Up @@ -108,22 +97,16 @@ function trackLoadingTime(loadType: ViewLoadingType, callback: (loadingTime: Dur
function trackActivityLoadingTime(
lifeCycle: LifeCycle,
domMutationObservable: DOMMutationObservable,
configuration: Configuration,
callback: (loadingTimeValue: Duration | undefined) => void
) {
const startTime = timeStampNow()
const { stop: stopWaitIdlePageActivity } = waitIdlePageActivity(
lifeCycle,
domMutationObservable,
configuration,
(params) => {
if (params.hadActivity) {
callback(elapsed(startTime, params.endTime))
} else {
callback(undefined)
}
const { stop: stopWaitIdlePageActivity } = waitIdlePageActivity(lifeCycle, domMutationObservable, (params) => {
if (params.hadActivity) {
callback(elapsed(startTime, params.endTime))
} else {
callback(undefined)
}
)
})

return { stop: stopWaitIdlePageActivity }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
timeStampNow,
TimeStamp,
display,
Configuration,
} from '@datadog/browser-core'
import { DOMMutationObservable } from '../../../browser/domMutationObservable'
import { ViewLoadingType, ViewCustomTimings } from '../../../rawRumEvent.types'
Expand Down Expand Up @@ -59,7 +58,6 @@ export function trackViews(
lifeCycle: LifeCycle,
domMutationObservable: DOMMutationObservable,
areViewsTrackedAutomatically: boolean,
configuration: Configuration,
initialViewName?: string
) {
const { stop: stopInitialViewTracking, initialView } = trackInitialView(initialViewName)
Expand All @@ -77,7 +75,6 @@ export function trackViews(
location,
ViewLoadingType.INITIAL_LOAD,
document.referrer,
configuration,
clocksOrigin(),
name
)
Expand All @@ -95,7 +92,6 @@ export function trackViews(
location,
ViewLoadingType.ROUTE_CHANGE,
currentView.url,
configuration,
startClocks,
name
)
Expand Down Expand Up @@ -176,7 +172,6 @@ function newView(
initialLocation: Location,
loadingType: ViewLoadingType,
referrer: string,
configuration: Configuration,
startClocks: ClocksState = clocksNow(),
name?: string
) {
Expand All @@ -203,8 +198,7 @@ function newView(
lifeCycle,
domMutationObservable,
scheduleViewUpdate,
loadingType,
configuration
loadingType
)

// Initial view update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ export function startViewCollection(
)
)

return trackViews(
location,
lifeCycle,
domMutationObservable,
!configuration.trackViewsManually,
configuration,
initialViewName
)
return trackViews(location, lifeCycle, domMutationObservable, !configuration.trackViewsManually, initialViewName)
}

function processViewUpdate(
Expand Down
Loading