Skip to content

Make node_id optional for Zoekt Admin API to add/remove namespace

What does this MR do and why?

We want to use create zoekt_indexed_namespace without providing the node_id. So, allowing this API to accept 0 as node_id. On the index creation endpoint, it will skip creating the Search::Zoekt::Index record when the node_id is 0. It will only create the record for Search::Zoekt::EnabledNamespace. In the case of DELETE when node_id is 0 it will remove the Search::Zoekt::Index records from all the nodes

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.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Testing for PUT endpoint

  • Create a new root namespace in the browser
  • Open a rails console
bin/rails c
  • Check the count of Search::Zoekt::EnabledNamespace and Search::Zoekt::Index
  • Now run the following the curl command. Replace access_token with your personal access token and namespace_id with the one you have created at the first step.
curl -X PUT --location 'http://127.0.0.1:3000/api/v4/admin/zoekt/shards/0/indexed_namespaces/:namespace_id?access_token=#{access_token}'
  • Now verify again the counts of Search::Zoekt::EnabledNamespace and Search::Zoekt::Index. The count of Search::Zoekt::EnabledNamespace should be incremented by 1 but the count of Search::Zoekt::Index should remain the same.

Testing for DELETE endpoint

  • Create a new Zoekt node
node = Search::Zoekt::Node.last
node2 = Search::Zoekt::Node.create! index_base_url: node.index_base_url, search_base_url: node.search_base_url, uuid: SecureRandom.uuid
  • Create indices for a Search::Zoekt::EnabledNamespace
zoekt_enabled_namespace = Search::Zoekt::EnabledNamespace.last
Search::Zoekt::Index.create! zoekt_enabled_namespace_id: zoekt_enabled_namespace.id, zoekt_node_id: Search::Zoekt::Node.first.id, namespace_id: zoekt_enabled_namespace.namespace.id
Search::Zoekt::Index.create! zoekt_enabled_namespace_id: zoekt_enabled_namespace.id, zoekt_node_id: Search::Zoekt::Node.last.id, namespace_id: zoekt_enabled_namespace.namespace.id
  • Verify that the following count is 2
zoekt_enabled_namespace.indices.count
  • Now run the following curl command. Replace access_token with your personal access token and namespace_id with the one you have created at the first step.
curl -X DELETE --location 'http://127.0.0.1:3000/api/v4/admin/zoekt/shards/0/indexed_namespaces/:namespace_id?access_token=#{access_token}'
  • Now verify that the following counts are 0. Replace namespace_id with the one you created
Search::Zoekt::EnabledNamespace.where(root_namespace_id: "#{namespace_id}").count
Search::Zoekt::Index.where(namespace_id: "#{namespace_id}").count

Related to #436498 (closed)

Edited by Ravi Kumar

Merge request reports

Loading