Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
fix(proxy): prevent duplicate creation of backends for proxy strains
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed May 6, 2019
1 parent 73f1d8e commit c157e8b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"dependencies": {
"@adobe/fastly-native-promises": "1.9.1",
"@adobe/helix-shared": "1.0.2",
"@adobe/helix-shared": "1.1.0",
"fs-extra": "7.0.1",
"glob-to-regexp": "0.4.1",
"uri-js": "4.2.2"
Expand Down
9 changes: 6 additions & 3 deletions src/fastly/backends.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ async function updatestrains(fastly, version, strains) {
// filter out all proxy strains
const proxystrains = strains.getProxyStrains();
// create a new backend or update and existing one for each origin defined
const origins = proxystrains.map(proxystrain => proxystrain.origin);
const updateorigins = origins.map(origin => fastly.writeBackend(
const origins = {};
proxystrains.forEach((proxystrain) => {
origins[proxystrain.origin.name] = proxystrain.origin;
});
const updateorigins = Object.values(origins).map(origin => fastly.writeBackend(
version,
origin.name,
origin.toJSON(),
));

return Promise.all([
...updateorigins,
writevcl(fastly, version, reset([...Object.values(backends), ...origins]), 'reset.vcl')]);
writevcl(fastly, version, reset([...Object.values(backends), ...Object.values(origins)]), 'reset.vcl')]);
}

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions test/backends.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe('Testing backends.js', () => {
.init();

assert.ok(await updatestrains(fastly, 1, config.strains));
assert.ok(fastly.writeBackend.calledThrice);
assert.ok(fastly.writeBackend.calledTwice);

assert.ok(fastly.writeVCL.calledOnce);

assert.ok(fastly.writeBackend.calledWith(1, 'Proxywwwadobeio861b'));
assert.ok(fastly.writeBackend.calledWith(1, 'Proxywwwadobeio3a0a'));
assert.ok(fastly.writeBackend.calledWith(1, 'publish'));
});
});
8 changes: 4 additions & 4 deletions test/fixtures/full-reset.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ if (req.backend == F_AdobeRuntime && req.restarts == 0) {
set req.backend = F_AdobeRuntime;
}
}
if (req.backend == F_Proxywwwadobeio861b && req.restarts == 0) {
if (req.backend == F_Proxywwwadobeio3a0a && req.restarts == 0) {
if (server.identity !~ "-IAD$" && req.http.Fastly-FF !~ "-IAD") {
set req.backend = ssl_shield_iad_va_us;
}
if (!req.backend.healthy) {
set req.backend = F_Proxywwwadobeio861b;
set req.backend = F_Proxywwwadobeio3a0a;
}
}
if (req.backend == F_publish && req.restarts == 0) {
Expand All @@ -31,11 +31,11 @@ if (req.backend == F_publish && req.restarts == 0) {
set req.backend = F_publish;
}
}
if (req.backend == F_Proxywwwadobeio6fab && req.restarts == 0) {
if (req.backend == F_Proxywwwadobeio3a0a && req.restarts == 0) {
if (server.identity !~ "-IAD$" && req.http.Fastly-FF !~ "-IAD") {
set req.backend = ssl_shield_iad_va_us;
}
if (!req.backend.healthy) {
set req.backend = F_Proxywwwadobeio6fab;
set req.backend = F_Proxywwwadobeio3a0a;
}
}
4 changes: 2 additions & 2 deletions test/fixtures/full-resolve.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (req.http.Host == "client.project-helix.io") {
set req.http.X-Proxy-Root = "/";
set req.http.X-Request-Type = "Proxy";

set req.backend = F_Proxywwwadobeio861b;
set req.backend = F_Proxywwwadobeio3a0a;
set req.http.host = "www.adobe.io";

set req.http.X-Sticky = "true";
Expand Down Expand Up @@ -42,7 +42,7 @@ if (req.http.Host == "client.project-helix.io") {
set req.http.X-Proxy-Root = "/newdir";
set req.http.X-Request-Type = "Proxy";

set req.backend = F_Proxywwwadobeio6fab;
set req.backend = F_Proxywwwadobeio3a0a;
set req.http.host = "www.adobe.io";

# Rewrite the URL to include the proxy path
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/urls-resolve.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (req.http.Host == "www.project-helix.io" && (req.http.X-FullDirname ~ "^/clie
set req.http.X-Proxy-Root = "/";
set req.http.X-Request-Type = "Proxy";

set req.backend = F_Proxywwwadobeio861b;
set req.backend = F_Proxywwwadobeio3a0a;
set req.http.host = "www.adobe.io";

set req.http.X-Sticky = "true";
Expand Down

0 comments on commit c157e8b

Please sign in to comment.