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

🐛 [RUM-2782] remove buggy redirect timing estimation based on fetchStart #2683

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 1 addition & 19 deletions packages/rum-core/src/domain/resource/resourceUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe('computePerformanceResourceDetails', () => {
},
{
reason: 'redirectStart > redirectEnd',
redirectEnd: 10 as RelativeTime,
redirectEnd: 15 as RelativeTime,
redirectStart: 20 as RelativeTime,
},
{
Expand Down Expand Up @@ -259,24 +259,6 @@ describe('computePerformanceResourceDetails', () => {
first_byte: { start: 0 as ServerDuration, duration: 30e6 as ServerDuration },
})
})

it('should use startTime and fetchStart as fallback for redirectStart and redirectEnd', () => {
expect(
computePerformanceResourceDetails(
generateResourceWith({
redirectEnd: 0 as RelativeTime,
redirectStart: 0 as RelativeTime,
})
)
).toEqual({
connect: { start: 5e6 as ServerDuration, duration: 2e6 as ServerDuration },
dns: { start: 3e6 as ServerDuration, duration: 1e6 as ServerDuration },
download: { start: 40e6 as ServerDuration, duration: 10e6 as ServerDuration },
first_byte: { start: 10e6 as ServerDuration, duration: 30e6 as ServerDuration },
redirect: { start: 0 as ServerDuration, duration: 2e6 as ServerDuration },
ssl: { start: 6e6 as ServerDuration, duration: 1e6 as ServerDuration },
})
})
})

describe('computePerformanceResourceDuration', () => {
Expand Down
57 changes: 17 additions & 40 deletions packages/rum-core/src/domain/resource/resourceUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { RelativeTime, ServerDuration } from '@datadog/browser-core'
import {
assign,
addTelemetryDebug,
elapsed,
getPathName,
Expand Down Expand Up @@ -140,50 +139,28 @@ export function toValidEntry(entry: RumPerformanceResourceTiming) {
// RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be
// collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing
// it.
if (
!areInOrder(
entry.startTime,
entry.fetchStart,
entry.domainLookupStart,
entry.domainLookupEnd,
entry.connectStart,
entry.connectEnd,
entry.requestStart,
entry.responseStart,
entry.responseEnd
)
) {
return undefined
}

if (!hasRedirection(entry)) {
const areCommonTimingsInOrder = areInOrder(
entry.startTime,
entry.fetchStart,
entry.domainLookupStart,
entry.domainLookupEnd,
entry.connectStart,
entry.connectEnd,
entry.requestStart,
entry.responseStart,
entry.responseEnd
)

const areRedirectionTimingsInOrder =
!hasRedirection(entry) || areInOrder(entry.startTime, entry.redirectStart, entry.redirectEnd, entry.fetchStart)
Copy link
Collaborator

Choose a reason for hiding this comment

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

🥜 nitpick: ‏ I think it would be easier to read as:

Suggested change
const areRedirectionTimingsInOrder =
!hasRedirection(entry) || areInOrder(entry.startTime, entry.redirectStart, entry.redirectEnd, entry.fetchStart)
const areRedirectionTimingsInOrder = hasRedirection(entry)
? areInOrder(entry.startTime, entry.redirectStart, entry.redirectEnd, entry.fetchStart)
: true


if (areCommonTimingsInOrder && areRedirectionTimingsInOrder) {
return entry
}

let { redirectStart, redirectEnd } = entry
// Firefox doesn't provide redirect timings on cross origin requests.
// Provide a default for those.
if (redirectStart < entry.startTime) {
redirectStart = entry.startTime
}
if (redirectEnd < entry.startTime) {
redirectEnd = entry.fetchStart
}

// Make sure redirect timings are in order
if (!areInOrder(entry.startTime, redirectStart, redirectEnd, entry.fetchStart)) {
return undefined
}

return assign({}, entry, {
redirectEnd,
redirectStart,
})
}

function hasRedirection(entry: RumPerformanceResourceTiming) {
// The only time fetchStart is different than startTime is if a redirection occurred.
return entry.fetchStart !== entry.startTime
return entry.redirectEnd > entry.startTime
}

function formatTiming(origin: RelativeTime, start: RelativeTime, end: RelativeTime) {
Expand Down