Skip to content

Add a new chatops command to delete zoekt indexed namespace

Resolves: gitlab-org/gitlab#420819 (closed)

This MR adds a chatops command to delete the zoekt indexed namespace.

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
--- 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"
 
         @host = host
         @internal_client = ::Gitlab::Client
  1. Go to http://127.0.0.1:3000/toolbox/gitlab-smoke-tests/edit#js-general-project-settings and make this project public
  2. Get the group id of group http://127.0.0.1:3000/toolbox (following steps assume it is 22)
  3. Get the project id of http://127.0.0.1:3000/toolbox/gitlab-smoke-tests (following steps assume it is 1)
  4. Get the id of ::Zoekt::Shard.first (following steps assume it is 1)
  5. Get an API token for your local root user on GDK
  6. Run env GITLAB_TOKEN='the-token' CHAT_INPUT='indexed_namespace_create 1 22' bundle exec ./bin/chatops zoekt
  7. 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
  8. Now delete the zoekt index namespace: env GITLAB_TOKEN='glpat-3r4zP1czEwXt9cWZ_8ym' CHAT_INPUT='indexed_namespace_delete 1 22' bundle exec ./bin/chatops zoekt
  9. Search the project and confirm it's not 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. I have masked my token

Successful case:

~/work/gitlab-development-kit/chatops (chatops-command-remove-zoekt-indexed-namespace ✗) env GITLAB_TOKEN='glpat-3r4zP1czEwXt9cWZ_***' CHAT_INPUT='indexed_namespace_delete 1 22' bundle exec ./bin/chatops zoekt
2023-08-30 14:47:08.952181 I [{:user=>nil}] Chatops -- Command to be executed -- {:name=>"zoekt", :chat_input=>"indexed_namespace_delete 1 22", :split_chat_input=>["indexed_namespace_delete", "1", "22"]}
2023-08-30 14:47:09.066636 D [{:user=>nil}] Chatops::Gitlab::Client -- [HTTParty] [2023-08-30 14:47:09 +0200] 204 "DELETE http://127.0.0.1:3000/api/v4/admin/zoekt/shards/1/indexed_namespaces/22" - 

Successfully deleted indexed namespace with shard 1 and namespace 22

Unsuccessful case:

~/work/gitlab-development-kit/chatops (chatops-command-remove-zoekt-indexed-namespace ✗) env GITLAB_TOKEN='glpat-3r4zP1czEwXt9cWZ_***' CHAT_INPUT='indexed_namespace_delete 1 22' bundle exec ./bin/chatops zoekt
2023-08-30 14:47:14.444752 I [{:user=>nil}] Chatops -- Command to be executed -- {:name=>"zoekt", :chat_input=>"indexed_namespace_delete 1 22", :split_chat_input=>["indexed_namespace_delete", "1", "22"]}
2023-08-30 14:47:14.464966 D [{:user=>nil}] Chatops::Gitlab::Client -- [HTTParty] [2023-08-30 14:47:14 +0200] 404 "DELETE http://127.0.0.1:3000/api/v4/admin/zoekt/shards/1/indexed_namespaces/22" 27 

Failed to delete the indexed namespace with shard 1 and namespace 22
Edited by Ravi Kumar

Merge request reports

Loading