Loading
Save Auto model routing setting and default it on with Feature preview
What does this MR do and why?
Saves the Auto model routing setting, and turns Auto on when Feature preview is turned on and Auto was never set.
| Case | Saved Auto |
|---|---|
| Feature preview off, or turned off | Not changed |
| Feature preview on, Auto never set | nil (off) |
| Feature preview turned on, Auto never set | true |
| Feature preview turned on, Auto set before | Kept |
| Owner or administrator changes Auto | true or false |
While duo_developer_model_routing is off for the current user, the setting is ignored and the default-on rule does not run. This way, no one gets Auto before the UI shows the setting.
| GitLab.com (top-level group) | GitLab Self-Managed and Dedicated (instance) | |
|---|---|---|
| Save | ai_settings_attributes[auto_model_routing_enabled] on PUT /groups/:id |
autoModelRoutingEnabled on the duoSettingsUpdate mutation (experiment) |
| Default-on rule | In the same save, in Groups::UpdateService. |
In the same save, in ApplicationSettings::UpdateService. |
| Audit event | auto_model_routing_enabled_updated |
ai_setting_updated (mutation) or application_setting_updated (PUT /application/settings) |
The default is written in the same save, so it gets an audit event too. Nothing reads the setting yet (!273274 (merged)). The UI is in #641329.
How to set up and validate locally
-
In a Rails console, run
Feature.enable(:duo_developer_model_routing), then define the helpers for your setup. Both define the same helpers.GitLab.com (top-level group):
GITLAB_SIMULATE_SAAS=1 bin/rails consolegroup = Group.find_by_full_path('gitlab-duo') user = group.owners.first group.ai_settings.save! unless group.ai_settings.persisted? fp = :experiment_features_enabled reset = ->(fp_on, auto) do group.namespace_settings.update_column(:experiment_features_enabled, fp_on) group.ai_settings.update_column(:auto_model_routing_enabled, auto) end save = ->(params) do Groups::UpdateService.new(group.reload, user, params).execute group.reload.ai_settings.auto_model_routing_enabled end set_auto = ->(value) { save.(ai_settings_attributes: { auto_model_routing_enabled: value }) }GitLab Self-Managed (instance):
bin/rails consoleadmin = User.admins.first settings = Gitlab::CurrentSettings.current_application_settings Current.organization = Organizations::Organization.default_organization fp = :instance_level_ai_beta_features_enabled reset = ->(fp_on, auto) do duo = settings.reload.duo_settings.except('auto_model_routing_enabled') duo['auto_model_routing_enabled'] = auto unless auto.nil? settings.update_columns(instance_level_ai_beta_features_enabled: fp_on, duo_settings: duo) ApplicationSetting.expire # update_columns skips the settings cache expiry end save = ->(params) do ApplicationSettings::UpdateService.new(settings.reload, admin, params).execute settings.reload.auto_model_routing_enabled end # Same service the `duoSettingsUpdate` mutation calls set_auto = ->(value) do Ai::DuoSettings::UpdateService.new({ auto_model_routing_enabled: value }, current_user: admin).execute settings.reload.auto_model_routing_enabled end -
Run each line. It returns the saved Auto value.
Case Run Returns Feature preview off reset.(false, nil); save.(fp => false)nilFeature preview turned off reset.(true, true); save.(fp => false)trueFeature preview on, Auto never set reset.(true, nil); save.(fp => true)nilFeature preview turned on, Auto never set reset.(false, nil); save.(fp => true)trueFeature preview turned on, Auto set before reset.(false, false); save.(fp => true)falseOwner or administrator changes Auto reset.(true, nil); set_auto.(false)falseFlag off, Feature preview turned on Feature.disable(:duo_developer_model_routing); reset.(false, nil); save.(fp => true)nil
References
- Closes #641323 (closed)
- Parent: #639377
- Rules: #639377 (comment 4263765508)
Edited by Cindy Halim