kratos
kratos copied to clipboard
fix(config): references between different sources are consistent when watch
Description (what this PR does / why we need it):
Fixed an issue where watch did not work when referencing configuration updates between multiple sources
Which issue(s) this PR fixes (resolves / be part of):
fixes #2801
Other special notes for the reviewers:
/
@shenqidebaozi Hi, our project needs to use this function, can we speed up the schedule?
@zhan3333 ok
@zhan3333 please fix lint
Codecov Report
Merging #2868 (c20dacf) into main (32b1d13) will increase coverage by
0.12%
. The diff coverage is55.55%
.
:exclamation: Current head c20dacf differs from pull request most recent head 2f37620. Consider uploading reports for the commit 2f37620 to get more accurate results
:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.
@@ Coverage Diff @@
## main #2868 +/- ##
==========================================
+ Coverage 84.50% 84.63% +0.12%
==========================================
Files 88 88
Lines 3970 3982 +12
==========================================
+ Hits 3355 3370 +15
+ Misses 439 435 -4
- Partials 176 177 +1
Impacted Files | Coverage Ξ | |
---|---|---|
config/config.go | 62.06% <55.55%> (+7.40%) |
:arrow_up: |
@shenqidebaozi the lint fix has been completed
@shenqidebaozi ping
Bot detected the issue body's language is not English, translate it automatically. π―ππ»π§βπ€βπ§π«π§πΏβπ€βπ§π»π©πΎβπ€βπ¨πΏπ¬πΏ
@Magic Baoziping
could you please provide more detailed background and modification instructions
could you please provide more detailed background and modification instructions
Of course @shenqidebaozi
Problem:
When a configuration is referenced across source config, updates to the referenced configuration cannot affect the referenced key.
How it works: config.load()
will merge all source config into reader, and when config.next()
gets a source configuration change, only that source KVS will be merged into reader.
Because the reference configuration is already processed to a specific value in reader, merge to reader does not trigger an update of the reference configuration.
For example:
source1:
{
"key": "${key2}"
}
source2:
{
"key2": "value"
}
After config.Load()
, the structure in reader looks like this:
reader:
{
"key": "value",
"key2": "value"
}
When source2.key2
value is updated to newValue
, the original config.watch()
logic merges new KVS with reader to obtain the new reader value:
new reader
{
"key": "value",
"key2": "newValue"
}
Clearly, updates to key2 do not affect the value of the reference configuration key, causing the problem.
Solution:
When watch changes, Re-read the sources, this will make the key
get the reference configuration value ${key2}
again, and create a new reader to replace the config.reader to avoid the merge does not trigger updates when the reference.
@shenqidebaozi ping
Bot detected the issue body's language is not English, translate it automatically. π―ππ»π§βπ€βπ§π«π§πΏβπ€βπ§π»π©πΎβπ€βπ¨πΏπ¬πΏ
@Magic Baoziping