documentation icon indicating copy to clipboard operation
documentation copied to clipboard

feat(devmanual): add section about system config key conventions

Open ChristophWurst opened this issue 7 months ago • 13 comments

☑️ Resolves

  • Fix topic discussed via chat

🖼️ Screenshots

image

ChristophWurst avatar Jun 17 '25 08:06 ChristophWurst

@ChristophWurst should we add a workflow to server that ensures the consistency after merging the doc here?

szaimen avatar Jun 17 '25 09:06 szaimen

@ChristophWurst should we add a workflow to server that ensures the consistency after merging the doc here?

I was thinking that we can update the phpdoc and see if psalm can help us. It will also make sense to find a mechanism for key aliases, so we can phase out the unconventional keys without hard breakages

ChristophWurst avatar Jun 17 '25 09:06 ChristophWurst

I was thinking that we can update the phpdoc and see if psalm can help us. It will also make sense to find a mechanism for key aliases, so we can phase out the unconventional keys without hard breakages

Maybe some kind of sysconfig lexicon that allows configure aliases

  • if the config contains unknown keys we can warn
  • if the config is writable we can migrate using it on update
  • if the config is readonly we can show that warning and remap the values

susnux avatar Jun 17 '25 09:06 susnux

Only thing one could argue would be to use __ instead of _ to separate subsystem and key, to not confuse with separating words. E.g

Yes, thought the same but this would mean even more changes to config keys, so I wouls argue it is better to leave it like it is currently with one separator...

szaimen avatar Jun 17 '25 09:06 szaimen

Only thing one could argue would be to use __ instead of _ to separate subsystem and key, to not confuse with separating words

Yes, it makes sense, but at the same time I'm with @szaimen that it means we have to change even more keys. Additionally, I have not worked with any other systems so far that would use double underscore, so it seems a bit unusual to do.

ChristophWurst avatar Jun 17 '25 09:06 ChristophWurst

Only thing one could argue would be to use __ instead of _ to separate subsystem and key, to not confuse with separating words

That sounds like a good idea.

kesselb avatar Jun 17 '25 09:06 kesselb

Yes, it makes sense, but at the same time I'm with szaimen that it means we have to change even more keys. Additionally, I have not worked with any other systems so far that would use double underscore, so it seems a bit unusual to do.

We can also have old system for old keys.

I had the thought yesterday already that we could allow NC_app__$APPID__$CONFIGKEY then to overwrite app configs via the env?

nickvergessen avatar Jun 17 '25 09:06 nickvergessen

Additionally, I have not worked with any other systems so far that would use double underscore, so it seems a bit unusual to do.

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-9.0#naming-of-environment-variables 🌝

ChristophWurst avatar Jun 17 '25 09:06 ChristophWurst

Yes, thought the same but this would mean even more changes to config keys, so I wouls argue it is better to leave it like it is currently with one separator...

We would not have to change them if they work. Kind of legacy dept.

My biggest problem with the environment config is that it does not allow scoped configuration, where we use arrays. For example:

'redis.cluster' => [
	'seeds' => [
		'localhost:7000',
		'localhost:7001',
	],
	'timeout' => 0.0,
],

susnux avatar Jun 17 '25 10:06 susnux

Well for me the main question is: Should all values be env-override-able or not? I don't think the answer is a clear yes, but I also lack the idea when/why an instance would use an environment overwrite (is it temporary?) vs touching the config file? Something like the cache, DB connection, etc. sound like a "no" to me. I can see how one would try to do it with the DB password and other secrets, so they are not stored in the filesystem, etc. but then we can also simply check if we can "flatten" out those specific values, so they can be specifically overwritten instead of having to translate the full array to ENV?

nickvergessen avatar Jun 17 '25 11:06 nickvergessen

@susnux so that example would translate to this

NC_REDIS_CLUSTER__SEEDS__0=localhost:7000
NC_REDIS_CLUSTER__SEEDS__1=localhost:7001
NC_REDIS_CLUSTER__TIMEOUT=0.0

right?

Should all values be env-override-able or not?

I'd say it's a good thing to allow it. It's very useful in container setups.

ChristophWurst avatar Jun 17 '25 11:06 ChristophWurst

The bigger question with arrays is how replacing works. Let's say file has:

        "log.condition": {
            "apps": {
                "1": "admin_audit",
                "50": "calendar-appointments",
                "51": "appointments",
                "52": "calendar",
                "200": "spreed-bfp",
                "501": "imaginary"
            }
        },

would:

NC_log_condition__apps__0=perf_debug

result in:

        "log.condition": {
            "apps": {
                "0": "perf_debug"
            }
        },

or:

        "log.condition": {
            "apps": {
                "0": "perf_debug",
                "1": "admin_audit",
                "50": "calendar-appointments",
                "51": "appointments",
                "52": "calendar",
                "200": "spreed-bfp",
                "501": "imaginary"
            }
        },

if the later, how could env be used to unset one key?

nickvergessen avatar Jun 17 '25 11:06 nickvergessen

Probably the second one, because of this:

php > $config = ["1" => "foo", "2" => "bar"];
php > $config[0] = "replaced";
php > var_dump($config);
array(3) {
  [1]=>
  string(3) "foo"
  [2]=>
  string(3) "bar"
  [0]=>
  string(8) "replaced"
}

ChristophWurst avatar Jun 17 '25 11:06 ChristophWurst

Time to get it in?

nickvergessen avatar Jul 11 '25 13:07 nickvergessen

To which extent? Some of the ideas won't work right now and need changes in server

ChristophWurst avatar Jul 16 '25 10:07 ChristophWurst

To which extent? Some of the ideas won't work right now and need changes in server

At least your changes here. They already work :)

susnux avatar Jul 16 '25 13:07 susnux

/backports to stable31

ChristophWurst avatar Jul 17 '25 16:07 ChristophWurst

/backport to stable31

ChristophWurst avatar Jul 17 '25 16:07 ChristophWurst