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

Universal Runtime Support #704

Merged
merged 15 commits into from
Feb 2, 2021
Merged

Universal Runtime Support #704

merged 15 commits into from
Feb 2, 2021

Conversation

trieloff
Copy link
Contributor

@trieloff trieloff commented Jan 26, 2021

Adds support for the universal runtime.

Request types:

  • dispatch
  • static_url
  • static
  • purge
  • cgi
  • query
  • embed
  • preflight will be done later, needs support in helix-shared.
  • content

@tripodsan for static_url static purge query embed we rely on the OpenWhisk linking feature that we have not replicated yet in helix-dispatch. Should we just hardcode a hostname (a.k.a. namespace) such as helix-shared.anywhere.run? We'd need to make sure the corresponding actions are deployed to this service.

@trieloff trieloff marked this pull request as draft January 26, 2021 14:34
@github-actions
Copy link

This PR will trigger a minor release when merged.

@codecov
Copy link

codecov bot commented Jan 26, 2021

Codecov Report

Merging #704 (d1628cb) into main (d6be062) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #704   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines          348       348           
=========================================
  Hits           348       348           
Impacted Files Coverage Δ
src/fastly/backends.js 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d5be38...d1628cb. Read the comment docs.

@tripodsan
Copy link
Contributor

tripodsan commented Jan 27, 2021

for static_url static purge query embed we rely on the OpenWhisk linking feature that we have not replicated yet in helix-dispatch. Should we just hardcode a hostname (a.k.a. namespace) such as helix-shared.anywhere.run? We'd need to make sure the corresponding actions are deployed to this service.

I don't quite understand the problem. the action invokes stay in the same environment.

eg: a request to:

https://helix-pages.anywhere.run/helix-services/dispatch@v4

will invoke the dispatch on the helix-pages namespace, which will then use the __OW_API_HOST and __OW_NAMESPACE to invoke the subsequent actions. so they don't use the anywhere gateway anymore.

see: https://github.com/adobe/helix-deploy/blob/7e21dc39969dadbd224d661b43240c948ded28c0/src/template/resolver.js#L94-L95

@trieloff
Copy link
Contributor Author

Let's take dispatch and purge as examples.

dispatch works just as you described, Fastly requests https://helix-pages.anywhere.run/helix-services/dispatch@v4 so everything is fine.

Now, purge is different:

  1. purge could be https://helix-pages.anywhere.run/helix-services/purge@v1, but this assumes that
  • either that the helix-pages project deployed all helix-related services to it's own namespace (on OW) and API gateway (on AWS)
  • or that the helix-services package is linked on OpenWhisk and the helix-pages API gateway is somehow mounting the lambdas from the helix AWS account into the helix-pages API gateway

or:
2. purge could be https://helix-services.anywhere.run/helix-services/purge@v1, but this comes with the drawback of:

  • no neat service sharing and accounting of invocations
  • all helix-services invocations count against the same rate limits

@tripodsan
Copy link
Contributor

tripodsan commented Jan 27, 2021

we don't have namespaces in AWS, and all helix-services are mounted in the helix-pages namespace in OW.

  1. purge could be https://helix-services.anywhere.run/helix-services/purge@v1, ...

no. that would be wrong.


I still don't understand the problem :-)

@trieloff
Copy link
Contributor Author

We deploy helix-pages (html action, etc) and helix-services (e.g. purge) differently in OW. I'd assume that we would have the same separation in AWS, i.e. different subdomains for anywhere.run. The question is how to reconcile this here.

@tripodsan
Copy link
Contributor

We deploy helix-pages (html action, etc) and helix-services (e.g. purge) differently in OW. I'd assume that we would have the same separation in AWS, i.e. different subdomains for anywhere.run. The question is how to reconcile this here.

ah, ok. in AWS we just ignore the namespaces, and hope there is no collision in the packages :-)
at a later stage, we could choose different API Gateways for different namespaces, and then use different AWS resource groups to execute the functions, for separation of limits/costs (I guess)

@trieloff
Copy link
Contributor Author

Ok, for now I will assume the specified subdomain has all the actions and later we can build adobe/helix-deploy#91

@trieloff trieloff marked this pull request as ready for review January 29, 2021 12:26
trieloff added a commit to adobe/helix-pages that referenced this pull request Jan 29, 2021
depends on adobe/helix-publish#704 and is probably broken. The `universal` strain can only be selected via header, so there is little risk of breaking things until you ask for it
Copy link
Contributor

@tripodsan tripodsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm..there is a lot of duplicated code that calculates the universal/namespace vars. can't this be done in a function?

@trieloff
Copy link
Contributor Author

VCL does not have function, it only has subroutines, which makes this difficult. Ideally, we'd have functions that return a struct with var.namespace and var.universal that we could simply call. I thought about building something that would inline a subroutine, but decided to go with the more obvious, but also more verbose way.

Copy link
Contributor

@stefan-guggisberg stefan-guggisberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems ok (but to be honest: I don't really understand it)

Copy link
Contributor Author

@trieloff trieloff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefan-guggisberg I've added some elaboration.

# We need the action root for the next bit
call hlx_action_root;

if (req.http.X-Action-Root ~ "(^|^https://)([^/:\.]+)(/|\.([^/]+)/)([^/]+)") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern supports both formats of the package parameter: namespace/package and https://namespace.anywhere.run/package

set var.universal = true;
set var.hostname = var.namespace + "." + re.group.4;
set req.backend = F_UniversalRuntime;
set req.http.X-Backend-Host = var.hostname;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using the universal runtime, so we need to store the backend hostname, e.g. namespace

@@ -555,8 +581,8 @@ sub hlx_type_static_url {
set var.static_version = {"const:static_version"};
}

set req.http.X-Action-Root = "/api/v1/web/" + table.lookup(secrets, "OPENWHISK_NAMESPACE") + "/helix-services/static@" + var.static_version;
set req.http.X-Backend-URL = req.http.X-Action-Root
set req.http.X-Backend-URL = if(var.universal, "/", "/api/v1/web" + "/" + var.namespace)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the /api/v1/web/${namespace} prefix for OpenWhisk – Universal Runtime does not need it.

@@ -1761,6 +1910,19 @@ sub hlx_bereq {
} else {
set bereq.http.hlx-forwarded-host = req.http.X-Orig-Host;
}
} elsif (req.backend == F_UniversalRuntime) {
// Set the hostame for the universal Runtime service
set bereq.http.Host = req.http.X-Backend-Host;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the backend hostname set here https://github.com/adobe/helix-publish/pull/704/files#diff-9e59debf5608a9bdb1f1a87b891b2f995823ea79254a122b8d1fcb2bb1f69785R567 (for instance)

As *.anywhere.run will always go to Fastly, setting the subdomain name here allows Fastly to pick the correct gateway service.

@trieloff trieloff merged commit 988aca5 into main Feb 2, 2021
@trieloff trieloff deleted the universal-runtime branch February 2, 2021 09:02
@adobe-bot
Copy link
Contributor

🎉 This PR is included in version 8.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants