Skip to content

chatops commands for Zoekt

Dylan Griffith requested to merge 404534-chatops-commands-for-zoekt into master

In gitlab-org/gitlab!116650 (merged) we added some admin APIs that will be used during our production rollout of Zoekt. This MR makes just 2 of these endpoints accessible in chatops as these are the ones that require write access. The other data can be easily accessed from read-only consoles if needed. We may consider exposing those via chatops eventually but for now these are the ones we need to move the rollout forward.

Resolves gitlab-org/gitlab#404534 (closed)

How to test

  1. Setup local GDK with Zoekt following https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/howto/zoekt.md
  2. Hack your local chatops to point at your local GDK
    diff --git a/lib/chatops/gitlab/client.rb b/lib/chatops/gitlab/client.rb
    index 9e4fa29..f3a0d9f 100644
    --- a/lib/chatops/gitlab/client.rb
    +++ b/lib/chatops/gitlab/client.rb
    @@ -14,7 +14,7 @@ module Chatops
           # token - The API token to use for authentication.
           # host - The hostname to use.
           def initialize(token:, host: DEFAULT_HOST, httparty: {})
    -        endpoint = "https://#{host}/api/v4"
    +        endpoint = "http://127.0.0.1:3000/api/v4"
  3. Go to http://127.0.0.1:3000/toolbox/gitlab-smoke-tests/edit#js-general-project-settings and make this project public
  4. Get the group id of group http://127.0.0.1:3000/toolbox (following steps assume it is 22)
  5. Get the project id of http://127.0.0.1:3000/toolbox/gitlab-smoke-tests (following steps assume it is 1)
  6. Get the id of ::Zoekt::Shard.first (following steps assume it is 1)
  7. Get an API token for your local root user on GDK
  8. Run env GITLAB_TOKEN='the-token' CHAT_INPUT='indexed_namespace_create 1 22' bundle exec ./bin/chatops zoekt
  9. Run `env GITLAB_TOKEN='the-token' CHAT_INPUT='force_index_project 1' bundle exec ./bin/chatops zoekt
  10. Search the project and confirm it's using zkt in the performance bar http://127.0.0.1:3000/search?search=Smok.*est&nav_source=navbar&project_id=1&group_id=22&search_code=true

My testing output

I tested locally and got this output:

16:31:24 dylangriffith@Dylan-GitLab-MBP:~/workspace/gitlab-com/chatops$ env GITLAB_TOKEN='the-token' CHAT_INPUT='indexed_namespace_create 1 22' bundle exec ./bin/chatops zoekt
2023-04-13 16:31:31.897820 I [{:user=>nil}] Chatops -- Command to be executed -- {:name=>"zoekt", :chat_input=>"indexed_namespace_create 1 22", :split_chat_input=>["indexed_namespace_create", "1", "22"]}
2023-04-13 16:31:31.922414 D [{:user=>nil}] Chatops::Gitlab::Client -- [HTTParty] [2023-04-13 16:31:31 +1000] 200 "PUT http://127.0.0.1:3000/api/v4/admin/zoekt/shards/1/indexed_namespaces/22" 45

Successfully created indexed namespace for shard 1 and namespace 22

16:31:31 dylangriffith@Dylan-GitLab-MBP:~/workspace/gitlab-com/chatops$ env GITLAB_TOKEN='the-token' CHAT_INPUT='force_index_project 1' bundle exec ./bin/chatops zoekt
2023-04-13 16:34:08.529529 I [{:user=>nil}] Chatops -- Command to be executed -- {:name=>"zoekt", :chat_input=>"force_index_project 1", :split_chat_input=>["force_index_project", "1"]}
2023-04-13 16:34:08.609893 D [{:user=>nil}] Chatops::Gitlab::Client -- [HTTParty] [2023-04-13 16:34:08 +1000] 200 "PUT http://127.0.0.1:3000/api/v4/admin/zoekt/projects/1/index" 37

Successfully triggered indexing for project 1 with job_id "f259b9636ecb59abf062da8c"
Edited by Dylan Griffith

Merge request reports