-
Notifications
You must be signed in to change notification settings - Fork 337
[dev] Use preview namespace for regular workers #1032
Comments
The option to duplicate data into a new namespace would be great! It would be really useful to let developers spawn a development environment from production without needing to @cloudflare/kv-worker-migrate. |
the reason we can do this for sites is that we control the title of the namespace; one mistake i think we made with KV was to use ID instead of Title in the wrangler.toml; Titles are unique per account and therefore would have been better. This particular point would work great if we remedied that by taking a
probably couldn't hurt? tangent: what if
this is complex and difficult for a few reasons. providing tools for users to do this i think could be valuable but doing so automatically might be overkill.
this seems good, given the same constraints as my response to point 1
depending on our concerns around churn, we could simply delete preview namespaces when the process is killed; this would be simplest but slowest. making the options around this configurable might be valuable. |
unfortunately this has some major backwards incompatibility issues - today we take id and binding and don't allow inheritance from top level.
probably would be reasonable addition but would need some way to know if preview session currently exists
this is an interesting thought, and one that we had discussed in the original environments proposal - dont think it's a good idea here though given backwards compatibility issues and also i'd assume you'd want to use wrangler dev across multiple environments
i think you're right and probably not necessary for mvp
probably makes sense just to delete entirely. The biggest concern I have here is backwards compatibility - changing the way we configure kv namespaces in the pursuit of wrangler dev feels... icky. Perhaps what we can do is
I think
|
agreed; this might be a thing to stuff into a 2.0 milestone, which we may want to consider compiling. the sequence you have is pretty good; it does rely on a clean up step and that really leaves room for odd state problems (what do you do if the preview namespace still exists?) i think it is worth exploring the use of kv prefixing for this... |
ok so - when a preview session is started with an environment that contains kv-namespaces, we will
|
I've updated the top level comment to reflect the current state of the discussion. |
Good feedback/question from @koeninger: "What do I do if I want to preview my production KV namespace?" |
could we add an optional
playing devil's advocate against my own idea, this could make it look like if you don't add this field we'll use the namespace specified by |
ok - i've kinda dropped the ball on actually starting implementation on this one/nailing down exact design. @ashleymichal I really like the idea of being explicit here and adding the idea of a preview namespace to i think to start out with, we should just flat out refuse to preview if there is not a preview namespace specified for the environment they're using and make them handle the creation/deletion themselves. this makes it so we are not in charge of provisioning namespaces or causing a bunch of churn/inflating their KV billing. the environment variable config could be added after the fact to add more explicit support for multiple developers, but at first we could just recommend a new environment for each dev. question becomes - should we also extend the |
@EverlastingBugstopper this seems like a good call. we can keep our eyes out for optimizations and convenience features, but for solving the biggest problem this seems good. |
For Workers Sites, we create a separate preview KV namespace so that we do not impact production namespaces. We do not do this for regular workers and I believe we should.
In order for folks using
wrangler dev
orwrangler preview
to safely interact with KV namespaces that are not automatically provisioned Workers Sites namespaces, we need to provide some sort of preview namespace.The most straightforward option here that requires no changes to the Workers API is to do exactly what we already do for Workers Sites: provision a new KV namespace automatically for preview sessions. I've laid out the technical approach for this here.
This solves the immediate goal of stopping impact to production namespaces, but it is not a perfect solution.
Drawbacks
The alternative to my proposed solution is to create a higher-level implementation of preview namespaces.
The best way to do this in my opinion would be to create a true local development environment that allows KV to be mocked and interacted with locally on the developer's machine.
Since this is likely out of the question, the other alternative would be to create a first class idea of preview namespaces with the Workers KV API. This would mean each user (not each account) gets 1 preview namespace per production namespace (hopefully for free). They would be able to interact with those namespaces in the same way that they would with production namespaces. Likely would want to add a
--preview
flag to allwrangler kv:namespace
commands, and when uploading preview workers, the config API would be in charge of replacing the uploaded KV namespace information with a preview namespace. I would guess that a full implementation would also require preview namespaces to be observable in the dashboard to provide a 1:1 developer experience.My recommendation is to start with the first approach since it is already possible with the API today, and since we already follow that approach for Workers Sites. This will allow us to quickly provide a significant improvement over the current development story, and keep folks from screwing up their production data.
The text was updated successfully, but these errors were encountered: