Skip to content

Commit

Permalink
fix: region selection criteria should be configurable (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszczerpak-cloudinary authored Dec 10, 2024
1 parent ebe329c commit 1c06bff
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const conf = {
},
timeout: process.env.WTP_TIMEOUT || 30000,
"locationSelector": {
"allowRegex": process.env.WTP_LS_ALLOW_REGEX || '_US_',
"cacheTtl": process.env.WTP_LS_CACHE_TTL || 10,
"updateTimeout": process.env.WTP_LS_UPDATE_TIMEOUT || 20,
"defaultLocation": process.env.WTP_LS_DEFAULT_LOCATION || "IAD_US_01"
Expand Down
2 changes: 1 addition & 1 deletion wtp/apiCaller.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const runWtpTest = async (url, mobile, cb) => {
height: config.get('wtp.viewportHeight'),
custom: config.get('wtp.imageScript'),
location: await locationSelector.getLocation() + ':Chrome.Native', // Native means no speed shaping in browser, full speed ahead
mobile: (mobile) ? 1 : 0,
mobile: (mobile) ? 1 : 0,
fvonly: 1, // first view only
timeline: 1 // workaround for WPT sometimes hanging on getComputedStyle()
},
Expand Down
3 changes: 2 additions & 1 deletion wtp/locationSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class LocationSelector {
if (!LocationSelector.instance) {
this.cachedAllLocations = [];
this.location = config.get('wtp.locationSelector.defaultLocation');
this.allowRegex = new RegExp(config.get('wtp.locationSelector.allowRegex'));
this.lastUpdated = null;
this.mutex = withTimeout(new Mutex(), config.get('wtp.locationSelector.updateTimeout') * 1000);
LocationSelector.instance = this;
Expand Down Expand Up @@ -113,7 +114,7 @@ class LocationSelector {
}

const filtered = Object.keys(newLocations)
.filter(key => key.includes("_US_")) // we only want US-based instances
.filter(key => this.allowRegex.test(key))
.reduce((arr, key) => {
return [...arr, newLocations[key]];
}, []);
Expand Down

0 comments on commit 1c06bff

Please sign in to comment.