Remove UP deny list from AvailableServicesGenerator

What does this MR do and why?

Removes the Unit Primitive deny list from AvailableServicesGenerator.

To make the new DataModel APIs that operate mainly on Unit Primitives backward compatible with our legacy Service concept, we had added AvailableServicesGenerator. This class generates a services catalog entry that matches the legacy schema for each Unit Primitive defined in the catalog. This allows us to treat UPs and Services largely equivalently in Ruby code until we remove services entirely.

In this class, we had maintained a UP deny list for UPs that would not get a service entry generated. We did this, because we used to have drift between the legacy service catalog and newly added UPs, and a test that verified these catalogs always match in their contents. However, we have already removed this legacy service catalog so this is not needed anymore.

In fact, maintaining this filter prevents us from progressing with Refactor AiGateway.headers to accept unit_primi... (gitlab-org/gitlab#546578 - closed), because here we need to locate service entries using UPs that happen to be on this deny list (such as complete_code and generate_code).

We should drop this entire list.

References

How to set up and validate locally

Simple test

  1. cd src/ruby
  2. bundle exec irb
  3. require 'gitlab/cloud_connector'
  4. Gitlab::CloudConnector::Configuration.config_dir = '../../config' (see #88 (closed))
  5. Gitlab::CloudConnector::AvailableServicesGenerator.new.generate('gitlab-com')['services']['complete_code']

This should print:

{"backend"=>"gitlab-ai-gateway",                                    
 "cut_off_date"=>"2024-02-15 00:00:00 UTC",                         
 "min_gitlab_version"=>"16.8",
 "bundled_with"=>{"duo_core"=>{"unit_primitives"=>["complete_code"]}, "duo_enterprise"=>{"unit_primitives"=>["complete_code"]}, "duo_pro"=>{"unit_primitives"=>["complete_code"]}}}

On main, this currently prints nil.

Integration test

We start with the master version of the CC lib.
In GDK (GitLab), run rails c with export GITLAB_SIMULATE_SAAS=1.

Query :complete_code and :agent_quick_actions services - both will return MissingServiceData because:

  • :complete_code is in denylist
  • :agent_quick_actions is in denylist
[2] pry(main)> CloudConnector::AvailableServices.find_by_name(:complete_code)
=> #<CloudConnector::MissingServiceData:0x000000015e359148>
[3] pry(main)> CloudConnector::AvailableServices.find_by_name(:agent_quick_actions)
=> #<CloudConnector::MissingServiceData:0x000000015ffbc768>

Now we want to test this branch.
Paste the AvailableServicesGenerator contents into GDK's into the matching gitlab-cloud-connector (gem) file.
(you should gem pristine gitlab-cloud-connector after the test is complete).
Or link the gem source into GitLab from the your local CC lib folder.
Restart rails c (not just reload the code).

Query :complete_code and :agent_quick_actions services.

:complete_code will start returning the service - because we dropped the denylist:

[1] pry(main)> CloudConnector::AvailableServices.find_by_name(:complete_code)
=> #<CloudConnector::SelfSigned::AvailableServiceData:0x000000033ed7cbc0
 @add_on_names=["duo_core", "duo_enterprise", "code_suggestions"],
 @backend="gitlab-ai-gateway",
 @bundled_with={"duo_core"=>[:complete_code], "duo_enterprise"=>[:complete_code], "duo_pro"=>[:complete_code]},
 @cut_off_date=2024-02-15 00:00:00 UTC,
 @key_loader=#<CloudConnector::CachingKeyLoader:0x0000000341e95180>,
 @name=:complete_code>

:agent_quick_actions will continue returning MissingService because it is only configured for self-managed in service defintion (we run in gitlab.com context):

[2] pry(main)> CloudConnector::AvailableServices.find_by_name(:agent_quick_actions)
=> #<CloudConnector::MissingServiceData:0x000000016f85d868>

Our logic respects that - despite the fact that we have UP with the same name and the fact the denylist is removed, we will not generate the service for :agent_quick_actions while in gitlab.com context because :agent_quick_actions is configured only for self-managed realm.

Finally, patch the UP config (inside the GDK itself or in CC repo - depending how you linked it) to update services/agent_quick_actions.yml:

---
name: agent_quick_actions
gitlab_realm:
  - self-managed
  - gitlab-com
unit_primitives:
  - agent_quick_actions

We added gitlab-com in supported realms.

Restart rails c.

Now agent_quick_actions will be findable:

[1] pry(main)> CloudConnector::AvailableServices.find_by_name(:agent_quick_actions)
=> #<CloudConnector::SelfSigned::AvailableServiceData:0x0000000146933220
 @add_on_names=["_irrelevant"],
 @backend="gitlab-ai-gateway-agent",
 @bundled_with={"_irrelevant"=>[:agent_quick_actions]},
 @cut_off_date=nil,
 @key_loader=#<CloudConnector::CachingKeyLoader:0x0000000339bb9f90>,
 @name=:agent_quick_actions>

Additionally, you can test everything through patching CDot and syncing UPs to your instance (to check self-managed side).

Edited by Aleksei Lipniagov

Merge request reports

Loading