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

Loading report #82

Open
LukeMathWalker opened this issue May 18, 2023 · 2 comments · May be fixed by #83
Open

Loading report #82

LukeMathWalker opened this issue May 18, 2023 · 2 comments · May be fixed by #83

Comments

@LukeMathWalker
Copy link

LukeMathWalker commented May 18, 2023

An extremely common issue when working with hierarchical configuration is understanding where values are coming from.

In particular, quickly determining if a specific value is coming from a specific source.

What I'd like to have is something I'm calling a "loading report": an iterator that touches all values that have been loaded and tells you "X was loaded from source Y, which overrode the value set by source Z".
This could be used to emit the report as telemetry data (e.g. a structured log record).

The current config crate does not help here, because the different layers are eagerly merged.
figment is almost equally unhelpful, because you'd have to wrap every single field in Tagged (+find a way to implement a visitor).

Is this something you'd be interested to support in the next iteration of config?

@matthiasbeyer
Copy link
Owner

matthiasbeyer commented May 18, 2023

Hi! Thanks for your issue!

That is definitively one valid thing to have, and I believe we have this (almost):

With Config::get_view() you can get a ConfigView into your loaded configuration:

https://github.com/matthiasbeyer/config-rs-ng/blob/master/src/config/layers.rs#L62

And with the ConfigView::description() function (https://github.com/matthiasbeyer/config-rs-ng/blob/master/src/object/mod.rs#L132) you can get a ConfigSourceDescription (https://github.com/matthiasbeyer/config-rs-ng/blob/master/src/description.rs#L3) which holds information about where the configuration value came from.

What I see missing is a way to iterate over all layers of a Config::layers() (https://github.com/matthiasbeyer/config-rs-ng/blob/master/src/config/config.rs#L32) object (https://github.com/matthiasbeyer/config-rs-ng/blob/master/src/config/layers.rs#L16)

Which I think we can add.


Edit: Ah, what also would be missing is a way to iterate all values of a ConfigObject. 🤔

@LukeMathWalker
Copy link
Author

Thanks for the answer!

Yeah, from a quick look it's the "visiting" part that's currently missing.

@matthiasbeyer matthiasbeyer linked a pull request May 18, 2023 that will close this issue
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 a pull request may close this issue.

2 participants