@@ -20,7 +20,7 @@ import { SettingsService } from './settings_service';
20
20
import { CONFIG_EXPIRY_LOCAL_STORAGE_KEY } from '../constants' ;
21
21
import { setupApi , Api } from './api_service' ;
22
22
import * as iidService from './iid_service' ;
23
- import { getConfig , isDestFl } from './remote_config_service' ;
23
+ import { getConfig } from './remote_config_service' ;
24
24
import { FirebaseApp } from '@firebase/app-types' ;
25
25
import '../../test/setup' ;
26
26
@@ -37,7 +37,6 @@ describe('Performance Monitoring > remote_config_service', () => {
37
37
"fpr_log_endpoint_url":"https://firebaselogging.test.com",\
38
38
"fpr_log_transport_key":"pseudo-transport-key",\
39
39
"fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
40
- "fpr_log_transport_web_percent":"100.0",\
41
40
"fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
42
41
"state":"UPDATE"}` ;
43
42
const PROJECT_ID = 'project1' ;
@@ -135,7 +134,6 @@ describe('Performance Monitoring > remote_config_service', () => {
135
134
TRANSPORT_KEY
136
135
) ;
137
136
expect ( SettingsService . getInstance ( ) . logSource ) . to . equal ( LOG_SOURCE ) ;
138
- expect ( SettingsService . getInstance ( ) . shouldSendToFl ) . to . be . true ;
139
137
expect (
140
138
SettingsService . getInstance ( ) . networkRequestsSamplingRate
141
139
) . to . equal ( NETWORK_SAMPLIG_RATE ) ;
@@ -176,7 +174,6 @@ describe('Performance Monitoring > remote_config_service', () => {
176
174
TRANSPORT_KEY
177
175
) ;
178
176
expect ( SettingsService . getInstance ( ) . logSource ) . to . equal ( LOG_SOURCE ) ;
179
- expect ( SettingsService . getInstance ( ) . shouldSendToFl ) . to . be . true ;
180
177
expect (
181
178
SettingsService . getInstance ( ) . networkRequestsSamplingRate
182
179
) . to . equal ( NETWORK_SAMPLIG_RATE ) ;
@@ -240,131 +237,38 @@ describe('Performance Monitoring > remote_config_service', () => {
240
237
expect ( SettingsService . getInstance ( ) . loggingEnabled ) . to . be . true ;
241
238
} ) ;
242
239
243
- it ( 'marks event destination to cc if there is no template' , async ( ) => {
244
- setup (
245
- {
246
- // Expired local config.
247
- expiry : '1556524895320' ,
248
- config : NOT_VALID_CONFIG
249
- } ,
250
- { reject : false , value : new Response ( '{"state":"NO_TEMPLATE"}' ) }
251
- ) ;
252
- await getConfig ( IID ) ;
253
-
254
- // If no template, will send to cc.
255
- expect ( SettingsService . getInstance ( ) . shouldSendToFl ) . to . be . false ;
256
- } ) ;
257
-
258
- it ( 'marks event destination to cc if instance state unspecified' , async ( ) => {
259
- setup (
260
- {
261
- // Expired local config.
262
- expiry : '1556524895320' ,
263
- config : NOT_VALID_CONFIG
264
- } ,
265
- {
266
- reject : false ,
267
- value : new Response ( '{"state":"INSTANCE_STATE_UNSPECIFIED"}' )
268
- }
269
- ) ;
270
- await getConfig ( IID ) ;
271
-
272
- // If instance state unspecified, will send to cc.
273
- expect ( SettingsService . getInstance ( ) . shouldSendToFl ) . to . be . false ;
274
- } ) ;
240
+ it ( 'gets the config from RC even with deprecated transport flag' , async ( ) => {
241
+ // Expired local config.
242
+ const EXPIRY_LOCAL_STORAGE_VALUE = '1556524895320' ;
243
+ const STRINGIFIED_CUSTOM_CONFIG = `{"entries":{\
244
+ "fpr_vc_network_request_sampling_rate":"0.250000",\
245
+ "fpr_log_transport_web_percent":"100.0",\
246
+ "fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
247
+ "state":"UPDATE"}` ;
275
248
276
- it ( "marks event destination to cc if state doesn't exist" , async ( ) => {
277
- setup (
249
+ const { storageGetItemStub : getItemStub } = setup (
278
250
{
279
- // Expired local config.
280
- expiry : '1556524895320' ,
281
- config : NOT_VALID_CONFIG
251
+ expiry : EXPIRY_LOCAL_STORAGE_VALUE ,
252
+ config : STRINGIFIED_CUSTOM_CONFIG
282
253
} ,
283
- { reject : false , value : new Response ( '{}' ) }
254
+ { reject : false , value : new Response ( STRINGIFIED_CONFIG ) }
284
255
) ;
285
- await getConfig ( IID ) ;
286
256
287
- // If "state" doesn't exist, will send to cc.
288
- expect ( SettingsService . getInstance ( ) . shouldSendToFl ) . to . be . false ;
289
- } ) ;
290
-
291
- it ( 'marks event destination to Fl if template exists but no rollout flag' , async ( ) => {
292
- const CONFIG_WITHOUT_ROLLOUT_FLAG = `{"entries":{"fpr_enabled":"true",\
293
- "fpr_log_endpoint_url":"https://firebaselogging.test.com",\
294
- "fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
295
- "fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
296
- "state":"UPDATE"}` ;
297
- setup (
298
- {
299
- // Expired local config.
300
- expiry : '1556524895320' ,
301
- config : NOT_VALID_CONFIG
302
- } ,
303
- { reject : false , value : new Response ( CONFIG_WITHOUT_ROLLOUT_FLAG ) }
304
- ) ;
305
257
await getConfig ( IID ) ;
306
258
307
- // If template exists but no rollout flag, will send to Fl.
308
- expect ( SettingsService . getInstance ( ) . shouldSendToFl ) . to . be . true ;
309
- } ) ;
310
-
311
- it ( 'marks event destination to cc when instance is outside of rollout range' , async ( ) => {
312
- const CONFIG_WITH_ROLLOUT_FLAG_10 = `{"entries":{"fpr_enabled":"true",\
313
- "fpr_log_endpoint_url":"https://firebaselogging.test.com",\
314
- "fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
315
- "fpr_log_transport_web_percent":"10.0",\
316
- "fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
317
- "state":"UPDATE"}` ;
318
- setup (
319
- {
320
- // Expired local config.
321
- expiry : '1556524895320' ,
322
- config : NOT_VALID_CONFIG
323
- } ,
324
- { reject : false , value : new Response ( CONFIG_WITH_ROLLOUT_FLAG_10 ) }
259
+ expect ( getItemStub ) . to . be . calledOnce ;
260
+ expect ( SettingsService . getInstance ( ) . loggingEnabled ) . to . be . true ;
261
+ expect ( SettingsService . getInstance ( ) . logEndPointUrl ) . to . equal ( LOG_URL ) ;
262
+ expect ( SettingsService . getInstance ( ) . transportKey ) . to . equal (
263
+ TRANSPORT_KEY
325
264
) ;
326
- await getConfig ( IID ) ;
327
-
328
- // If rollout flag exists, will send to cc when this instance is out of rollout scope.
329
- expect ( SettingsService . getInstance ( ) . shouldSendToFl ) . to . be . false ;
330
- } ) ;
331
-
332
- it ( 'marks event destination to Fl when instance is within rollout range' , async ( ) => {
333
- const CONFIG_WITH_ROLLOUT_FLAG_40 = `{"entries":{"fpr_enabled":"true",\
334
- "fpr_log_endpoint_url":"https://firebaselogging.test.com",\
335
- "fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
336
- "fpr_log_transport_web_percent":"40.0",\
337
- "fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
338
- "state":"UPDATE"}` ;
339
- setup (
340
- {
341
- // Expired local config.
342
- expiry : '1556524895320' ,
343
- config : NOT_VALID_CONFIG
344
- } ,
345
- { reject : false , value : new Response ( CONFIG_WITH_ROLLOUT_FLAG_40 ) }
265
+ expect ( SettingsService . getInstance ( ) . logSource ) . to . equal ( LOG_SOURCE ) ;
266
+ expect (
267
+ SettingsService . getInstance ( ) . networkRequestsSamplingRate
268
+ ) . to . equal ( NETWORK_SAMPLIG_RATE ) ;
269
+ expect ( SettingsService . getInstance ( ) . tracesSamplingRate ) . to . equal (
270
+ TRACE_SAMPLING_RATE
346
271
) ;
347
- await getConfig ( IID ) ;
348
-
349
- // If rollout flag exists, will send to Fl when this instance is within rollout scope.
350
- expect ( SettingsService . getInstance ( ) . shouldSendToFl ) . to . be . true ;
351
- } ) ;
352
- } ) ;
353
-
354
- describe ( 'isDestFl' , ( ) => {
355
- it ( 'marks traffic to cc when rollout percentage is 0' , ( ) => {
356
- const shouldSendToFl = isDestFl ( 'abc' , 0 ) ; // Hash percentage of "abc" is 38%.
357
- expect ( shouldSendToFl ) . to . be . false ;
358
- } ) ;
359
-
360
- it ( 'marks traffic to Fl when rollout percentage is 100' , ( ) => {
361
- const shouldSendToFl = isDestFl ( 'abc' , 100 ) ; // Hash percentage of "abc" is 38%.
362
- expect ( shouldSendToFl ) . to . be . true ;
363
- } ) ;
364
-
365
- it ( 'marks traffic to Fl if hash percentage is lower than rollout percentage 50%' , ( ) => {
366
- const shouldSendToFl = isDestFl ( 'abc' , 50 ) ; // Hash percentage of "abc" is 38%.
367
- expect ( shouldSendToFl ) . to . be . true ;
368
272
} ) ;
369
273
} ) ;
370
274
} ) ;
0 commit comments