Skip to content

Commit

Permalink
Merge branch 'main' into najib.boutaib/sr-898-add-frustration-records
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Boutaib committed Jul 20, 2022
2 parents 911d63b + fba5527 commit 0ee3479
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 231 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
day: monday
time: '09:00'
commit-message:
prefix: '👷'

- package-ecosystem: npm
directory: /
schedule:
Expand Down
24 changes: 1 addition & 23 deletions packages/core/src/domain/configuration/configuration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import type { RumEvent } from '../../../../rum-core/src'
import { display } from '../../tools/display'
import { ONE_KILO_BYTE } from '../../tools/utils'
import type { InitConfiguration } from './configuration'
import { validateAndBuildConfiguration } from './configuration'
import {
isExperimentalFeatureEnabled,
resetExperimentalFeatures,
updateExperimentalFeatures,
} from './experimentalFeatures'
import { isExperimentalFeatureEnabled, updateExperimentalFeatures } from './experimentalFeatures'

describe('validateAndBuildConfiguration', () => {
const clientToken = 'some_client_token'
Expand Down Expand Up @@ -128,21 +123,4 @@ describe('validateAndBuildConfiguration', () => {
expect(displaySpy).toHaveBeenCalledWith('beforeSend threw an error:', myError)
})
})

describe('batchBytesLimit ', () => {
afterEach(() => {
resetExperimentalFeatures()
})

it('should be set to 10KB when lower-batch-size is enabled', () => {
updateExperimentalFeatures(['lower-batch-size'])
const configuration = validateAndBuildConfiguration({ clientToken })!
expect(configuration.batchBytesLimit).toEqual(10 * ONE_KILO_BYTE)
})

it('should be set to 16KB when lower-batch-size is disabled', () => {
const configuration = validateAndBuildConfiguration({ clientToken })!
expect(configuration.batchBytesLimit).toEqual(16 * ONE_KILO_BYTE)
})
})
})
4 changes: 2 additions & 2 deletions packages/core/src/domain/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getCurrentSite } from '../../browser/cookie'
import { catchUserErrors } from '../../tools/catchUserErrors'
import { display } from '../../tools/display'
import { assign, isPercentage, ONE_KILO_BYTE, ONE_SECOND } from '../../tools/utils'
import { isExperimentalFeatureEnabled, updateExperimentalFeatures } from './experimentalFeatures'
import { updateExperimentalFeatures } from './experimentalFeatures'
import type { TransportConfiguration } from './transportConfiguration'
import { computeTransportConfiguration } from './transportConfiguration'

