Support callable functions in cloud run zip deploy#10125
Support callable functions in cloud run zip deploy#10125brittanycho wants to merge 1 commit intomainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the deployment process to support callable functions on Cloud Run. It introduces a mechanism to reserve a unique URL for these functions by creating a temporary placeholder function, ensuring that the callable endpoint is available before the actual function deployment. This change is crucial for enabling a consistent and reliable deployment experience for callable Cloud Run functions. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for callable functions when deploying to Cloud Run. The core change involves a new reserveCallableUrl method in the Fabricator class, which pre-creates a temporary GCFv2 function to reserve the URL for a callable function before the actual Cloud Run service is deployed. The changes are well-tested. I have a couple of suggestions to improve code robustness and type safety.
| apiFunction.buildConfig.source = { | ||
| storageSource: { | ||
| bucket: HELLO_WORLD_GCS_URL.split("/")[2], | ||
| object: HELLO_WORLD_GCS_URL.split("/").slice(3).join("/"), | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Parsing the GCS bucket and object from the HELLO_WORLD_GCS_URL string by splitting the path is a bit brittle. If the URL format were to change, this logic could break. Using a regular expression to parse the bucket and object would be more robust.
const gcsUrlMatch = HELLO_WORLD_GCS_URL.match(/^gs:\/\/([^/]+)\/(.*)$/);
if (!gcsUrlMatch) {
// This should not happen with a valid GCS URL.
// Throw an error to prevent deploying with an invalid source.
throw new Error(`Could not parse GCS URL: ${HELLO_WORLD_GCS_URL}`);
}
apiFunction.buildConfig.source = {
storageSource: {
bucket: gcsUrlMatch[1],
object: gcsUrlMatch[2],
},
};| throw err; | ||
| } | ||
| }) | ||
| .catch(rethrowAs(endpoint, "reserve URL" as any)); |
There was a problem hiding this comment.
The type assertion as any is used here because "reserve URL" is not a member of the OperationType union in src/deploy/functions/release/reporter.ts.
To adhere to the style guide and improve type safety, you should add "reserve URL" to the OperationType definition. This will remove the need for the type cast.
References
- The style guide prohibits using
anyas an escape hatch and recommends defining proper types or interfaces instead. (link)
Support callable functions in cloud run zip deploy