-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cloud Run Functions data model #8767
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
Conversation
/gemini review |
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.
Code Review
This pull request extends the data model to support Cloud Run Functions, introducing a new 'run' platform type. The changes include refactoring shared utilities into a new k8s.ts
file and adding a comprehensive runv2.ts
module with tests for interacting with the Cloud Run v2 API.
My review focuses on ensuring consistency and correctness in the new code. I've identified areas for improvement, including an inconsistency in the AllFunctionsPlatforms
array, a potential bug in how CPU values are handled, and critical bugs related to function ID conversion and billing calculations.
// N.B. If GCF starts allowing v1's allowable characters in IDs they're | ||
// going to need to have a transform to create a service ID (which has a | ||
// more restrictive character set). We'll need to reimplement that here. | ||
// BUG BUG BUG. This has happened and we need to fix 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.
This comment indicates a known issue where the function ID to service ID conversion is not happening. It's marked as a BUG BUG BUG
, suggesting it's critical and needs to be addressed.
// BUG BUG BUG. This has happened and we need to fix it. | |
// TODO: Implement function ID to service ID conversion |
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.
IMO the severity of this comment is accurate. This is a WIP and a BUG should be resolved before releasing to the public whereas a TODO can be ignored for years.
src/gcp/runv2.ts
Outdated
], | ||
resources: { | ||
limits: { | ||
cpu: String((endpoint.cpu as Number) || 1), |
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.
Using the logical OR ||
for default values can lead to unexpected behavior if 0
is a valid value for endpoint.cpu
. The nullish coalescing operator ??
is safer as it only provides the default for null
or undefined
values.
cpu: String((endpoint.cpu as Number) || 1), | |
cpu: String((endpoint.cpu as number) ?? 1), |
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.
0 is not a valid value AFAIK, so this shouldn't make a difference.
// This may be tricky because the image has been deleted. How does this work | ||
// with GCF? | ||
throw new FirebaseError("Updating Cloud Run functions is not yet implemented."); |
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 error message is not very informative. Consider adding more context to the error message to help users understand why updating Cloud Run functions is not yet implemented.
// This may be tricky because the image has been deleted. How does this work | |
// with GCF? | |
throw new FirebaseError("Updating Cloud Run functions is not yet implemented."); | |
throw new FirebaseError("Updating secrets for Cloud Run functions is not yet implemented. Please use GCFv2."); |
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.
Bad suggestion
src/gcp/runv2.ts
Outdated
export const RUNTIME_LABEL = "goog-cloudfunctions-runtime"; | ||
export const CLIENT_NAME_LABEL = "goog-managed-by"; | ||
export const CLIENT_NAME_ANNOTATION = "run.googleapis.com/client-name"; | ||
export const CPU_BOOST_ANNOTATION = "run.googleapis.com/startup-cpu-boost"; | ||
export const TRIGGER_TYPE_ANNOTATION = "cloudfunctions.googleapis.com/trigger-type"; | ||
export const FUNCTION_TARGET_ANNOTATION = "run.googleapis.com/build-function-target"; // e.g. '{"worker":"triggerTest"}' | ||
export const FUNCTION_ID_ANNOTATION = "cloudfunctions.googleapis.com/function-id"; // e.g. "triggerTest" | ||
export const BASE_IMAGE_ANNOTATION = "run.googleapis.com/base-images"; // : '{"worker":"us-central1-docker.pkg.dev/serverless-runtimes/google-22-full/runtimes/nodejs22"}' | ||
export const MAX_INSTANCES_ANNOTATION = "autoscaling.knative.dev/maxScale"; | ||
export const MIN_INSTANCES_ANNOTATION = "autoscaling.knative.dev/minScale"; | ||
export const DEFAULT_FUNCTION_CONTAINER_NAME = "worker"; |
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.
In https://cloud.google.com/run/docs/reference/rest/v2/projects.locations.services#Service
Cloud Run API v2 does not support annotations with run.googleapis.com, cloud.googleapis.com, serving.knative.dev, or autoscaling.knative.dev namespaces, and they will be rejected in new resources. All system annotations in v1 now have a corresponding field in v2 Service.
Suspect we'll have to refactor many of these?
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.
Uuuuuugh... I think the Cloud Console uses the V1 API and I need to start using resource explorer. Will go back to the drawing board.
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.
Updated to read from these fields where there is no analog (or the analog is an env var) but write to fields we have access to
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.
fuuuudge. Edited in the wrong branch (IIRC a parent to this one). Sifting through the Git nonsense.
15e40f2
to
6ce821e
Compare
/gemini review |
Warning Gemini encountered an error creating the review. You can try again by commenting |
/gemini review |
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.
Code Review
This pull request introduces the data model for Cloud Run Functions (CRF) by adding a new run
platform type. It extends various parts of the functions deployment logic, including backend definitions, argument types, preparation steps, and pricing calculations, to accommodate this new platform. A significant part of the change is the new runv2.ts
module, which provides the API client and data models for Cloud Run v2, along with conversion functions to and from the internal Endpoint
representation. The changes are well-structured, with new tests for the runv2
module and refactoring of shared utilities. My review found a couple of areas for improvement to ensure consistency and code quality.
src/deploy/functions/backend.ts
Outdated
@@ -300,7 +300,7 @@ | |||
serviceAccount?: string | null; | |||
} | |||
|
|||
export type FunctionsPlatform = "gcfv1" | "gcfv2"; | |||
export type FunctionsPlatform = "gcfv1" | "gcfv2" | "run"; |
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.
While the FunctionsPlatform
type is correctly updated to include run
, the related AllFunctionsPlatforms
constant on the next line is not. This will cause parts of the system that iterate over AllFunctionsPlatforms
(e.g., in release/planner.ts
) to miss Cloud Run functions, which can lead to them not being planned for updates or deletion. Please update AllFunctionsPlatforms
to include run
to be consistent with the type definition.
src/gcp/runv2.ts
Outdated
], | ||
resources: { | ||
limits: { | ||
cpu: String((endpoint.cpu as Number) || 1), |
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.
The type assertion as Number
uses the Number
object wrapper type, which is not idiomatic in TypeScript. It's better to use the primitive type number
. While this works due to auto-unboxing, it can be confusing. Using as number
or even omitting the assertion if the type is already correctly inferred would be cleaner and improve readability.
cpu: String((endpoint.cpu as Number) || 1), | |
cpu: String(endpoint.cpu || 1), |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #8767 +/- ##
==========================================
- Coverage 50.93% 49.16% -1.78%
==========================================
Files 510 670 +160
Lines 33396 38334 +4938
Branches 6934 7644 +710
==========================================
+ Hits 17011 18846 +1835
- Misses 14886 17968 +3082
- Partials 1499 1520 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* Checkpoint * Checkpoint * Run Functions experiment + model changes * Simplify; format * Checkpoint * Checkpoint * Run Functions experiment + model changes * Simplify; format * Checkpoint * Refactor scaling and tool * Fix tests. Somehow unrelated code is failing * Fix tests * Resotore runv2 from reflog * Format fix * PR feedback
Thanks for your patience. I've got part one of 2-3 on getting some PoCs ready for CRF. This just extends the data model to support the RunV2 API (needed for the submit build stuff), the service<->endpoint stuff, and the changes that popped up with assertExhaustive once a new type has been added.
This PR exposed two bugs (not fixed):