Skip to content

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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ChristophWurst
Copy link
Member

@ChristophWurst ChristophWurst commented Jun 17, 2025

☑️ Resolves

  • Fix topic discussed via chat

🖼️ Screenshots

image


For consistency there are conventions for config keys:

* System config keys should only contain lower case letters, numbers and `_`. This ensures that they can be used as environment variables.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* System config keys should only contain lower case letters, numbers and `_`. This ensures that they can be used as environment variables.
* System config keys should only contain lower case letters, numbers and ``_``. This ensures that they can be used as environment variables.

Did you mean to make it code?

Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like bikes and sheds.

@szaimen
Copy link
Contributor

szaimen commented Jun 17, 2025

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

@ChristophWurst
Copy link
Member Author

@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

@susnux
Copy link
Contributor

susnux commented Jun 17, 2025

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

Copy link
Contributor

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

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

  • localstorage_umask
  • localstorage_unlink_on_truncate

VS

  • localstorage__umask
  • localstorage__unlink_on_truncate

@szaimen
Copy link
Contributor

szaimen commented Jun 17, 2025

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...

Copy link
Contributor

@szaimen szaimen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ChristophWurst
Copy link
Member Author

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.

@kesselb
Copy link
Contributor

kesselb commented Jun 17, 2025

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.

@nickvergessen
Copy link
Member

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?

@ChristophWurst
Copy link
Member Author

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 🌝

@susnux
Copy link
Contributor

susnux commented Jun 17, 2025

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,
],

@nickvergessen
Copy link
Member

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?

@ChristophWurst
Copy link
Member Author

ChristophWurst commented Jun 17, 2025

@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.

@nickvergessen
Copy link
Member

nickvergessen commented Jun 17, 2025

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?

@ChristophWurst
Copy link
Member Author

ChristophWurst commented Jun 17, 2025

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"
}

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

Successfully merging this pull request may close these issues.

6 participants