-
Notifications
You must be signed in to change notification settings - Fork 985
feat: tag services and environments #10546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: f31edfc The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
b1172e7
to
45c8035
Compare
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.
Hi @1000hz. This doesn't account for redirected configs (as used by the Vite plugin, Nitro and possibly others), which flatten the configuration using the selected environment at build time. See the following:
workers-sdk/packages/wrangler/src/config/validation.ts
Lines 168 to 181 in cc47b51
if (isRedirectedConfig && definedEnvironments.length > 0) { | |
diagnostics.errors.push( | |
dedent` | |
Redirected configurations cannot include environments but the following have been found:\n${definedEnvironments | |
.map((env) => ` - ${env}`) | |
.join("\n")} | |
Such configurations are generated by tools, meaning that one of the tools | |
your application is using is generating the incorrect configuration. | |
Report this issue to the tool's author so that this can be fixed there. | |
` | |
); | |
} |
We propose that an environmentName
property is added to ComputedFields
that is included in the output of readConfig
. Then, for redirected configs (which are configs that have been generated by readConfig
), this value can be used to provide the env
to applyServiceAndEnvironmentTags
. Does that sound OK?
45c8035
to
af14df0
Compare
0f2b7ac
to
cd128b7
Compare
…vironments is deployed or has a new version upload.
cd128b7
to
f31edfc
Compare
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.
Looks good to me! Thanks for doing the extra work to support the redirected config. It would be good to add some tests for that scenario but it's not blocking. I think we probably need a writeRedirectedWranglerConfig
helper equivalent to writeWranglerConfig
to make this more straightforward.
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.
Can you add a test for redirectied config?
@@ -48,6 +50,10 @@ export interface ComputedFields { | |||
* It can be useful to know what the top-level name was before the flattening. | |||
*/ | |||
topLevelName: string | undefined; | |||
/** A list of environment names declared in the raw configuration. */ | |||
definedEnvironments: string[] | undefined; |
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 do we need definedEnvironments
? It looks like it's only used to decide whether or not to apply environment tags, but surely the presence of a target environment is enough to decide that?
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.
target environment alone is not sufficient. we need to apply service tags as long as there are any environments defined in the config file, even when you're targeting the top-level environment (i.e. target environment would be empty).
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.
That makes sense, but to play devils advocate for a second, did you consider just always adding the service name tag, regardless of whether the user has environments in their config?
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.
We potentially could, but there'd be some undesirable implications on other parts of the system that we'd need to handle (i.e. service grouping) and it'd be better to only apply it where necessary for now.
let requestCount = 0; | ||
mockPatchScriptSettings(async ({ request }) => { | ||
requestCount++; | ||
if (requestCount === 2) { |
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 are we sending three requests to this endpoint?
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.
we are sending two. why not bundle setting the tags into the existing request? there's a chance updating the tags will fail if the additional tags push the worker beyond the tag limit, so I didn't want to jeopardize syncing the other script settings.
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.
Is there no way we can exempt these specific tags from the tag limit server side? I'm not going to block on this because we already do this all over the place in Wrangler, but I'd definitely prefer we get closer to 1 API call being a deploy, rather than further away
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.
yeah, now that we're qualifying these tags with a cf:
prefix, we probably should exempt these two specific tags from the limit.
Spoke with @penalosa and decided I'll follow up this PR with another one to add additional test coverage |
This PR adds tagging behavior that applies appropriate service and environment tags to Workers with multiple environments when deploying or uploading a new version. If any environments are detected in the Wrangler config file, running
wrangler deploy
orwrangler version upload
will apply acf:service=${topLevelName}
and (if a--env
was specified) acf:environment=${environmentName}
tag. This metadata will be used by the Cloudflare Dashboard to group these Workers together in a more user-friendly way.This PR also adds a new
definedEnvironments
computed field to Wrangler config that can be used to more easily determine whether a Worker uses environments.