Skip to content

Commit

Permalink
✨ [RUMF-1425] enable request retry/throttle for replay intake
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer committed Nov 14, 2022
1 parent 1e1ad08 commit d2db408
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HttpRequest, TimeStamp } from '@datadog/browser-core'
import { PageExitReason, updateExperimentalFeatures, resetExperimentalFeatures, isIE } from '@datadog/browser-core'
import { PageExitReason, isIE } from '@datadog/browser-core'
import type { ViewContexts, ViewContext } from '@datadog/browser-rum-core'
import { LifeCycle, LifeCycleEventType } from '@datadog/browser-rum-core'
import type { Clock } from '@datadog/browser-core/test/specHelper'
Expand Down Expand Up @@ -83,7 +83,6 @@ describe('startSegmentCollection', () => {
afterEach(() => {
clock?.cleanup()
stopSegmentCollection()
resetExperimentalFeatures()
})

describe('initial segment', () => {
Expand Down Expand Up @@ -135,17 +134,6 @@ describe('startSegmentCollection', () => {
expect(httpRequestSpy.sendOnExit).toHaveBeenCalled()
})

describe('with the retry_replay experimental flag', () => {
beforeEach(() => {
updateExperimentalFeatures(['retry_replay'])
})

it('uses `httpRequest.sendOnExit` when sending the segment', () => {
addRecordAndFlushSegment(emulatePageUnload)
expect(httpRequestSpy.sendOnExit).toHaveBeenCalled()
})
})

it('next segment is created because of beforeunload event', () => {
addRecordAndFlushSegment(emulatePageUnload)
addRecordAndFlushSegment()
Expand All @@ -163,17 +151,6 @@ describe('startSegmentCollection', () => {
expect(httpRequestSpy.sendOnExit).toHaveBeenCalled()
})

describe('with the retry_replay experimental flag', () => {
beforeEach(() => {
updateExperimentalFeatures(['retry_replay'])
})

it('uses `httpRequest.sendOnExit` when sending the segment', () => {
addRecordAndFlushSegment(emulatePageHidden)
expect(httpRequestSpy.sendOnExit).toHaveBeenCalled()
})
})

it('next segment is created because of visibility hidden event', () => {
addRecordAndFlushSegment(emulatePageHidden)
addRecordAndFlushSegment()
Expand All @@ -186,20 +163,9 @@ describe('startSegmentCollection', () => {
lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, {} as any)
}

it('uses `httpRequest.sendOnExit` when sending the segment', () => {
it('uses `httpRequest.send` when sending the segment', () => {
addRecordAndFlushSegment(emulateViewChange)
expect(httpRequestSpy.sendOnExit).toHaveBeenCalled()
})

describe('with the retry_replay experimental flag', () => {
beforeEach(() => {
updateExperimentalFeatures(['retry_replay'])
})

it('uses `httpRequest.send` when sending the segment', () => {
addRecordAndFlushSegment(emulateViewChange)
expect(httpRequestSpy.send).toHaveBeenCalled()
})
expect(httpRequestSpy.send).toHaveBeenCalled()
})

it('next segment is created because of view change', () => {
Expand All @@ -210,24 +176,11 @@ describe('startSegmentCollection', () => {
})

describe('flush when reaching a bytes limit', () => {
it('uses `httpRequest.sendOnExit` when sending the segment', () => {
it('uses `httpRequest.send` when sending the segment', () => {
addRecordAndFlushSegment(() => {
addRecord(VERY_BIG_RECORD)
})
expect(httpRequestSpy.sendOnExit).toHaveBeenCalled()
})

describe('with the retry_replay experimental flag', () => {
beforeEach(() => {
updateExperimentalFeatures(['retry_replay'])
})

it('uses `httpRequest.send` when sending the segment', () => {
addRecordAndFlushSegment(() => {
addRecord(VERY_BIG_RECORD)
})
expect(httpRequestSpy.send).toHaveBeenCalled()
})
expect(httpRequestSpy.send).toHaveBeenCalled()
})

it('next segment is created because the bytes limit has been reached', () => {
Expand Down Expand Up @@ -270,26 +223,12 @@ describe('startSegmentCollection', () => {
})

describe('flush when a duration has been reached', () => {
it('uses `httpRequest.sendOnExit` when sending the segment', () => {
it('uses `httpRequest.send` when sending the segment', () => {
clock = mockClock()
addRecordAndFlushSegment(() => {
clock!.tick(SEGMENT_DURATION_LIMIT)
})
expect(httpRequestSpy.sendOnExit).toHaveBeenCalled()
})

describe('with the retry_replay experimental flag', () => {
beforeEach(() => {
updateExperimentalFeatures(['retry_replay'])
})

it('uses `httpRequest.send` when sending the segment', () => {
clock = mockClock()
addRecordAndFlushSegment(() => {
clock!.tick(SEGMENT_DURATION_LIMIT)
})
expect(httpRequestSpy.send).toHaveBeenCalled()
})
expect(httpRequestSpy.send).toHaveBeenCalled()
})

it('next segment is created because of the segment duration limit has been reached', () => {
Expand Down Expand Up @@ -317,20 +256,9 @@ describe('startSegmentCollection', () => {
})

describe('flush when stopping segment collection', () => {
it('uses `httpRequest.sendOnExit` when sending the segment', () => {
it('uses `httpRequest.send` when sending the segment', () => {
addRecordAndFlushSegment(stopSegmentCollection)
expect(httpRequestSpy.sendOnExit).toHaveBeenCalled()
})

describe('with the retry_replay experimental flag', () => {
beforeEach(() => {
updateExperimentalFeatures(['retry_replay'])
})

it('uses `httpRequest.send` when sending the segment', () => {
addRecordAndFlushSegment(stopSegmentCollection)
expect(httpRequestSpy.send).toHaveBeenCalled()
})
expect(httpRequestSpy.send).toHaveBeenCalled()
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ export function doStartSegmentCollection(
},
(data, rawSegmentBytesCount) => {
const payload = buildReplayPayload(data, segment.metadata, rawSegmentBytesCount)
if (
!isExperimentalFeatureEnabled('retry_replay') ||
segment.flushReason === 'visibility_hidden' ||
segment.flushReason === 'before_unload'
) {
if (segment.flushReason === 'visibility_hidden' || segment.flushReason === 'before_unload') {
httpRequest.sendOnExit(payload)
} else {
httpRequest.send(payload)
Expand Down

0 comments on commit d2db408

Please sign in to comment.