Skip to content

Commit b787386

Browse files
committed
Added comment, variable naming changes.
1 parent 4f025e4 commit b787386

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ describe('Performance Monitoring > perf_logger', () => {
303303
);
304304
});
305305

306+
// Performance SDK doesn't instrument requests sent from SDK itself, therefore blacklist
307+
// requests sent to cc endpoint.
306308
it('skips performance collection if domain is cc', () => {
307309
const CC_NETWORK_PERFORMANCE_ENTRY: PerformanceResourceTiming = {
308310
connectEnd: 0,
@@ -338,6 +340,8 @@ describe('Performance Monitoring > perf_logger', () => {
338340
expect(addToQueueStub).not.called;
339341
});
340342

343+
// Performance SDK doesn't instrument requests sent from SDK itself, therefore blacklist
344+
// requests sent to fl endpoint.
341345
it('skips performance collection if domain is fl', () => {
342346
const FL_NETWORK_PERFORMANCE_ENTRY: PerformanceResourceTiming = {
343347
connectEnd: 0,

packages/performance/src/services/perf_logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export function logNetworkRequest(networkRequest: NetworkRequest): void {
156156
const networkRequestHostName = new URL(networkRequest.url).hostname;
157157

158158
// Blacklist old log endpoint and new transport endpoint.
159+
// Because Performance SDK doesn't instrument requests sent from SDK itself.
159160
const logEndpointHostName = new URL(settingsService.logEndPointUrl).hostname;
160161
const flEndpointHostName = new URL(settingsService.flTransportEndpointUrl)
161162
.hostname;

packages/performance/src/services/remote_config_service.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface SecondaryConfig {
4141

4242
// These values will be used if the remote config object is successfully
4343
// retrieved, but the template does not have these fields.
44-
const SECONDARY_CONFIGS: SecondaryConfig = {
44+
const DEFAULT_CONFIGS: SecondaryConfig = {
4545
loggingEnabled: true,
4646
shouldSendToFl: true
4747
};
@@ -184,28 +184,28 @@ function processConfig(
184184
// known.
185185
settingsServiceInstance.loggingEnabled =
186186
String(entries.fpr_enabled) === 'true';
187-
} else if (SECONDARY_CONFIGS.loggingEnabled !== undefined) {
187+
} else if (DEFAULT_CONFIGS.loggingEnabled !== undefined) {
188188
// Config retrieved successfully, but there is no fpr_enabled in template.
189189
// Use secondary configs value.
190-
settingsServiceInstance.loggingEnabled = SECONDARY_CONFIGS.loggingEnabled;
190+
settingsServiceInstance.loggingEnabled = DEFAULT_CONFIGS.loggingEnabled;
191191
}
192192
if (entries.fpr_log_source) {
193193
settingsServiceInstance.logSource = Number(entries.fpr_log_source);
194-
} else if (SECONDARY_CONFIGS.logSource) {
195-
settingsServiceInstance.logSource = SECONDARY_CONFIGS.logSource;
194+
} else if (DEFAULT_CONFIGS.logSource) {
195+
settingsServiceInstance.logSource = DEFAULT_CONFIGS.logSource;
196196
}
197197

198198
if (entries.fpr_log_endpoint_url) {
199199
settingsServiceInstance.logEndPointUrl = entries.fpr_log_endpoint_url;
200-
} else if (SECONDARY_CONFIGS.logEndPointUrl) {
201-
settingsServiceInstance.logEndPointUrl = SECONDARY_CONFIGS.logEndPointUrl;
200+
} else if (DEFAULT_CONFIGS.logEndPointUrl) {
201+
settingsServiceInstance.logEndPointUrl = DEFAULT_CONFIGS.logEndPointUrl;
202202
}
203203

204204
// Key from Remote Config has to be non-empty string, otherwsie use local value.
205205
if (entries.fpr_log_transport_key) {
206206
settingsServiceInstance.transportKey = entries.fpr_log_transport_key;
207-
} else if (SECONDARY_CONFIGS.transportKey) {
208-
settingsServiceInstance.transportKey = SECONDARY_CONFIGS.transportKey;
207+
} else if (DEFAULT_CONFIGS.transportKey) {
208+
settingsServiceInstance.transportKey = DEFAULT_CONFIGS.transportKey;
209209
}
210210

211211
// If config object state indicates that no template has been set, that means it is new user of
@@ -219,7 +219,7 @@ function processConfig(
219219
settingsServiceInstance.shouldSendToFl =
220220
NO_TEMPLATE_CONFIGS.shouldSendToFl;
221221
}
222-
} else if (entries.fpr_log_transport_web_percent !== undefined) {
222+
} else if (entries.fpr_log_transport_web_percent) {
223223
// If config object state doesn't indicate no template, it can only be UPDATE for now.
224224
// - Performance Monitoring doesn't set etag in request, therefore state cannot be NO_CHANGE.
225225
// - Sampling rate flags and master flag are required, therefore state cannot be EMPTY_CONFIG.
@@ -228,27 +228,27 @@ function processConfig(
228228
iid,
229229
Number(entries.fpr_log_transport_web_percent)
230230
);
231-
} else if (SECONDARY_CONFIGS.shouldSendToFl !== undefined) {
231+
} else if (DEFAULT_CONFIGS.shouldSendToFl !== undefined) {
232232
// If config object state is UPDATE and rollout flag is not present, that means rollout is
233233
// complete and rollout flag is deprecated, therefore dispatch events to new transport endpoint.
234-
settingsServiceInstance.shouldSendToFl = SECONDARY_CONFIGS.shouldSendToFl;
234+
settingsServiceInstance.shouldSendToFl = DEFAULT_CONFIGS.shouldSendToFl;
235235
}
236236

237237
if (entries.fpr_vc_network_request_sampling_rate !== undefined) {
238238
settingsServiceInstance.networkRequestsSamplingRate = Number(
239239
entries.fpr_vc_network_request_sampling_rate
240240
);
241-
} else if (SECONDARY_CONFIGS.networkRequestsSamplingRate !== undefined) {
241+
} else if (DEFAULT_CONFIGS.networkRequestsSamplingRate !== undefined) {
242242
settingsServiceInstance.networkRequestsSamplingRate =
243-
SECONDARY_CONFIGS.networkRequestsSamplingRate;
243+
DEFAULT_CONFIGS.networkRequestsSamplingRate;
244244
}
245245
if (entries.fpr_vc_trace_sampling_rate !== undefined) {
246246
settingsServiceInstance.tracesSamplingRate = Number(
247247
entries.fpr_vc_trace_sampling_rate
248248
);
249-
} else if (SECONDARY_CONFIGS.tracesSamplingRate !== undefined) {
249+
} else if (DEFAULT_CONFIGS.tracesSamplingRate !== undefined) {
250250
settingsServiceInstance.tracesSamplingRate =
251-
SECONDARY_CONFIGS.tracesSamplingRate;
251+
DEFAULT_CONFIGS.tracesSamplingRate;
252252
}
253253
// Set the per session trace and network logging flags.
254254
settingsServiceInstance.logTraceAfterSampling = shouldLogAfterSampling(
@@ -269,7 +269,7 @@ function shouldLogAfterSampling(samplingRate: number): boolean {
269269
}
270270

271271
/**
272-
* True if event should be sent to Fl transport endpoint rather than log endpoint.
272+
* True if event should be sent to Fl transport endpoint rather than CC transport endpoint.
273273
* rolloutPercent is in range [0.0, 100.0].
274274
* @param {string} iid Installation ID which identifies a web app installed on client.
275275
* @param {number} rolloutPercent the possibility of this app sending events to Fl endpoint.
@@ -282,7 +282,7 @@ export function isDestFl(iid: string, rolloutPercent: number): boolean {
282282
return getHashPercent(iid) < rolloutPercent;
283283
}
284284
/**
285-
* Generate integer value range in [0, 99].
285+
* Generate integer value range in [0, 99]. Implementation from String.hashCode() in Java.
286286
* @param {string} seed Same seed will generate consistent hash value using this algorithm.
287287
* @return {number} Hash value in range [0, 99], generated from seed and hash algorithm.
288288
*/

packages/performance/src/services/transport_service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ export function setupTransportService(): void {
6565
}
6666
}
6767

68+
/**
69+
* Utilized by testing to clean up message queue and un-initialize transport service.
70+
*/
6871
export function resetTransportService(): void {
6972
isTransportSetup = false;
7073
queue = [];

0 commit comments

Comments
 (0)