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-1036] Add negative loading time internal monitoring #1095

Merged
merged 4 commits into from
Oct 1, 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 @@ -7,10 +7,10 @@ import {
generateUUID,
ClocksState,
clocksNow,
TimeStamp,
Configuration,
ONE_SECOND,
Observable,
addMonitoringMessage,
} from '@datadog/browser-core'
import { ActionType } from '../../../rawRumEvent.types'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'
Expand Down Expand Up @@ -106,7 +106,7 @@ function startActionManagement(lifeCycle: LifeCycle, domMutationObservable: Obse
domMutationObservable,
(params) => {
if (params.hadActivity) {
pendingAutoAction.complete(params.endTime)
pendingAutoAction.complete(params.endClocks)
} else {
pendingAutoAction.discard()
}
Expand Down Expand Up @@ -137,15 +137,28 @@ class PendingAutoAction {
this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { id: this.id, startClocks: this.startClocks })
}

complete(endTime: TimeStamp) {
complete(endClocks: ClocksState) {
const actionDuration = elapsed(this.startClocks.timeStamp, endClocks.timeStamp)
if (actionDuration < 0) {
addMonitoringMessage('auto action with negative loading time', {
debug: {
actionDuration,
type: this.type,
name: this.name,
startClocks: this.startClocks,
endClocks,
},
Comment on lines +144 to +150
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding currentDrift too?
to see if it can be related somehow

})
}

const eventCounts = this.eventCountsSubscription.eventCounts
this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, {
counts: {
errorCount: eventCounts.errorCount,
longTaskCount: eventCounts.longTaskCount,
resourceCount: eventCounts.resourceCount,
},
duration: elapsed(this.startClocks.timeStamp, endTime),
duration: actionDuration,
id: this.id,
name: this.name,
startClocks: this.startClocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function trackActivityLoadingTime(
const startTime = timeStampNow()
const { stop: stopWaitIdlePageActivity } = waitIdlePageActivity(lifeCycle, domMutationObservable, (params) => {
if (params.hadActivity) {
callback(elapsed(startTime, params.endTime))
callback(elapsed(startTime, params.endClocks.timeStamp))
} else {
callback(undefined)
}
Expand Down
38 changes: 27 additions & 11 deletions packages/rum-core/src/domain/trackPageActivities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,18 @@ describe('waitPageActivitiesCompletion', () => {

expect(completionCallbackSpy).toHaveBeenCalledOnceWith({
hadActivity: true,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
endTime: (startTime + BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY) as TimeStamp,
endClocks: {
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
timeStamp: (startTime + BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY) as TimeStamp,
relative: BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY,
},
})
})

describe('extend with activities', () => {
it('is extended while there is page activities', () => {
const activityObservable = new Observable<PageActivityEvent>()
const startTime = timeStampNow()

// Extend the action 10 times
const extendCount = 10

Expand All @@ -199,10 +201,14 @@ describe('waitPageActivitiesCompletion', () => {

clock.tick(EXPIRE_DELAY)

const relative = extendCount * BEFORE_PAGE_ACTIVITY_END_DELAY
expect(completionCallbackSpy).toHaveBeenCalledOnceWith({
hadActivity: true,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
endTime: (startTime + extendCount * BEFORE_PAGE_ACTIVITY_END_DELAY) as TimeStamp,
endClocks: {
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
timeStamp: (startTime + relative) as TimeStamp,
relative,
},
})
})

Expand All @@ -228,8 +234,11 @@ describe('waitPageActivitiesCompletion', () => {

expect(completionCallbackSpy).toHaveBeenCalledOnceWith({
hadActivity: true,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
endTime: (startTime + MAX_DURATION) as TimeStamp,
endClocks: {
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
timeStamp: (startTime + MAX_DURATION) as TimeStamp,
relative: MAX_DURATION,
},
})
})
})
Expand All @@ -248,10 +257,14 @@ describe('waitPageActivitiesCompletion', () => {

clock.tick(EXPIRE_DELAY)

const relative = BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY + PAGE_ACTIVITY_END_DELAY * 2
expect(completionCallbackSpy).toHaveBeenCalledOnceWith({
hadActivity: true,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
endTime: (startTime + BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY + PAGE_ACTIVITY_END_DELAY * 2) as TimeStamp,
endClocks: {
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
timeStamp: (startTime + relative) as TimeStamp,
relative,
},
})
})

Expand All @@ -267,8 +280,11 @@ describe('waitPageActivitiesCompletion', () => {

expect(completionCallbackSpy).toHaveBeenCalledOnceWith({
hadActivity: true,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
endTime: (startTime + MAX_DURATION) as TimeStamp,
endClocks: {
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
timeStamp: (startTime + MAX_DURATION) as TimeStamp,
relative: MAX_DURATION,
},
})
})
})
Expand Down
10 changes: 5 additions & 5 deletions packages/rum-core/src/domain/trackPageActivities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { monitor, Observable, Subscription, TimeStamp, timeStampNow } from '@datadog/browser-core'
import { clocksNow, ClocksState, monitor, Observable, Subscription } from '@datadog/browser-core'
import { LifeCycle, LifeCycleEventType } from './lifeCycle'

// Delay to wait for a page activity to validate the tracking process
Expand All @@ -10,7 +10,7 @@ export interface PageActivityEvent {
isBusy: boolean
}

export type CompletionCallbackParameters = { hadActivity: true; endTime: TimeStamp } | { hadActivity: false }
export type CompletionCallbackParameters = { hadActivity: true; endClocks: ClocksState } | { hadActivity: false }

export function waitIdlePageActivity(
lifeCycle: LifeCycle,
Expand Down Expand Up @@ -133,17 +133,17 @@ export function waitPageActivitiesCompletion(
const maxDurationTimeoutId =
maxDuration &&
setTimeout(
monitor(() => complete({ hadActivity: true, endTime: timeStampNow() })),
monitor(() => complete({ hadActivity: true, endClocks: clocksNow() })),
maxDuration
)

pageActivitiesObservable.subscribe(({ isBusy }) => {
clearTimeout(validationTimeoutId)
clearTimeout(idleTimeoutId)
const lastChangeTime = timeStampNow()
const lastChangeTime = clocksNow()
if (!isBusy) {
idleTimeoutId = setTimeout(
monitor(() => complete({ hadActivity: true, endTime: lastChangeTime })),
monitor(() => complete({ hadActivity: true, endClocks: lastChangeTime })),
PAGE_ACTIVITY_END_DELAY
)
}
Expand Down