Skip to content

Draft: Introduce api to access CloudConnector data

What does this MR do and why?

Introduce api to read the Cloud Connector service data.
We sync that data from CustomersDot and save it into the instance DB (done via !140980 (merged)).

It allows you to call:

  • ::Gitlab::CloudConnector::Client.new.services to list all the service data we store
  • Check individual service start date: ::Gitlab::CloudConnector::Client.new.find_service(:code_suggestions).started?

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

Prep: you need the record in the ::CloudConnector::Access table, for example:

[2] pry(main)> ::CloudConnector::Access.last
  CloudConnector::Access Load (0.5ms)  SELECT "cloud_connector_access".* FROM "cloud_connector_access" ORDER BY "cloud_connector_access"."id" DESC LIMIT 1 /*application:console,db_config_name:main,console_hostname:Alekseis-MBP-2,console_username:al,line:(pry):2:in `__pry__'*/
=> #<CloudConnector::Access:0x0000000139c75008
 id: 8,
 created_at: Tue, 09 Jan 2024 15:51:57.482570000 UTC +00:00,
 updated_at: Tue, 16 Jan 2024 10:55:25.184285000 UTC +00:00,
 data:
  {"available_services"=>
    [{"name"=>"code_suggestions", "serviceStartTime"=>"2024-02-15T00:00:00Z"},
     {"name"=>"duo_chat", "serviceStartTime"=>nil}]}>

You can get it the natural way:

  • Firstly, you need to run CustomersDot locally, connect it to your GitLab instance, and have a valid Cloud license issued to your GitLab instance.
  • Pull this branch: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/8987
  • Make sure FF is enabled for your local CDot instance: cloud_connector_available_services. It doesn't work for me locally as described in CDot Readme (need to investigate), so unless I figure it out, I just mocked it: if true || Unleash.enabled?(:cloud_connector_available_services)
  • On your local GitLab, pull this branch
  • Open rails console: export GITLAB_LICENSE_MODE=test && export CUSTOMER_PORTAL_URL='http://localhost:5000' && bundle exec rails c (adjust CDot URL accordingly)
  • Run the sync: result = ::Ai::SyncCloudConnectorAccessService.new.execute
  • Check that the data was saved to the DB: ::CloudConnector::Access.last should have the data, ::CloudConnector::Access.count should be 1

...or you can create the DB record manually.

The actual check

Open rails c and run:

[4] pry(main)> ::Gitlab::CloudConnector::Client.new.services
=> [#<Gitlab::CloudConnector::Service:0x000000015e6329a0 @name=:code_suggestions, @start_time=2024-02-15 00:00:00 UTC>,
 #<Gitlab::CloudConnector::Service:0x000000015e632950 @name=:duo_chat, @start_time=nil>]   

Related to #438276 (closed)

Edited by Aleksei Lipniagov

Merge request reports