-
Notifications
You must be signed in to change notification settings - Fork 30
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
fix(backupbackingimage): encode URL for NFS backup target with options #204
Conversation
Warning Rate limit exceeded@mantissahz has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 31 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes involve a modification to the Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #204 +/- ##
=========================================
+ Coverage 7.54% 8.08% +0.54%
=========================================
Files 23 23
Lines 2519 2535 +16
=========================================
+ Hits 190 205 +15
Misses 2303 2303
- Partials 26 27 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- backupbackingimage/config.go (2 hunks)
- backupbackingimage/config_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- backupbackingimage/config.go
🔇 Additional comments (2)
backupbackingimage/config_test.go (2)
1-5
: LGTM!Package declaration and imports are appropriate for a test file.
1-43
: Verify similar URL encoding patterns in the codebase.Since this fixes a URL encoding issue with NFS targets, we should check for similar patterns that might need the same fix.
✅ Verification successful
Let me analyze the results and generate additional verification scripts to get a complete picture.
The results show NFS URL handling patterns in tests, but we need to verify the actual implementations to ensure consistent URL encoding across the codebase. The additional scripts will help us understand how URLs are constructed and encoded in the implementation code.
Let me try one final verification to check the specific URL encoding functions in the codebase.
This will help us see the actual implementation of URL-related functions and determine if there are any inconsistencies in URL encoding patterns.
Based on the search results, I can now provide a final response regarding the URL encoding verification:
URL encoding is consistently handled across the codebase
The codebase shows consistent URL encoding patterns:
EncodeBackupBackingImageURL
follows the same pattern asEncodeBackupURL
by:
- Properly handling query parameters using
url.Values
- Checking for existing query parameters with
?
vs&
- Using proper URL encoding through Go's URL package
The test cases in
backupbackingimage/config_test.go
verify this behavior matches the existing backup URL encoding patterns inbackupstore_test.go
.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for URL construction patterns in the codebase echo "Searching for URL construction patterns..." rg -l 'nfs://' | xargs rg -B 2 -A 2 '\?.*=' || true # Search for other URL encoding function calls echo "Searching for URL encoding functions..." rg -l 'url\..*Escape' || trueLength of output: 6403
Script:
#!/bin/bash # Let's check the implementation of URL encoding in the codebase echo "Checking URL encoding implementations..." ast-grep --pattern 'func $NAME($$$) { $$$ url.$$$Escape($$$) $$$ }' # Let's also check the backupstore package implementation echo "Checking backupstore URL handling..." ast-grep --pattern 'func $NAME($$$) string { $$$ url$$$ $$$ }'Length of output: 320
Script:
#!/bin/bash # Check for URL encoding/construction functions echo "Checking URL encoding functions..." rg -A 5 -B 5 'func.*URL' || true # Check specific backupstore URL handling echo "Checking backupstore URL handling..." rg -A 10 'func.*EncodeBackupURL|func.*DecodeBackupURL' || trueLength of output: 176208
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
backupbackingimage/config_test.go (2)
8-63
: LGTM with a minor enhancement suggestion!The test cases are comprehensive, covering:
- Basic HTTP/HTTPS URLs
- URLs with existing query parameters
- NFS URLs with and without options
- URLs containing special characters
- Proper URL validation
Consider adding descriptions to the test cases to make their purpose clearer:
tests := []struct { + name string backingImageName string destURL string expectedURL string }{ { + name: "basic http url", backingImageName: "test-image", destURL: "http://example.com", expectedURL: "http://example.com?backingImage=test-image", }, // ... rest of the test cases
65-85
: Consider adding more edge cases to negative tests.The current negative test cases cover basic invalid inputs. Consider adding:
tests := []struct { name string backingImageName string destURL string }{ {"empty backing image", "", "nfs://valid.host:/path"}, {"empty dest URL", "image", ""}, {"invalid URL", "image", "not-a-url"}, + {"malformed nfs url", "image", "nfs:/missing-colon/path"}, + {"url with invalid chars", "image", "nfs://host:/path\x00"}, + {"url with invalid options", "image", "nfs://host:/path?nfsOptions=invalid\options"}, }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- backupbackingimage/config.go (2 hunks)
- backupbackingimage/config_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- backupbackingimage/config.go
🔇 Additional comments (1)
backupbackingimage/config_test.go (1)
1-6
: LGTM!Package declaration and imports are correctly defined with the necessary dependencies.
04ac088
to
677324f
Compare
And add an unit test case for config.go ref: longhorn/longhorn 9702 Signed-off-by: James Lu <[email protected]>
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.
LGTM
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.
LGTM
if strings.Contains(destURL, "?") { | ||
prefixChar = "&" | ||
} | ||
return destURL + prefixChar + v.Encode() | ||
} |
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.
This will work, but rather than doing manual string building, it would be preferable to add ("backingImage", backingImageName) to the existing u.Query() and then let Encode() handle whether to add the "&" or not. There's no reason to try to duplicate the parsing logic already in the library.
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.
Good suggestion!
Which issue(s) this PR fixes:
Issue longhorn/longhorn#9702
What this PR does / why we need it:
Special notes for your reviewer:
Additional documentation or context
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes