-
Notifications
You must be signed in to change notification settings - Fork 115
Conversation
Remove the `{grpc,rest,supervisor}Host` arguments and replace with `host` and `bindHost`. The `host` argument is the hostname at which the GCF emulator can be reached by clients, while the `bindHost` is the address to which the emulator will bind its listener(s). This allows the emulator to be running on a different host from the client, and supports running the emulator behind a NAT (for example when running as a docker container).
The `service` argument is currently documented in the wiki..
Always use localhost when calling back into the Supervisor.
Great work! 👍
I think I was imagining a use case where one might want to scale the supervisor portion of the Emulator horizontally in a sort of dev environment setup (think multiple devs talking to the same Emulator instance). Probably just premature optimization.
The local archive may or may not go away in the future, so I don't think that issue is a big deal.
Would you mind posting some output on what's failing? In any case, I will clone your PR and run the tests myself. It would probably be good in another PR for me to make the |
Upon further testing, it turns out the emulator does require filesystem access to the zip archive at deployment-time. If it does not, this error appears in the log:
I'm able to work around this in my environment using filesystem sharing between my laptop and the VM running docker. I suppose one could work around this limitation by using a GCS bucket for staging as well... I'm not sure if the local-filesystem requirement is a deal-breaker for this feature, but if you elect to reject this PR for this reason, I understand :) |
Here's a recent test run: https://gist.github.com/kpruden/13b3751e2c70c25fad43084e8e89a3b0 The The other failure is representative of the failures I'm seeing, but the individual failures are not reliable - different tests fail each time... |
Pull your branch and try it now. |
Do the tests pass for you now after my changes were merged into your branch? |
Yes, all the tests pass now, thanks! There is some noisy output however: https://gist.github.com/kpruden/e73d8bec52d7c698247b9e285caa1a57 Do you have any thoughts about my previous comment about filesystem access ? |
Ah I missed that comment, I'll take a look. |
Regarding the filesystem access issue, can you further describe what broke? Were you unable to the deploy the function? Unable to call the function? Unable to delete the function? etc. |
Okay, I think I see what the issue is.
There's simply no way around this, the worker has to be able to load the function source code from somewhere. The production Cloud Functions works because when you deploy you provide Luckily, I built Before I posted this comment, I tested the Emulator's |
This PR is unblocked, you can rebase against master and resolve conflicts. Or if you want me to do, check the "allow edits from maintainers" box |
Your explanation makes sense. I'm not using I'm merged master locally and I'm resolving conflicts. I'll push an update shortly.. |
I think I may have found another flaky test:
A second test run passed, so it may have been a hiccup on my machine 🤷♂️ |
@@ -614,7 +614,7 @@ class Functions { | |||
} | |||
|
|||
getSupervisorHost () { | |||
return `http://${this.config.supervisorHost}:${this.config.supervisorPort}`; | |||
return `http://localhost:${this.config.supervisorPort}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why localhost
and not ${this.config.host}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used by code that runs inside the emulator service to talk to itself (lines 392 and 538 - createFunction
and deleteFunction
). Neither host
nor bindHost
are guaranteed to be routable from the emulator process. For example, bindHost
could be 0.0.0.0
and host
could be the IP of the other side of the NAT (the docker host for example).
I forgot about this detail in my original PR description, but this effectively eliminates the possibility of the three services (rest, grpc, supervisor) from running on different hosts. Since the consolidation of the {grpc,rest,supervisor}Host
arguments already has this effect, I think this is OK..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thanks for clarifying.
src/cli/commands/config/index.js
Outdated
@@ -37,24 +37,18 @@ const EPILOGUE = `Available configuration options: | |||
${OPTIONS.timeout.description} | |||
|
|||
${'EMULATOR'.underline} - Emulates the Cloud Functions API. | |||
${'grpcHost'.bold} | |||
${OPTIONS.grpcHost.description} | |||
|
|||
${'grpcPort'.bold} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a bindHost
entry is missing from this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, you're right. I'll add it..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I'm now wondering if there should be some kind of migration. The |
I just pulled down the latest master and ran |
I thought about that, and mentioned it in the original PR description (it's one point in a long description so I understand if you missed it). Given that this is pre-release software I'm not sure what the stance is on backwards compatibility/migration, so I left this out of the original PR. If you think this is important, I can probably get something submitted tomorrow. I agree that the failure mode in this case is not obvious, so it's probably worth doing... |
I added some migration in 904fc36 |
Cool. I took a stab at it myself and came up with a similar fix, but there's a problem - since these options have defaults ( I put up a PR that addresses this. |
Fixes #91
Remove the
{grpc,rest,supervisor}Host
arguments and replace withhost
andbindHost
. Thehost
argument is the hostname at which theGCF emulator can be reached by clients, while the
bindHost
is theaddress to which the emulator will bind its listener(s). This allows
the emulator to be running on a different host from the client, and
supports running the emulator behind a NAT (for example when running
as a docker container).
npm test
succeeds (see below)Some questions/comments for reviewers:
host
argument. It's not clear to me why supporting separate values for each of these would be useful, but if there's a use case I'm not aware of I can work them back in.{grpc,rest,supervisor}Host
, but since this is still pre-release software this didn't seem that critical.delete
assumes the filesystem location of the zip archive is accessible to the emulator process (it attempts to delete it). This obviously fails when the function was deployed by a client running on a different host, but the only negative effect I can see is a log message (and the file not actually getting deleted). Since the zip archive is located in a temporary folder, this doesn't seem to be a big deal to me, but if this is important I can rework the delete command so the unlink happens in the client process.rest-sdk/deploy
suite, which if I understand correctly is testing pointing thegcloud
tool at the emulator. The failures themselves are unreliable - different specific tests fail on each run - which leads me to suspect there's a timing issue or perhaps a subtle compatibility issue with my version ofgcloud
(I'm running 153.0.0). As such, I can't be 100% my changes don't introduce a regression, but I don't think they do. I can include details of the failures in a subsequent comment if desired.