Skip to content
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(config): references between different sources are consistent when watch #2868

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zhan3333
Copy link

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
Copy link
Author

zhan3333 commented Jul 5, 2023

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

@shenqidebaozi
Copy link
Sponsor Member

@zhan3333 ok

@shenqidebaozi
Copy link
Sponsor Member

@zhan3333 please fix lint

@zhan3333 zhan3333 force-pushed the fix/different_sources_references_config branch from a1daa5d to 2f37620 Compare July 6, 2023 03:15
@codecov-commenter
Copy link

codecov-commenter commented Jul 6, 2023

Codecov Report

Merging #2868 (c20dacf) into main (32b1d13) will increase coverage by 0.12%.
The diff coverage is 55.55%.

❗ Current head c20dacf differs from pull request most recent head 2f37620. Consider uploading reports for the commit 2f37620 to get more accurate results

❗ 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%) ⬆️

... and 1 file with indirect coverage changes

@zhan3333
Copy link
Author

zhan3333 commented Jul 6, 2023

@shenqidebaozi the lint fix has been completed

@zhan3333
Copy link
Author

@shenqidebaozi ping

@kratos-ci-bot
Copy link
Collaborator

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@magic Baoziping

@shenqidebaozi
Copy link
Sponsor Member

could you please provide more detailed background and modification instructions

@zhan3333
Copy link
Author

zhan3333 commented Jul 18, 2023

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
Copy link
Author

zhan3333 commented Aug 2, 2023

@shenqidebaozi ping

@kratos-ci-bot
Copy link
Collaborator

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@magic Baoziping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Config update cascade for Config.Watch()
4 participants