kratos icon indicating copy to clipboard operation
kratos copied to clipboard

fix(config): references between different sources are consistent when watch

Open zhan3333 opened this issue 1 year ago β€’ 11 comments

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:

/

zhan3333 avatar Jun 14 '23 03:06 zhan3333

@shenqidebaozi Hi, our project needs to use this function, can we speed up the schedule?

zhan3333 avatar Jul 05 '23 03:07 zhan3333

@zhan3333 ok

shenqidebaozi avatar Jul 05 '23 07:07 shenqidebaozi

@zhan3333 please fix lint

shenqidebaozi avatar Jul 05 '23 12:07 shenqidebaozi

Codecov Report

Merging #2868 (c20dacf) into main (32b1d13) will increase coverage by 0.12%. The diff coverage is 55.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:

... and 1 file with indirect coverage changes

codecov-commenter avatar Jul 06 '23 03:07 codecov-commenter

@shenqidebaozi the lint fix has been completed

zhan3333 avatar Jul 06 '23 03:07 zhan3333

@shenqidebaozi ping

zhan3333 avatar Jul 17 '23 02:07 zhan3333

Bot detected the issue body's language is not English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ


@Magic Baoziping

kratos-ci-bot avatar Jul 17 '23 02:07 kratos-ci-bot

could you please provide more detailed background and modification instructions

shenqidebaozi avatar Jul 17 '23 02:07 shenqidebaozi

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.

zhan3333 avatar Jul 18 '23 08:07 zhan3333

@shenqidebaozi ping

zhan3333 avatar Aug 02 '23 02:08 zhan3333

Bot detected the issue body's language is not English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ


@Magic Baoziping

kratos-ci-bot avatar Aug 02 '23 02:08 kratos-ci-bot