fix consul engine bug when calling Set and List#283
fix consul engine bug when calling Set and List#283git-hulk merged 8 commits intoapache:unstablefrom
Conversation
| continue | ||
| } | ||
| key := strings.TrimLeft(string(kv.Key[prefixLen+1]), "/") | ||
| key := strings.TrimLeft(string(kv.Key[prefixLen+1:]), "/") |
There was a problem hiding this comment.
Bug 2 fix. I noticed that this was missing the : which I could find in the etcd and other implementations
| if len(key) > 0 && key[0] == '/' { | ||
| key = strings.TrimPrefix(key, "/") | ||
| } |
There was a problem hiding this comment.
trimming the leading / to avoid the error
https://github.com/hashicorp/consul/blob/main/api/kv.go#L208-L210
|
|
||
| ctx := context.Background() | ||
| keys := []string{"a/b/c0", "a/b/c1", "a/b/c2"} | ||
| keys := []string{"/a/b/c0", "/a/b/c1", "/a/b/c2"} |
There was a problem hiding this comment.
the error really happened because the nsPrefix has a leading /, but I think if we just keep the tests consistent with the other engines and it'll be ok?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #283 +/- ##
============================================
+ Coverage 43.38% 46.34% +2.95%
============================================
Files 37 45 +8
Lines 2971 4296 +1325
============================================
+ Hits 1289 1991 +702
- Misses 1544 2097 +553
- Partials 138 208 +70
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@bseto Great! Thanks for your fix, will have a look soon. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes two critical issues in the Consul engine implementation: ensuring that keys do not start with a leading slash and correcting the key trimming logic in the List function to return complete namespace names.
- Updated Consul configuration to point to the correct Consul agent address.
- Modified engine methods (Get, Exists, Set, Delete, List) to sanitize keys using a new helper function.
- Adjusted tests to provide keys with a leading slash, verifying that key sanitization works as expected.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| config/config-consul.yaml | Updated Consul address to match test setup requirements. |
| store/engine/consul/consul.go | Introduced key sanitization in Consul methods and fixed key slicing in List. |
| store/engine/consul/consul_test.go | Modified test keys to include a leading slash to trigger sanitization. |
This PR fixes two bugs with the Consul Engine Implementation
/./_build/kvctl create namespace test-ns error: Invalid key. Key must not begin with a '/': /kvrocks/metadata/test-nsSetup