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

Lazy grouping within IAppConfig #41755

Merged
merged 3 commits into from
Jan 16, 2024
Merged

Lazy grouping within IAppConfig #41755

merged 3 commits into from
Jan 16, 2024

Conversation

ArtificialOwl
Copy link
Member

@ArtificialOwl ArtificialOwl commented Nov 26, 2023

Added features to the IAppConfig:

  • lazy loading to avoid loading all app configs on each request. It split the configs in 2 groups; the normal (fast) config values that are loaded in all requests and the lazy config that contains values that are loaded only when one config key of this type is needed.
  • typed value so that app knows what to expect when setting/getting config values,
  • sensitivity is now set directly when storing a new config value.

limitation

  • sensitivity status and type of a value cannot be removed/changed by mistake.
  • While it is easy to configure value as sensitive on set, to switch back the status to non-sensitive the app must call updateSensitive()
  • Once typed, a value must be deleted in order to change its type.

oc_appconfig

New fields in the appconfig table:

  • lazy (bool): 0 is the normal/default way to store a config value,
  • type (int): will store the type and the sensitive status of a config value. This is a bit flag using those const:
	VALUE_SENSITIVE = 1;
	VALUE_MIXED = 2;
	VALUE_STRING = 4;
	VALUE_INT = 8;
	VALUE_FLOAT = 16;
	VALUE_BOOL = 32;
	VALUE_ARRAY = 64;

occ

occ config:app:get

It adds the --details option to the config:app:get:

$ ./occ config:app:get myapp mykey --details
{
    "app": "myapp",
    "key": "mykey",
    "value": "ouila",
    "lazy": true,
    "type": 4,
    "typeString": "string",
    "sensitive": false
}

occ config:app:set

New options:

  • --lazy, --no-lazy to change the way to store/retrieve the config value,
  • --sensitive, --no-sensitive to change the sensitivity of a config value,
  • --type to set/change the type of a value,
  • Unless using --no-interaction a confirmation from the admin is needed when editing the type/status of a config value.

Note(s)

PR is big and adds huge edits. It should stays compatible with previous call to AppConfig.

@ArtificialOwl ArtificialOwl added the 2. developing Work in progress label Nov 26, 2023
@ArtificialOwl ArtificialOwl added this to the Nextcloud 29 milestone Nov 26, 2023
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/AllConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
@ArtificialOwl ArtificialOwl force-pushed the enh/noid/lazyconfig branch 3 times, most recently from 94d16bf to ab05155 Compare November 27, 2023 20:55
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Fixed Show fixed Hide fixed
lib/private/LazyConfig.php Outdated Show resolved Hide resolved
@ArtificialOwl ArtificialOwl changed the title ILazyConfig Lazy grouping within IAppConfig Nov 29, 2023
@ArtificialOwl ArtificialOwl force-pushed the enh/noid/lazyconfig branch 2 times, most recently from fa397a2 to 6b121f1 Compare December 5, 2023 12:42
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Psalm found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

Really not a fan of the caching strategy.
It sounds really risky to get database and cache out of sync easily with a long running task in OCC or request, etc.

As per chat however I like the general idea of having a lazy "block" and even more integrating the sensitive part directly.

Speaking of sensitive some apps use the ICrypto::encrypt() and ICrypto::dectrypt(). We could include that into the methods and help developers again to not have security optionally?

