Skip to content

Commit 8b8c321

Browse files
committed
Update function comment and replace URL usage with regex.
1 parent b787386 commit 8b8c321

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/performance/src/services/perf_logger.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,12 @@ export function logNetworkRequest(networkRequest: NetworkRequest): void {
153153

154154
// Do not log the js sdk's call to transport service domain to avoid unnecessary cycle.
155155
// Need to blacklist both old and new endpoints to avoid migration gap.
156-
const networkRequestHostName = new URL(networkRequest.url).hostname;
156+
const networkRequestHostName = extractDomain(networkRequest.url);
157157

158158
// Blacklist old log endpoint and new transport endpoint.
159159
// Because Performance SDK doesn't instrument requests sent from SDK itself.
160-
const logEndpointHostName = new URL(settingsService.logEndPointUrl).hostname;
161-
const flEndpointHostName = new URL(settingsService.flTransportEndpointUrl)
162-
.hostname;
160+
const logEndpointHostName = extractDomain(settingsService.logEndPointUrl);
161+
const flEndpointHostName = extractDomain(settingsService.flTransportEndpointUrl);
163162
if (
164163
networkRequestHostName === logEndpointHostName ||
165164
networkRequestHostName === flEndpointHostName
@@ -177,6 +176,15 @@ export function logNetworkRequest(networkRequest: NetworkRequest): void {
177176
setTimeout(() => sendLog(networkRequest, ResourceType.NetworkRequest), 0);
178177
}
179178

179+
function extractDomain(url: string): string {
180+
const urlRegex = /(https?:\/\/)?([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4})\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g;
181+
let matched = urlRegex.exec(url);
182+
if (matched && matched[1]) {
183+
return matched[1];
184+
}
185+
return "";
186+
}
187+
180188
function serializer(
181189
resource: NetworkRequest | Trace,
182190
resourceType: ResourceType

packages/performance/src/services/remote_config_service.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@ function shouldLogAfterSampling(samplingRate: number): boolean {
271271
/**
272272
* True if event should be sent to Fl transport endpoint rather than CC transport endpoint.
273273
* rolloutPercent is in range [0.0, 100.0].
274-
* @param {string} iid Installation ID which identifies a web app installed on client.
275-
* @param {number} rolloutPercent the possibility of this app sending events to Fl endpoint.
276-
* @return {boolean} true if this installation should send events to Fl endpoint.
277274
*/
278275
export function isDestFl(iid: string, rolloutPercent: number): boolean {
279276
if (iid.length === 0) {
@@ -283,8 +280,6 @@ export function isDestFl(iid: string, rolloutPercent: number): boolean {
283280
}
284281
/**
285282
* Generate integer value range in [0, 99]. Implementation from String.hashCode() in Java.
286-
* @param {string} seed Same seed will generate consistent hash value using this algorithm.
287-
* @return {number} Hash value in range [0, 99], generated from seed and hash algorithm.
288283
*/
289284
function getHashPercent(seed: string): number {
290285
let hash = 0;

0 commit comments

Comments
 (0)