Skip to content

chore(tools/alloydb,tools/alloydbainl): decouple source config from tool#2059

Merged
Yuan325 merged 3 commits into
config-branchfrom
config-alloydb
Dec 13, 2025
Merged

chore(tools/alloydb,tools/alloydbainl): decouple source config from tool#2059
Yuan325 merged 3 commits into
config-branchfrom
config-alloydb

Conversation

@Yuan325

@Yuan325 Yuan325 commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Description

Decouple source config from tools.

PR Checklist

Thank you for opening a Pull Request! Before submitting your PR, there are a
few things you can do to make sure it goes smoothly:

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Yuan325, 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 significantly refactors the AlloyDB tools and the AlloyDB AI NL tool by introducing interface-based programming. The primary goal is to reduce tight coupling between tools and their underlying data sources, making the system more flexible, maintainable, and easier to extend. By relying on interfaces, tools can now interact with any source that provides the necessary functionalities, abstracting away implementation details.

Highlights

  • Decoupling Source Configuration: The core change involves decoupling the specific source configuration from the tools that utilize them. This enhances modularity and allows tools to work with any source implementing the required interfaces.
  • Introduction of compatibleSource Interfaces: New interfaces, compatibleSource, have been introduced in various AlloyDB tools to define the expected methods from a source (e.g., DefaultProject, UseClientAuthorization, GetService, PostgresPool). Tools now rely on these interfaces rather than concrete source types.
  • Dynamic Source Retrieval: Tools no longer store a direct reference to their source. Instead, they dynamically retrieve the source via resourceMgr.GetSource() during initialization and invocation, ensuring a more flexible and less coupled architecture.
  • Refactored DefaultProject Access: In alloydbadmin.go, the DefaultProject field was made unexported (defaultProject), and a public DefaultProject() method was added to the Source struct, providing controlled access to this configuration.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 effectively decouples the AlloyDB tools from the concrete alloydbadmin source implementation by introducing a compatibleSource interface. This is a great improvement for maintainability and extensibility. The changes are consistent across all the affected tools. My main feedback is to address the code duplication for retrieving and validating the source in the Invoke and RequiresClientAuthorization methods across multiple tool files. Extracting this logic into a shared helper method would further improve the code quality.

Comment thread internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster.go
Comment thread internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser.go
Comment thread internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster.go
Comment thread internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance.go
Comment thread internal/tools/alloydb/alloydbgetuser/alloydbgetuser.go
Comment thread internal/tools/alloydb/alloydblistclusters/alloydblistclusters.go
Comment thread internal/tools/alloydb/alloydblistinstances/alloydblistinstances.go
Comment thread internal/tools/alloydb/alloydblistusers/alloydblistusers.go
@averikitsch averikitsch assigned averikitsch and unassigned duwenxin99 Dec 1, 2025
Base automatically changed from config-server to config-branch December 9, 2025 01:36
@Yuan325 Yuan325 requested review from a team December 9, 2025 01:36
return false, fmt.Errorf("unable to retrieve source %s in tool %s", t.Source, t.Name)
}

source, ok := s.(compatibleSource)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we checking compatibility in this method for all tools?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

@Yuan325 Yuan325 merged commit 26ac3c4 into config-branch Dec 13, 2025
6 of 11 checks passed
@Yuan325 Yuan325 deleted the config-alloydb branch December 13, 2025 03:39
Yuan325 added a commit that referenced this pull request Dec 17, 2025
…ool (#2059)

## Description

Decouple source config from tools.

## PR Checklist

> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:

- [ ] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
Yuan325 added a commit that referenced this pull request Dec 18, 2025
…ool (#2059)

## Description

Decouple source config from tools.

## PR Checklist

> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:

- [ ] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
Yuan325 added a commit that referenced this pull request Dec 19, 2025
…ool (#2059)

## Description

Decouple source config from tools.

## PR Checklist

> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:

- [ ] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
Yuan325 added a commit that referenced this pull request Dec 19, 2025
…ool (#2059)

## Description

Decouple source config from tools.

## PR Checklist

> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:

- [ ] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
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