-
Notifications
You must be signed in to change notification settings - Fork 20
chore(core): decompose config loading #2639
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
chore(core): decompose config loading #2639
Conversation
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.
Summary of Changes
Hello @ntrevino-virtru, 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 application's configuration loading system. The primary goal is to decompose the monolithic configuration loading into a more modular and extensible architecture. This is achieved by introducing a new Loader
interface and providing distinct implementations for loading configuration from environment variables, configuration files, and default settings. The main LoadConfig
function now accepts an ordered list of these loaders, allowing for clear precedence and a more robust configuration pipeline. This change improves maintainability and flexibility for future configuration requirements.
Highlights
- Modular Configuration Loading: The core configuration loading logic has been refactored to support a modular, ordered approach. Instead of a single
LoadConfig
function handling all concerns, the system now uses a slice ofLoader
interfaces, allowing different sources (environment variables, config files, default settings) to contribute to the final configuration in a defined precedence. - New Loader Implementations: Three new
Loader
implementations have been introduced:ConfigFileLoader
for file-based configuration,EnvironmentValueLoader
for environment variables, andDefaultSettingsLoader
for built-in default values. This separation of concerns makes the configuration system more extensible and easier to understand. - Updated Core Configuration Function: The
LoadConfig
function inservice/pkg/config/config.go
has been updated to accept a list ofLoader
interfaces. It now orchestrates the loading process, applying defaults and validating the configuration at each step. This change centralizes the loading logic while delegating source-specific details to individual loaders. - Explicit Configuration Loader Ordering: The application's startup process in
service/pkg/server/start.go
now explicitly defines and uses an ordered list of configuration loaders. This ensures that configuration values are applied in a predictable sequence (e.g., environment variables override file settings, which override defaults). - Configuration Tag Naming Consistency: Several
mapstructure
andjson
tags in configuration structs (e.g.,service/internal/auth/config.go
,service/pkg/db/db.go
) have been updated for consistency, primarily changing from snake_case to camelCase for better alignment with Go's idiomatic naming conventions.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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.
Config's old ways gone, New loaders now take their place, Order brings clear path.
Footnotes
-
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. ↩
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 refactors the configuration loading mechanism to be more modular and extensible by introducing a Loader
interface. This is a significant improvement to the configuration management.
However, there are a few critical issues that need to be addressed:
- The config hot-reloading feature appears to be broken by this refactoring.
- There is a bug in
service/pkg/server/start.go
that leads to an incorrect allow-list for environment variables. - Error handling in
cmd
packages now usespanic
instead of returning errors, which is incorrect for the function signatures.
Additionally, this PR introduces breaking changes by renaming configuration keys from snake_case
to camelCase
(e.g., cache_refresh_interval
to cacheRefreshInterval
). This should be clearly documented for users.
I've left detailed comments on these issues and some other suggestions for improving code quality and maintainability.
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
Error Summary
TDF3 Benchmark Results:
Error Summary:
NANOTDF Benchmark Results:
Error Summary:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
Error Summary
TDF3 Benchmark Results:
Error Summary:
NANOTDF Benchmark Results:
Error Summary:
|
…pose-config-loading
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
Error Summary
TDF3 Benchmark Results:
Error Summary:
NANOTDF Benchmark Results:
Error Summary:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
Error Summary
TDF3 Benchmark Results:
Error Summary:
NANOTDF Benchmark Results:
Error Summary:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
579ff36
to
39a64e5
Compare
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
/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 is a significant and well-executed refactoring of the configuration loading mechanism. It decomposes the monolithic config loader into smaller, more specialized loaders for environment variables, config files, and default settings. This greatly improves modularity, flexibility, and testability. The new Reload
logic with its dependency-aware iteration is a clever solution for handling complex configuration scenarios. I've found one bug in the environment variable change detection and an opportunity to reduce code duplication in the cmd
package. Overall, great work on this complex change.
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 refactors the configuration loading mechanism by decomposing it into a system of prioritized loaders. This is a significant improvement for flexibility and maintainability. The changes introduce FileLoader
, EnvironmentValueLoader
, and DefaultSettingsLoader
, which are managed by a new Reload
mechanism in the main Config
object.
My review has identified several areas for improvement:
- There is code duplication in command files for initializing the configuration loaders.
- There are several breaking changes in
mapstructure
andjson
tags for configuration keys, which will impact users with existing configuration files. These should be carefully considered and communicated. - A potential bug was found in the
Watch
implementation for environment variables, where value changes might be missed. - A minor issue with logging severity was also noted.
Overall, this is a solid refactoring, but the breaking changes and the bug in the watch logic need to be addressed.
4fe7dae
to
b4a375d
Compare
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
/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 a significant and well-designed refactoring of the configuration loading mechanism, making it more extensible and robust through the use of loaders. The stabilization loop in the Reload
function to handle inter-loader dependencies is a particularly strong addition. My review includes suggestions to reduce code duplication, improve error handling in a library function, and optimize performance in a few areas.
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
🤖 I have created a release *beep* *boop* --- ## [0.4.0](lib/ocrypto/v0.3.0...lib/ocrypto/v0.4.0) (2025-09-02) ### Features * add AES protected key interface and implementation ([#2599](#2599)) ([2bb7eb0](2bb7eb0)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com>
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
…pose-config-loading
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
7b202a3
to
2b877ae
Compare
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Standard Benchmark Metrics Skipped or FailedBulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
|
Proposed Changes
Checklist
Testing Instructions