lib/private/Server.php Outdated Show resolved Hide resolved
core/Migrations/Version29000Date20231126110901.php Outdated Show resolved Hide resolved
lib/private/AllConfig.php Outdated Show resolved Hide resolved
lib/private/AllConfig.php Outdated Show resolved Hide resolved
lib/private/AllConfig.php Outdated Show resolved Hide resolved
lib/private/AppConfig.php Outdated Show resolved Hide resolved
lib/private/AppConfig.php Outdated Show resolved Hide resolved
lib/private/AppConfig.php Outdated Show resolved Hide resolved
lib/private/AppConfig.php Outdated Show resolved Hide resolved
lib/private/AppConfig.php Outdated Show resolved Hide resolved
core/ajax/update.php Fixed Show fixed Hide fixed
lib/private/AppConfig.php Fixed Show fixed Hide fixed
core/Command/Config/ListConfigs.php Fixed Show fixed Hide fixed
core/Command/Config/App/GetConfig.php Outdated Show resolved Hide resolved
core/Command/Config/App/SetConfig.php Outdated Show resolved Hide resolved
core/Command/Config/App/SetConfig.php Fixed Show resolved Hide resolved
core/Command/Config/App/SetConfig.php Outdated Show resolved Hide resolved
core/Migrations/Version29000Date20231126110901.php Outdated Show resolved Hide resolved
try {
$typeString = $this->convertTypeToString($type);
} catch (AppConfigIncorrectTypeException $e) {
$this->logger->warning('type stored in database is not correct', ['exception' => $e, 'type' => $type]);
Copy link
Member

Choose a reason for hiding this comment

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

This spams Unknown numeric type 0 very heavily for me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am interested how you came to this as type should not be 0 in database

Copy link
Member

Choose a reason for hiding this comment

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

Mostlikely from occ config:app:set -vvv ${dir##*/} enabled --value="no" which I have in my set up script to force disable all apps as an option.
The point is more that there will be a lot of "dirty" instances already out there and spaming their logs with warnings when the admin can not know what to do about it is meh.

Copy link
Member Author

@ArtificialOwl ArtificialOwl Jan 15, 2024

Choose a reason for hiding this comment

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

I cannot reproduce this issue and think we can merge as it is right now.
By default, occ config:app:set set value as mixed.

The only issue that I am seeing when using the occ config:app:set is that during the upgrading process, between the files are changed and the upgrade process is run.

Maybe we can edit the database (adding type+lazy field) already in 28 so we don't have error about missing field during the upgrade steps

lib/public/IAppConfig.php Outdated Show resolved Hide resolved
lib/public/IAppConfig.php Outdated Show resolved Hide resolved
lib/public/IAppConfig.php Outdated Show resolved Hide resolved
lib/public/IAppConfig.php Outdated Show resolved Hide resolved
@nickvergessen
Copy link
Member

❌ Drone failures are related!

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

Okay otherwise

lib/private/AppConfig.php Outdated Show resolved Hide resolved
core/Command/Config/App/SetConfig.php Fixed Show resolved Hide resolved
Signed-off-by: Maxence Lange <[email protected]>
Signed-off-by: Maxence Lange <[email protected]>
d

Signed-off-by: Maxence Lange <[email protected]>
Signed-off-by: Maxence Lange <[email protected]>
Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

At least needs an issue in the guests app to make them aware of the breakage that is coming their way:
https://github.com/nextcloud/guests/blob/master/lib/AppConfigOverwrite.php

@juliusknorr
Copy link
Member

juliusknorr commented Jan 25, 2024

Just noticed we also have two different IAppConfig interfaces (one generic and one as a app framework service). The app framework service should probably also get adapted to cover the new API as currently it is just a wrapper for the deprecated methods: https://github.com/nextcloud/server/blob/215aef3cbdc1963be1bb6bca5218ee0a4b7f1665/lib/public/AppFramework/Services/IAppConfig.php

@nickvergessen
Copy link
Member

Should we just deprecate it? we shouldn't have 2 similar interfaces like this?

@juliusknorr
Copy link
Member

I still like the service approach to simplify and not need to pass in the app id which makes the api a bit easier for app developers and and more restrictive to not mess with other apps configs

@nickvergessen
Copy link
Member

Ah, missed that bit. It's basically what I abstracted away in talk by using my own config class :D

Comment on lines +66 to +72
->addOption(
'type',
null,
InputOption::VALUE_REQUIRED,
'Value type [string, integer, float, boolean, array]',
'string'
)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Array handling still needs to be documented. Particularly since it's diverged from system: https://docs.nextcloud.com/server/latest/admin_manual/occ_command.html#setting-an-array-configuration-value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews pending documentation This pull request needs an associated documentation update performance 🚀
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants