Skip to content

Conversation

harmony7
Copy link
Member

@harmony7 harmony7 commented Jul 19, 2025

This PR adds code to the CLI to enable fastly compute serve with "enable Pushpin", a new mode that locates and runs Pushpin before starting Viceroy to run guest code.

This is a companion PR to fastly/Viceroy#497, and will only function after that feature has landed.

How to enable it:

It can be invoked in one of two ways:

  1. set a new flag --experimental-enable-pushpin
  2. or, set a new flag in fastly.toml:
[local_server.pushpin]
enable = true

What it does:

  • fastly compute serve starts Pushpin before starting Viceroy, and detects its startup. It also sets up to shut it down when the CLI process ends.

    • pushpin must be started at this time, because routes are set based on the backends defined in the fastly.toml manifest file.
    • "kill process" is done differently between Windows and Unix, so build flags are used to include the right implementation of killProcess.
  • Pushpin routes are set up based on the fastly.toml manifest file.

    • A route is set up per backend.
    • The name of each backend is set as an id= condition. For example, a backend named origin will set id=origin. Viceroy handles Fanout handoff by forwarding a request for this backend to Pushpin and set the header Pushpin-Route: origin, allowing Pushpin to match the route.
    • If the backend definition's URL has a path segment, then it is set as a replace_beg configuration on the route. For example, if a backend is configured for http://localhost:3000/realtime, then this is set as replace_beg=realtime. Pushpin will forward a request for /api/user to this backend as http://localhost:3000/realtime/api/user.
    • over_http is set for every route target, as to always enable WebSocket-over-HTTP.
    • If the backend URL is HTTPS, then ssl is added.
    • If the backend definition sets override_host, then it will be set as the host value of the route target.
  • When starting Viceroy, --local-pushpin-proxy-port=<port> is appended as a command-line argument, which starts Viceroy in "enable Pushpin" mode.

  • Pushpin proxy runs by default on port 7677, but this can be overridden:

    • using proxy_port=<port> under local_server.pushpin section of the fastly.toml file, or
    • using --pushpin-proxy-port=<port>
  • Pushpin's publishing endpoint runs by default on port 5561, but this can be overridden:

    • using publish_port=<port> under local_server.pushpin section of the fastly.toml file, or
    • using --pushpin-publish-port=<port>
  • The pushpin binary is searched on the system path, but can be specified:

    • using pushpin_path=/path/to/pushpin under the local_server.pushpin section of the fastly.toml file, or
    • using --pushpin-path=/path/to/pushpin.
  • The CLI writes the config and routes to temporary files in the OS temporary directory. This is cleaned up as part of shutdown.

  • Pushpin runner places some runtime files into a temporary directory specified in pushpin.conf. We set this to an OS temporary directory, so that multiple instances can run if necessary. This is cleaned up as part of shutdown.

  • Pushpin runner places logs into a directory specified in pushpin.conf. This is placed in the ./pushpin-logs directory under the current project

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  • Does your submission pass tests?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

User Impact

  • What is the user impact of this change?

Are there any considerations that need to be addressed for release?

The new feature is opt-in using the --experimental-enable-pushpin flag, and does nothing if the new flag is not set.

@harmony7 harmony7 requested a review from a team as a code owner July 19, 2025 14:16
@harmony7 harmony7 marked this pull request as draft July 19, 2025 19:19
@harmony7 harmony7 marked this pull request as ready for review July 22, 2025 10:21
@harmony7 harmony7 force-pushed the kats/proxy-pushpin branch 2 times, most recently from c3b10ef to e7d0a14 Compare July 23, 2025 04:04
@harmony7 harmony7 marked this pull request as draft July 23, 2025 22:30
@harmony7
Copy link
Member Author

Reverting to draft, as I am going to add another feature.

@harmony7 harmony7 force-pushed the kats/proxy-pushpin branch 4 times, most recently from 624e65c to d09de5d Compare July 25, 2025 05:29
@harmony7
Copy link
Member Author

This is ready for review.

@harmony7 harmony7 marked this pull request as ready for review July 25, 2025 06:07
@harmony7 harmony7 force-pushed the kats/proxy-pushpin branch from d09de5d to fe11084 Compare July 25, 2025 06:09
Copy link
Contributor

@anthony-gomez-fastly anthony-gomez-fastly left a comment

Choose a reason for hiding this comment

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

LGTM

@harmony7 harmony7 force-pushed the kats/proxy-pushpin branch from 4a2b70a to b0a0f73 Compare August 1, 2025 18:15
@harmony7
Copy link
Member Author

harmony7 commented Aug 1, 2025

I've added the following updates to the way this works:

We write a routes file to disk to the OS temporary directory, and reference it from a fresh copy of the pushpin.conf file (which I've copied out from the Pushpin repo and made some modifications to), also written to the temporary directory.
This conf file is configured with the publish and proxy ports, as well as a temporary directory for the runtime files, and settings logs output to pushpin-logs under the compute directory.

@harmony7 harmony7 force-pushed the kats/proxy-pushpin branch from 405c87b to 6cab8c0 Compare August 5, 2025 06:50
@harmony7 harmony7 requested a review from kpfleming August 6, 2025 15:47
@harmony7
Copy link
Member Author

harmony7 commented Aug 6, 2025

@kpfleming thanks for the review! I've made fixes, please re-review =)

@harmony7 harmony7 force-pushed the kats/proxy-pushpin branch from b0d6946 to 2847f25 Compare August 6, 2025 16:08
@harmony7 harmony7 force-pushed the kats/proxy-pushpin branch from 2847f25 to aff91b3 Compare August 6, 2025 16:11
@harmony7 harmony7 merged commit f6bb91f into main Aug 6, 2025
12 checks passed
@harmony7 harmony7 deleted the kats/proxy-pushpin branch August 6, 2025 22:06
kpfleming added a commit that referenced this pull request Aug 18, 2025
kpfleming added a commit that referenced this pull request Aug 18, 2025
Format correction for this entry.
kpfleming pushed a commit that referenced this pull request Aug 19, 2025
This PR is a followup to #1509 that includes the following fixes:

* Fix to Pushpin context that inadvertently left out the path to the
routes file and the cleanup function when building the context
* Adds an output message indicating when "Experimental Pushpin mode" is
enable
* Makes Pushpin-related logs slightly less noisy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants