Skip to content

Commit 1f7f6ab

Browse files
committed
Put max flush size behind remote config flag
1 parent fe795f3 commit 1f7f6ab

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

packages/performance/src/services/remote_config_service.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ describe('Performance Monitoring > remote_config_service', () => {
4040
"fpr_log_endpoint_url":"https://firebaselogging.test.com",\
4141
"fpr_log_transport_key":"pseudo-transport-key",\
4242
"fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
43-
"fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
43+
"fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000",
44+
"fpr_log_max_flush_size":"10"},\
4445
"state":"UPDATE"}`;
4546
const PROJECT_ID = 'project1';
4647
const APP_ID = '1:23r:web:fewq';
@@ -80,6 +81,7 @@ describe('Performance Monitoring > remote_config_service', () => {
8081
settingsService.loggingEnabled = false;
8182
settingsService.networkRequestsSamplingRate = 1;
8283
settingsService.tracesSamplingRate = 1;
84+
settingsService.logMaxFlushSize = 40;
8385
}
8486

8587
// parameterized beforeEach. Should be called at beginning of each test.
@@ -150,6 +152,7 @@ describe('Performance Monitoring > remote_config_service', () => {
150152
expect(SettingsService.getInstance().tracesSamplingRate).to.equal(
151153
TRACE_SAMPLING_RATE
152154
);
155+
expect(SettingsService.getInstance().logMaxFlushSize).to.equal(10);
153156
});
154157

155158
it('does not call remote config if a valid config is in local storage', async () => {
@@ -190,6 +193,7 @@ describe('Performance Monitoring > remote_config_service', () => {
190193
expect(SettingsService.getInstance().tracesSamplingRate).to.equal(
191194
TRACE_SAMPLING_RATE
192195
);
196+
expect(SettingsService.getInstance().logMaxFlushSize).to.equal(10);
193197
});
194198

195199
it('does not change the default config if call to RC fails', async () => {
@@ -207,6 +211,7 @@ describe('Performance Monitoring > remote_config_service', () => {
207211
await getConfig(performanceController, IID);
208212

209213
expect(SettingsService.getInstance().loggingEnabled).to.equal(false);
214+
expect(SettingsService.getInstance().logMaxFlushSize).to.equal(40);
210215
});
211216

212217
it('uses secondary configs if the response does not have all the fields', async () => {

packages/performance/src/services/remote_config_service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface SecondaryConfig {
3838
transportKey?: string;
3939
tracesSamplingRate?: number;
4040
networkRequestsSamplingRate?: number;
41+
logMaxFlushSize?: number;
4142
}
4243

4344
// These values will be used if the remote config object is successfully
@@ -56,6 +57,7 @@ interface RemoteConfigTemplate {
5657
fpr_vc_network_request_sampling_rate?: string;
5758
fpr_vc_trace_sampling_rate?: string;
5859
fpr_vc_session_sampling_rate?: string;
60+
fpr_log_max_flush_size?: string;
5961
}
6062
/* eslint-enable camelcase */
6163

@@ -221,6 +223,14 @@ function processConfig(
221223
settingsServiceInstance.tracesSamplingRate =
222224
DEFAULT_CONFIGS.tracesSamplingRate;
223225
}
226+
227+
if (entries.fpr_log_max_flush_size) {
228+
settingsServiceInstance.logMaxFlushSize = Number(
229+
entries.fpr_log_max_flush_size
230+
);
231+
} else if (DEFAULT_CONFIGS.logMaxFlushSize) {
232+
settingsServiceInstance.logMaxFlushSize = DEFAULT_CONFIGS.logMaxFlushSize;
233+
}
224234
// Set the per session trace and network logging flags.
225235
settingsServiceInstance.logTraceAfterSampling = shouldLogAfterSampling(
226236
settingsServiceInstance.tracesSamplingRate

packages/performance/src/services/settings_service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export class SettingsService {
5454
// TTL of config retrieved from remote config in hours.
5555
configTimeToLive = 12;
5656

57+
// The max number of events to send during a flush. This number is kept low to since Chrome has a
58+
// shared payload limit for all sendBeacon calls in the same nav context.
59+
logMaxFlushSize = 40;
60+
5761
getFlTransportFullUrl(): string {
5862
return this.flTransportEndpointUrl.concat('?key=', this.transportKey);
5963
}

packages/performance/src/services/transport_service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ const DEFAULT_REMAINING_TRIES = 3;
2626

2727
// Most browsers have a max payload of 64KB for sendbeacon/keep alive payload.
2828
const MAX_SEND_BEACON_PAYLOAD_SIZE = 65536;
29-
// The max number of events to send during a flush. This number is kept low to since Chrome has a
30-
// shared payload limit for all sendBeacon calls in the same nav context.
31-
const MAX_FLUSH_SIZE = 40;
3229

3330
const TEXT_ENCODER = new TextEncoder();
3431

@@ -189,7 +186,7 @@ export function flushQueuedEvents(): void {
189186

190187
while (queue.length > 0) {
191188
// Send the last events first to prioritize page load traces
192-
const staged = queue.splice(-MAX_FLUSH_SIZE);
189+
const staged = queue.splice(-SettingsService.getInstance().logMaxFlushSize);
193190
const body = buildPayload(staged);
194191

195192
if (

0 commit comments

Comments
 (0)