Skip to content

Conversation

inlined
Copy link
Member

@inlined inlined commented Jun 18, 2025

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):

  1. The Eventarc source is not converting function IDs to service IDs (which can use a utility function where there is a TODO in the runv2 code)
  2. The billing calculator was created when GCFv2 had a different SKU and that's no longer the case. But the billing change will also go out, so we need to figure out which way to fix it.

@taeold
Copy link
Contributor

taeold commented Jul 2, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
// BUG BUG BUG. This has happened and we need to fix it.
// TODO: Implement function ID to service ID conversion

Copy link
Member Author

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),
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
cpu: String((endpoint.cpu as Number) || 1),
cpu: String((endpoint.cpu as number) ?? 1),

Copy link
Member Author

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.

Comment on lines +363 to +365
// 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.");
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
// 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.");

Copy link
Member Author

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
Comment on lines 262 to 272
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";
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member Author

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.

@inlined inlined force-pushed the inlined.run-functions-exp branch from 15e40f2 to 6ce821e Compare July 30, 2025 21:59
@inlined
Copy link
Member Author

inlined commented Jul 30, 2025

/gemini review

Copy link
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@inlined
Copy link
Member Author

inlined commented Aug 1, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@@ -300,7 +300,7 @@
serviceAccount?: string | null;
}

export type FunctionsPlatform = "gcfv1" | "gcfv2";
export type FunctionsPlatform = "gcfv1" | "gcfv2" | "run";
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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),
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
cpu: String((endpoint.cpu as Number) || 1),
cpu: String(endpoint.cpu || 1),

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 69.78417% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.16%. Comparing base (ecbbc91) to head (c5bbba5).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
src/gcp/runv2.ts 82.02% 10 Missing and 6 partials ⚠️
src/deploy/functions/release/fabricator.ts 14.28% 9 Missing and 3 partials ⚠️
src/deploy/functions/functionsDeployHelper.ts 16.66% 5 Missing ⚠️
src/deploy/functions/backend.ts 33.33% 1 Missing and 1 partial ⚠️
src/functions/secrets.ts 0.00% 2 Missing ⚠️
src/gcp/k8s.ts 83.33% 1 Missing and 1 partial ⚠️
src/deploy/functions/ensure.ts 0.00% 1 Missing ⚠️
src/deploy/functions/prepare.ts 0.00% 1 Missing ⚠️
src/gcp/cloudscheduler.ts 0.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@inlined inlined merged commit fd963fc into master Aug 15, 2025
48 checks passed
@inlined inlined deleted the inlined.run-functions-exp branch August 15, 2025 01:03
@github-project-automation github-project-automation bot moved this from Approved [PR] to Done in [Cloud] Extensions + Functions Aug 15, 2025
schnecle pushed a commit that referenced this pull request Aug 15, 2025
* 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
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