-
Notifications
You must be signed in to change notification settings - Fork 16
Fix listener config migration #148
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
Conversation
WalkthroughThe migration logic for updating listener-related config fields in Fiber applications was refactored. Instead of simple string replacements, the migration now uses regex to extract, rename, and relocate certain fields into a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Suggested labels
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧰 Additional context used🧠 Learnings (3)📓 Common learningscmd/internal/migrations/v3/common.go (1)Learnt from: ReneWerner87 cmd/internal/migrations/v3/common_test.go (4)Learnt from: ReneWerner87 Learnt from: norri Learnt from: norri Learnt from: norri ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (6)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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 @ReneWerner87, 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!
I've implemented a fix for the listener configuration migration. This change moves several listener-related fields from fiber.Config to fiber.ListenConfig to align with updated API structures, ensuring that existing configurations are correctly migrated.
Highlights
- Configuration Migration Logic: The MigrateConfigListenerFields function has been updated to identify and extract Prefork, Network, DisableStartupMessage, and EnablePrintRoutes fields from fiber.Config.
- Dynamic ListenConfig Injection: The migration now intelligently injects these extracted fields into a new fiber.ListenConfig instance if app.Listen() is called without an explicit ListenConfig struct, ensuring backward compatibility.
- Field Renaming during Migration: During the migration, Prefork is renamed to EnablePrefork and Network is renamed to ListenerNetwork to match the new fiber.ListenConfig field names.
- Test Coverage Enhancement: The migration tests have been updated to include the newly moved fields (DisableStartupMessage, EnablePrintRoutes) and verify that the fiber.ListenConfig is correctly formed after migration.
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 or fill out our survey to provide feedback.
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
-
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 updates the migration logic for listener configuration fields that were moved from fiber.Config to fiber.ListenConfig. My review focuses on the correctness and robustness of the migration script. I've identified a potential issue in the migration logic where it doesn't handle all app.Listen call variations, which could lead to configuration loss. I've also suggested improvements to the test suite to cover more edge cases and ensure the migration is reliable.
| // inject ListenConfig with the moved fields if Listen is used without config | ||
| reListen := regexp.MustCompile(`\.Listen\(([^,\n]+)\)`) | ||
| content = reListen.ReplaceAllStringFunc(content, func(m string) string { | ||
| if strings.Contains(m, "ListenConfig{") { | ||
| return m | ||
| } | ||
| addr := reListen.FindStringSubmatch(m)[1] | ||
| return fmt.Sprintf(".Listen(%s, fiber.ListenConfig{%s})", addr, strings.Join(moved, ", ")) | ||
| }) | ||
|
|
||
| return content |
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.
The logic for injecting the moved listener configuration fields is incomplete. It only handles app.Listen calls with a single argument and does not modify calls that already include a fiber.ListenConfig. This can lead to an incorrect migration where configuration is lost if a ListenConfig is already present.
To make the migration more robust, it should handle both cases: adding a new ListenConfig and injecting fields into an existing one.
// inject ListenConfig with the moved fields
newFieldsStr := strings.Join(moved, ", ")
// First, try to inject into an existing ListenConfig.
reListenWithCfg := regexp.MustCompile(`(\.Listen\([^,]+,\s*fiber\.ListenConfig{)([^}]*)(\})`)
content = reListenWithCfg.ReplaceAllStringFunc(content, func(m string) string {
sub := reListenWithCfg.FindStringSubmatch(m)
prefix, existing, suffix := sub[1], strings.TrimSpace(sub[2]), sub[3]
if existing != "" && !strings.HasSuffix(existing, ",") {
existing += ","
}
return fmt.Sprintf("%s%s %s%s", prefix, existing, newFieldsStr, suffix)
})
// Then, handle cases without an existing ListenConfig.
reListenSimple := regexp.MustCompile(`(\.Listen\()([^,)]+)(\))`) // It specifically looks for Listen calls with only one argument.
content = reListenSimple.ReplaceAllString(content, fmt.Sprintf(`${1}${2}, fiber.ListenConfig{%s}${3}`, newFieldsStr))
return content| require.NoError(t, v3.MigrateConfigListenerFields(cmd, dir, nil, nil)) | ||
|
|
||
| content := readFile(t, file) | ||
| assert.Contains(t, content, "EnablePrefork: true") | ||
| assert.Contains(t, content, "ListenerNetwork: \"tcp\"") | ||
| assert.Contains(t, content, "fiber.ListenConfig{EnablePrefork: true, ListenerNetwork: \"tcp\", DisableStartupMessage: true, EnablePrintRoutes: true}") | ||
| assert.Contains(t, buf.String(), "Migrating listener related config fields") | ||
| } |
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.
The test coverage for MigrateConfigListenerFields could be improved. The current test only covers the scenario where app.Listen is called with a single argument. To ensure the migration is robust, consider adding test cases for other scenarios, such as:
app.Listenis called with an existing, emptyfiber.ListenConfig{}.app.Listenis called with an existingfiber.ListenConfigcontaining other options.- No
app.Listencall is present in the code, to verify how the moved fields are handled (or if configuration loss is an acceptable trade-off).
Adding these tests would help prevent regressions and ensure the migration handles more edge cases correctly.
Summary
fiber.Configtofiber.ListenConfigTesting
go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 -shuffle=ongo run github.com/golangci/golangci-lint/cmd/[email protected] run ./...(fails: can't load config - Go 1.23 vs. 1.24)https://chatgpt.com/codex/tasks/task_e_6888ca5c6558832686a65efdaf1d37de
Summary by CodeRabbit
Bug Fixes
Tests