chatops commands for Zoekt
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
- Setup local GDK with Zoekt following https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/howto/zoekt.md
- 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"
- Go to
http://127.0.0.1:3000/toolbox/gitlab-smoke-tests/edit#js-general-project-settings
and make this project public - Get the group id of group
http://127.0.0.1:3000/toolbox
(following steps assume it is22
) - Get the project id of http://127.0.0.1:3000/toolbox/gitlab-smoke-tests (following steps assume it is
1
) - Get the id of
::Zoekt::Shard.first
(following steps assume it is1
) - Get an API token for your local
root
user on GDK - Run
env GITLAB_TOKEN='the-token' CHAT_INPUT='indexed_namespace_create 1 22' bundle exec ./bin/chatops zoekt
- Run `env GITLAB_TOKEN='the-token' CHAT_INPUT='force_index_project 1' bundle exec ./bin/chatops zoekt
- 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