Skip to content

Commit 7533327

Browse files
Merge branch 'master' into mrschmidt/componentsv2
2 parents c0b9713 + 7fa3d03 commit 7533327

17 files changed

+637
-97
lines changed

packages/firestore/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
- [fixed] Temporarily reverted the use of window.crypto to generate document
3+
IDs to address compatibility issues with IE 11, WebWorkers, and React Native.
24
- [changed] Firestore now limits the number of concurrent document lookups it
35
will perform when resolving inconsistencies in the local cache (#2683).
46
- [changed] Changed the in-memory representation of Firestore documents to

packages/messaging/src/controllers/sw-controller.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -277,6 +277,11 @@ describe('SwController', () => {
277277
});
278278

279279
it('warns if there are more action buttons than the browser limit', async () => {
280+
// This doesn't exist on Firefox:
281+
// https://developer.mozilla.org/en-US/docs/Web/API/notification/maxActions
282+
if (!Notification.maxActions) {
283+
return;
284+
}
280285
stub(Notification, 'maxActions').value(1);
281286

282287
const warnStub = stub(console, 'warn');

packages/messaging/src/controllers/sw-controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -339,6 +339,8 @@ function showNotification(details: NotificationDetails): Promise<void> {
339339
const title = details.title ?? '';
340340

341341
const { actions } = details;
342+
// Note: Firefox does not support the maxActions property.
343+
// https://developer.mozilla.org/en-US/docs/Web/API/notification/maxActions
342344
const { maxActions } = Notification;
343345
if (actions && maxActions && actions.length > maxActions) {
344346
console.warn(

packages/performance/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Unreleased
2+
- [changed] Update the transport mechanism of Fireperf events.
3+
4+
# 0.2.30
25
- [changed] Internal transport protocol update from proto2 to proto3.

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { SDK_VERSION } from '../constants';
2828
import * as attributeUtils from '../utils/attributes_utils';
2929
import { createNetworkRequestEntry } from '../resources/network_request';
3030
import '../../test/setup';
31+
import { mergeStrings } from '../utils/string_merger';
3132

3233
describe('Performance Monitoring > perf_logger', () => {
3334
const IID = 'idasdfsffe';
@@ -301,5 +302,82 @@ describe('Performance Monitoring > perf_logger', () => {
301302
EXPECTED_NETWORK_MESSAGE
302303
);
303304
});
305+
306+
// Performance SDK doesn't instrument requests sent from SDK itself, therefore blacklist
307+
// requests sent to cc endpoint.
308+
it('skips performance collection if domain is cc', () => {
309+
const CC_NETWORK_PERFORMANCE_ENTRY: PerformanceResourceTiming = {
310+
connectEnd: 0,
311+
connectStart: 0,
312+
decodedBodySize: 0,
313+
domainLookupEnd: 0,
314+
domainLookupStart: 0,
315+
duration: 39.610000094398856,
316+
encodedBodySize: 0,
317+
entryType: 'resource',
318+
fetchStart: 5645.689999917522,
319+
initiatorType: 'fetch',
320+
name: 'https://firebaselogging.googleapis.com/v0cc/log?message=a',
321+
nextHopProtocol: 'http/2+quic/43',
322+
redirectEnd: 0,
323+
redirectStart: 0,
324+
requestStart: 0,
325+
responseEnd: 5685.300000011921,
326+
responseStart: 0,
327+
secureConnectionStart: 0,
328+
startTime: 5645.689999917522,
329+
transferSize: 0,
330+
workerStart: 0,
331+
toJSON: () => {}
332+
};
333+
getIidStub.returns(IID);
334+
SettingsService.getInstance().loggingEnabled = true;
335+
SettingsService.getInstance().logNetworkAfterSampling = true;
336+
// Calls logNetworkRequest under the hood.
337+
createNetworkRequestEntry(CC_NETWORK_PERFORMANCE_ENTRY);
338+
clock.tick(1);
339+
340+
expect(addToQueueStub).not.called;
341+
});
342+
343+
// Performance SDK doesn't instrument requests sent from SDK itself, therefore blacklist
344+
// requests sent to fl endpoint.
345+
it('skips performance collection if domain is fl', () => {
346+
const FL_NETWORK_PERFORMANCE_ENTRY: PerformanceResourceTiming = {
347+
connectEnd: 0,
348+
connectStart: 0,
349+
decodedBodySize: 0,
350+
domainLookupEnd: 0,
351+
domainLookupStart: 0,
352+
duration: 39.610000094398856,
353+
encodedBodySize: 0,
354+
entryType: 'resource',
355+
fetchStart: 5645.689999917522,
356+
initiatorType: 'fetch',
357+
name: mergeStrings(
358+
'hts/frbslgigp.ogepscmv/ieo/eaylg',
359+
'tp:/ieaeogn-agolai.o/1frlglgc/o'
360+
),
361+
nextHopProtocol: 'http/2+quic/43',
362+
redirectEnd: 0,
363+
redirectStart: 0,
364+
requestStart: 0,
365+
responseEnd: 5685.300000011921,
366+
responseStart: 0,
367+
secureConnectionStart: 0,
368+
startTime: 5645.689999917522,
369+
transferSize: 0,
370+
workerStart: 0,
371+
toJSON: () => {}
372+
};
373+
getIidStub.returns(IID);
374+
SettingsService.getInstance().loggingEnabled = true;
375+
SettingsService.getInstance().logNetworkAfterSampling = true;
376+
// Calls logNetworkRequest under the hood.
377+
createNetworkRequestEntry(FL_NETWORK_PERFORMANCE_ENTRY);
378+
clock.tick(1);
379+
380+
expect(addToQueueStub).not.called;
381+
});
304382
});
305383
});

packages/performance/src/services/perf_logger.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,19 @@ export function logNetworkRequest(networkRequest: NetworkRequest): void {
150150
if (!settingsService.instrumentationEnabled) {
151151
return;
152152
}
153-
// Do not log the js sdk's call to cc service to avoid unnecessary cycle.
154-
if (networkRequest.url === settingsService.logEndPointUrl.split('?')[0]) {
153+
154+
// Do not log the js sdk's call to transport service domain to avoid unnecessary cycle.
155+
// Need to blacklist both old and new endpoints to avoid migration gap.
156+
const networkRequestUrl = networkRequest.url;
157+
158+
// Blacklist old log endpoint and new transport endpoint.
159+
// Because Performance SDK doesn't instrument requests sent from SDK itself.
160+
const logEndpointUrl = settingsService.logEndPointUrl.split('?')[0];
161+
const flEndpointUrl = settingsService.flTransportEndpointUrl.split('?')[0];
162+
if (
163+
networkRequestUrl === logEndpointUrl ||
164+
networkRequestUrl === flEndpointUrl
165+
) {
155166
return;
156167
}
157168

@@ -165,6 +176,7 @@ export function logNetworkRequest(networkRequest: NetworkRequest): void {
165176
setTimeout(() => sendLog(networkRequest, ResourceType.NetworkRequest), 0);
166177
}
167178

179+
168180
function serializer(
169181
resource: NetworkRequest | Trace,
170182
resourceType: ResourceType

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

Lines changed: 148 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,30 @@ import { SettingsService } from './settings_service';
2020
import { CONFIG_EXPIRY_LOCAL_STORAGE_KEY } from '../constants';
2121
import { setupApi, Api } from './api_service';
2222
import * as iidService from './iid_service';
23-
import { getConfig } from './remote_config_service';
23+
import { getConfig, isDestFl } from './remote_config_service';
2424
import { FirebaseApp } from '@firebase/app-types';
2525
import '../../test/setup';
2626

2727
describe('Performance Monitoring > remote_config_service', () => {
2828
const IID = 'asd123';
2929
const AUTH_TOKEN = 'auth_token';
3030
const LOG_URL = 'https://firebaselogging.test.com';
31+
const TRANSPORT_KEY = 'pseudo-transport-key';
3132
const LOG_SOURCE = 2;
3233
const NETWORK_SAMPLIG_RATE = 0.25;
3334
const TRACE_SAMPLING_RATE = 0.5;
3435
const GLOBAL_CLOCK_NOW = 1556524895326;
3536
const STRINGIFIED_CONFIG = `{"entries":{"fpr_enabled":"true",\
36-
"fpr_log_endpoint_url":"https://firebaselogging.test.com",\
37-
"fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
38-
"fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
39-
"state":"UPDATE"}`;
37+
"fpr_log_endpoint_url":"https://firebaselogging.test.com",\
38+
"fpr_log_transport_key":"pseudo-transport-key",\
39+
"fpr_log_source":"2","fpr_vc_network_request_sampling_rate":"0.250000",\
40+
"fpr_log_transport_web_percent":"100.0",\
41+
"fpr_vc_session_sampling_rate":"0.250000","fpr_vc_trace_sampling_rate":"0.500000"},\
42+
"state":"UPDATE"}`;
4043
const PROJECT_ID = 'project1';
4144
const APP_ID = '1:23r:web:fewq';
4245
const API_KEY = 'asdfghjk';
46+
const NOT_VALID_CONFIG = 'not a valid config and should not be used';
4347

4448
let clock: SinonFakeTimers;
4549

@@ -127,7 +131,11 @@ describe('Performance Monitoring > remote_config_service', () => {
127131
expect(getItemStub).to.be.called;
128132
expect(SettingsService.getInstance().loggingEnabled).to.be.true;
129133
expect(SettingsService.getInstance().logEndPointUrl).to.equal(LOG_URL);
134+
expect(SettingsService.getInstance().transportKey).to.equal(
135+
TRANSPORT_KEY
136+
);
130137
expect(SettingsService.getInstance().logSource).to.equal(LOG_SOURCE);
138+
expect(SettingsService.getInstance().shouldSendToFl).to.be.true;
131139
expect(
132140
SettingsService.getInstance().networkRequestsSamplingRate
133141
).to.equal(NETWORK_SAMPLIG_RATE);
@@ -164,7 +172,11 @@ describe('Performance Monitoring > remote_config_service', () => {
164172
expect(getItemStub).to.be.calledOnce;
165173
expect(SettingsService.getInstance().loggingEnabled).to.be.true;
166174
expect(SettingsService.getInstance().logEndPointUrl).to.equal(LOG_URL);
175+
expect(SettingsService.getInstance().transportKey).to.equal(
176+
TRANSPORT_KEY
177+
);
167178
expect(SettingsService.getInstance().logSource).to.equal(LOG_SOURCE);
179+
expect(SettingsService.getInstance().shouldSendToFl).to.be.true;
168180
expect(
169181
SettingsService.getInstance().networkRequestsSamplingRate
170182
).to.equal(NETWORK_SAMPLIG_RATE);
@@ -180,7 +192,7 @@ describe('Performance Monitoring > remote_config_service', () => {
180192
setup(
181193
{
182194
expiry: EXPIRY_LOCAL_STORAGE_VALUE,
183-
config: 'not a valid config and should not be used'
195+
config: NOT_VALID_CONFIG
184196
},
185197
{ reject: true }
186198
);
@@ -201,7 +213,7 @@ describe('Performance Monitoring > remote_config_service', () => {
201213
setup(
202214
{
203215
expiry: EXPIRY_LOCAL_STORAGE_VALUE,
204-
config: 'not a valid config and should not be used'
216+
config: NOT_VALID_CONFIG
205217
},
206218
{ reject: false, value: new Response(STRINGIFIED_PARTIAL_CONFIG) }
207219
);
@@ -214,18 +226,145 @@ describe('Performance Monitoring > remote_config_service', () => {
214226
it('uses secondary configs if the response does not have any fields', async () => {
215227
// Expired local config.
216228
const EXPIRY_LOCAL_STORAGE_VALUE = '1556524895320';
217-
const STRINGIFIED_PARTIAL_CONFIG = '{"state":"NO TEMPLATE"}';
229+
const STRINGIFIED_PARTIAL_CONFIG = '{"state":"NO_TEMPLATE"}';
218230

219231
setup(
220232
{
221233
expiry: EXPIRY_LOCAL_STORAGE_VALUE,
222-
config: 'not a valid config and should not be used'
234+
config: NOT_VALID_CONFIG
223235
},
224236
{ reject: false, value: new Response(STRINGIFIED_PARTIAL_CONFIG) }
225237
);
226238
await getConfig(IID);
227239

228240
expect(SettingsService.getInstance().loggingEnabled).to.be.true;
229241
});
242+
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+
});
275+
276+
it("marks event destination to cc if state doesn't exist", async () => {
277+
setup(
278+
{
279+
// Expired local config.
280+
expiry: '1556524895320',
281+
config: NOT_VALID_CONFIG
282+
},
283+
{ reject: false, value: new Response('{}') }
284+
);
285+
await getConfig(IID);
286+
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+
await getConfig(IID);
306+
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) }
325+
);
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) }
346+
);
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+
});
230369
});
231370
});

0 commit comments

Comments
 (0)