Expand Down Expand Up @@ -104,7 +104,7 @@ export function validateAndBuildConfiguration(initConfiguration: InitConfigurati
* beacon payload max queue size implementation is 64kb
* ensure that we leave room for logs, rum and potential other users
*/
batchBytesLimit: isExperimentalFeatureEnabled('lower-batch-size') ? 10 * ONE_KILO_BYTE : 16 * ONE_KILO_BYTE,
batchBytesLimit: 16 * ONE_KILO_BYTE,

eventRateLimiterThreshold: 3000,
maxTelemetryEventsPerPage: 15,
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,7 @@ export {
export {
SESSION_TIME_OUT_DELAY, // Exposed for tests
} from './domain/session/sessionConstants'
export {
HttpRequest,
Batch,
canUseEventBridge,
getEventBridge,
startBatchWithReplica,
startFlushFailedSendBeacons,
} from './transport'
export { HttpRequest, Batch, canUseEventBridge, getEventBridge, startBatchWithReplica } from './transport'
export * from './tools/display'
export * from './tools/urlPolyfill'
export * from './tools/timeUtils'
Expand Down
33 changes: 9 additions & 24 deletions packages/core/src/transport/batch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('batch', () => {

batch.flush()

expect(transport.send).toHaveBeenCalledWith('{"message":"hello"}', jasmine.any(Number), undefined)
expect(transport.send).toHaveBeenCalledWith('{"message":"hello"}', jasmine.any(Number))
})

it('should empty the batch after a flush', () => {
Expand All @@ -50,8 +50,7 @@ describe('batch', () => {
batch.add({ message: '3' })
expect(transport.send).toHaveBeenCalledWith(
'{"message":"1"}\n{"message":"2"}\n{"message":"3"}',
jasmine.any(Number),
'batch_messages_limit'
jasmine.any(Number)
)
})

Expand All @@ -60,36 +59,24 @@ describe('batch', () => {
expect(transport.send).not.toHaveBeenCalled()

batch.add({ message: '60 bytes - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' })
expect(transport.send).toHaveBeenCalledWith(
'{"message":"50 bytes - xxxxxxxxxxxxxxxxxxxxxxxxx"}',
50,
'batch_bytes_limit'
)
expect(transport.send).toHaveBeenCalledWith('{"message":"50 bytes - xxxxxxxxxxxxxxxxxxxxxxxxx"}', 50)

batch.flush()
expect(transport.send).toHaveBeenCalledWith(
'{"message":"60 bytes - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}',
60,
undefined
)
expect(transport.send).toHaveBeenCalledWith('{"message":"60 bytes - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}', 60)
})

it('should consider separators when computing the byte count', () => {
batch.add({ message: '30 bytes - xxxxx' }) // batch: 30 sep: 0
batch.add({ message: '30 bytes - xxxxx' }) // batch: 60 sep: 1
batch.add({ message: '39 bytes - xxxxxxxxxxxxxx' }) // batch: 99 sep: 2

expect(transport.send).toHaveBeenCalledWith(
'{"message":"30 bytes - xxxxx"}\n{"message":"30 bytes - xxxxx"}',
61,
jasmine.any(String)
)
expect(transport.send).toHaveBeenCalledWith('{"message":"30 bytes - xxxxx"}\n{"message":"30 bytes - xxxxx"}', 61)
})

it('should call send one time when the byte count is too high and the batch is empty', () => {
const message = '101 bytes - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
batch.add({ message })
expect(transport.send).toHaveBeenCalledWith(`{"message":"${message}"}`, 101, jasmine.any(String))
expect(transport.send).toHaveBeenCalledWith(`{"message":"${message}"}`, 101)
})

it('should flush the batch and send the message when the message is too heavy', () => {
Expand Down Expand Up @@ -128,8 +115,7 @@ describe('batch', () => {

expect(transport.send).toHaveBeenCalledWith(
'{"message":"2"}\n{"message":"3"}\n{"message":"4"}',
jasmine.any(Number),
jasmine.any(String)
jasmine.any(Number)
)

batch.upsert({ message: '5' }, 'c')
Expand All @@ -138,8 +124,7 @@ describe('batch', () => {

expect(transport.send).toHaveBeenCalledWith(
'{"message":"5"}\n{"message":"6"}\n{"message":"7"}',
jasmine.any(Number),
jasmine.any(String)
jasmine.any(Number)
)

batch.upsert({ message: '8' }, 'a')
Expand All @@ -148,7 +133,7 @@ describe('batch', () => {
batch.upsert({ message: '11' }, 'b')
batch.flush()

expect(transport.send).toHaveBeenCalledWith('{"message":"10"}\n{"message":"11"}', jasmine.any(Number), undefined)
expect(transport.send).toHaveBeenCalledWith('{"message":"10"}\n{"message":"11"}', jasmine.any(Number))
})

it('should be able to use telemetry in the httpRequest.send', () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/transport/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Batch {
this.addOrUpdate(message, key)
}

flush(reason?: string) {
flush() {
if (this.bufferMessagesCount !== 0) {
const messages = this.pushOnlyBuffer.concat(objectValues(this.upsertBuffer))
const bytesCount = this.bufferBytesCount
Expand All @@ -44,7 +44,7 @@ export class Batch {
this.bufferBytesCount = 0
this.bufferMessagesCount = 0

this.request.send(messages.join('\n'), bytesCount, reason)
this.request.send(messages.join('\n'), bytesCount)
}
}

Expand Down Expand Up @@ -73,12 +73,12 @@ export class Batch {
this.remove(key)
}
if (this.willReachedBytesLimitWith(messageBytesCount)) {
this.flush('batch_bytes_limit')
this.flush()
}

this.push(processedMessage, messageBytesCount, key)
if (this.isFull()) {
this.flush('batch_messages_limit')
this.flush()
}
}

Expand Down Expand Up @@ -129,7 +129,7 @@ export class Batch {
private flushPeriodically() {
setTimeout(
monitor(() => {
this.flush('batch_flush_timeout')
this.flush()
this.flushPeriodically()
}),
this.flushTimeout
Expand All @@ -155,15 +155,15 @@ export class Batch {
*/
addEventListener(document, DOM_EVENT.VISIBILITY_CHANGE, () => {
if (document.visibilityState === 'hidden') {
this.flush('visibility_hidden')
this.flush()
}
})
/**
* Safari does not support yet to send a request during:
* - a visibility change during doc unload (cf: https://bugs.webkit.org/show_bug.cgi?id=194897)
* - a page hide transition (cf: https://bugs.webkit.org/show_bug.cgi?id=188329)
*/
addEventListener(window, DOM_EVENT.BEFORE_UNLOAD, () => this.flush('before_unload'))
addEventListener(window, DOM_EVENT.BEFORE_UNLOAD, () => this.flush())
}
}
}
88 changes: 0 additions & 88 deletions packages/core/src/transport/failedSendBeacon.spec.ts

This file was deleted.

48 changes: 0 additions & 48 deletions packages/core/src/transport/failedSendBeacon.ts

This file was deleted.

5 changes: 1 addition & 4 deletions packages/core/src/transport/httpRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { EndpointBuilder } from '../domain/configuration'
import { addTelemetryError } from '../domain/telemetry'
import { addFailedSendBeacon } from './failedSendBeacon'

/**
* Use POST request without content type to:
Expand All @@ -13,7 +12,7 @@ import { addFailedSendBeacon } from './failedSendBeacon'
export class HttpRequest {
constructor(private endpointBuilder: EndpointBuilder, private bytesLimit: number) {}

send(data: string | FormData, bytesCount: number, flushReason?: string) {
send(data: string | FormData, bytesCount: number) {
const url = this.endpointBuilder.build()
const canUseBeacon = !!navigator.sendBeacon && bytesCount < this.bytesLimit
if (canUseBeacon) {
Expand All @@ -23,8 +22,6 @@ export class HttpRequest {
if (isQueued) {
return
}

addFailedSendBeacon(this.endpointBuilder.endpointType, bytesCount, flushReason)
} catch (e) {
reportBeaconError(e)
}
Expand Down
Loading

0 comments on commit 0ee3479

Please sign in to comment.