Skip to content

Support callable functions in cloud run zip deploy#10125

Open
brittanycho wants to merge 1 commit intomainfrom
zip-deploy-callable-implementation
Open

Support callable functions in cloud run zip deploy#10125
brittanycho wants to merge 1 commit intomainfrom
zip-deploy-callable-implementation

Conversation

@brittanycho
Copy link
Contributor

Support callable functions in cloud run zip deploy

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Callable Cloud Run Function Support: Implemented the necessary logic to support callable functions when deploying to Cloud Run, including reserving a callable URL.
  • New reserveCallableUrl Method: Introduced a new reserveCallableUrl method in the Fabricator class to create a placeholder GCFv2 function, thereby reserving the callable URL for Cloud Run functions.
  • Error Handling for URL Reservation: Added specific error handling for the reserveCallableUrl method to ignore ALREADY_EXISTS (409) errors, allowing for idempotent URL reservation, while rethrowing other errors.
  • Expanded Test Coverage: Added new unit tests to verify the correct creation of Cloud Run functions and the proper reservation of callable URLs, including scenarios for error handling.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 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.

Comment on lines +213 to +218
apiFunction.buildConfig.source = {
storageSource: {
bucket: HELLO_WORLD_GCS_URL.split("/")[2],
object: HELLO_WORLD_GCS_URL.split("/").slice(3).join("/"),
},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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));
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 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
  1. The style guide prohibits using any as an escape hatch and recommends defining proper types or interfaces instead. (link)

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.

2 participants