Page MenuHomePhabricator

wmfLabsOverrideSettings() doesn't merge settings recursively
Closed, ResolvedPublic

Description

For the $wmgMonologChannels setting, I want to add three new log settings for the beta cluster that are unique from the values that are set in $wmgMonologChannels['default'] for production hosts:

// Additional log channels for beta cluster
'wmgMonologChannels' => array(                                          
    'default' => array(
        'CentralAuthVerbose' => 'debug',
        'dnsblacklist' => 'debug',
        'squid' => 'debug',
    ),
),

Unfortunately, the wmfLabsOverrideSettings() function that merges the values provided by wmfLabsSettings() only handles the merge at the top key level (eg wmgMonologChannels). If the top level key is prefixed with a - then the beta settings replace the production settings. Otherwise the production settings and the beta specific settings are combined using array_merge:

foreach ( $betaSettings as $key => $value ) {
        if ( substr( $key, 0, 1 ) == '-' ) {
                // Settings prefixed with - are completely overriden
                $wgConf->settings[substr( $key, 1 )] = $value;
        } elseif ( isset( $wgConf->settings[$key] ) ) {
                $wgConf->settings[$key] = array_merge( $wgConf->settings[$key], $value );
        } else {
                $wgConf->settings[$key] = $value;
        }
}

The problem here is that array_merge is not recursive (by design). This leads to the $wmgMonologChannels['default'] entry from the beta settings overriding the $wmgMonologChannels['default'] entry from the production settings rather than my desired behavior of merging the two $wmgMonologChannels['default'] collections.

Event Timeline

bd808 raised the priority of this task from to Needs Triage.
bd808 updated the task description. (Show Details)
bd808 subscribed.

Change 210203 had a related patch set uploaded (by BryanDavis):
beta: Add common wikitag for all beta cluster wikis

https://gerrit.wikimedia.org/r/210203

Change 210203 merged by jenkins-bot:
beta: Add common wikitag for all beta cluster wikis

https://gerrit.wikimedia.org/r/210203

Merging config recursively properly is a non-trivial problem. The easier thing to do in this case was to add a wikitag to all beta cluster wikis that can be used by the normal SiteConfiguration settings merge system by using setting key of '+beta'. $wmgMonologChannels is working as previously expected now on the beta cluster.

bd808 claimed this task.