-
Notifications
You must be signed in to change notification settings - Fork 71
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
Create config "service" #181
Comments
I definitely see the simplicity of doing something like this. I can make some comments however:
I have always thought (but maybe I am wrong!) that limiting the scope of variables and only giving to different components what they need is better/safer idiom. If a value is truely needed everywhere, then it would make sense to have global data. In the case of Also, what if we have in that |
We already handle the thread management problem because you can't just destroy providers and other such structures (which are themselves readonly) if you don't stop the threadpool. Here's the code: if reload_signal.swap(false, Ordering::Relaxed) {
let _ = sd_notify::notify(false, &[sd_notify::NotifyState::Reloading]);
info!("SIGHUP signal received. Reloading the configuration...");
threadpool.join();
... so that's covered - when you recreate the
It is, when it only affects those variables. We could just give this data to the providers (though even that would be overkill, having all providers share these flags), but we'd have to also put it in the key info managers, authenticators etc. Logging is a cross-cutting concern and other languages have frameworks that allow you to handle these in a way that affects everything at the same time (I've not checked for Rust, tbh). My idea is that since some configuration values apply equally to everything in the service, they should be available globally. Another configuration value like this might be, for example, a flag for whether deprecated values should be rejected or not.
That's not what I had in mind, I only intend to use this for configuration values that affect similar mechanisms everywhere in the service.
Not needed since it will be read-only as per what I described above. |
How to recreate it if it is a |
True, I guess Rust wouldn't normally let you do that, but we can make it let us. Given that we know that the usage pattern is safe, we can do something like
And only allow construction of |
Yes we could do it using Could we list the config fields that would need, today, this feature? For I guess I am worried that we trade safety for ease of use of configuration. |
Done in #182 - thread safety was fixed with using atomic structures within the |
Given that with increasing complexity we will most likely see a need for accessing configuration values (e.g. for logging) throughout the service, I propose creating a structure that will act as a "config service".
The service will rely on a
Config
struct wrapped in a global singleton. The config will have a builder which initializes the state and all other methods will be "object-less":The configuration can then be accessed from anywhere in the service as
Config::verbose_log()
. Whenever we need to add more flags/configuration values, this can be done quite easily, without having to change any signatures/interfaces apart fromConfig
.The text was updated successfully, but these errors were encountered: