Skip to content

Fix user search for code suggestions

Mohamed Hamda requested to merge fix-user-search-curor-conditions into master

What does this MR do and why?

This merge request addresses issues outlined in https://gitlab.com/gitlab-org/gitlab/-/issues/431986 and https://gitlab.com/gitlab-org/gitlab/-/issues/434287.

Bug Cause:

  • The identified bug stems from the fact that the current keyset connection did not take into account the scopes for search.
  • I created an issue to check the problem with our GraphQL keyset pagination, but this should not block anything.

In this merge request, we are changing to use offset_pagination:

  • We apply the offset_pagination to rectify the issue.
  • Include test cases to encompass the resolution of both bugs.

Notes:

In the GraphQL library for offset pagination (see: GraphQL ActiveRecord Relation Connection), there is no default order by clause. Previously, using the keyset pagination we used to order the results by id in descending order. The switch to using offset pagination has introduced ordering issues.

To address this, I am reintroducing a default ordering by id in descending order within the query. This mirrors the previous behavior observed with keyset pagination.

How to set up and validate locally

Green specs may suffice, but please review this branch to confirm that the bug no longer occurs in either of the two scenarios.

Detailed test cases

Ensure the bug is resolved for SaaS:

  • GITLAB_SIMULATE_SAAS=1 rails c
  • Feature.enable(:hamilton_seat_management)
  • GitlabSubscriptions::AddOnPurchase.destroy_all
add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
add_on_purchase = GitlabSubscriptions::AddOnPurchase.create!(A-S0001'
  add_on: add_on, expires_on: 1.month.from_now, quantity: 5, namespace: namespace, purchase_xid: 'A-S0001'
)
add_on_purchase_id = add_on_purchase.to_global_id.to_s
  • Run a SaaS server gdk stop rails-web && GITLAB_RAILS_RACK_TIMEOUT_ENABLE_LOGGING=false PUMA_SINGLE_MODE=true GITLAB_SIMULATE_SAAS=1 gdk rails s
  • Fetch eligible users, go to http://gdk.test:3000/-/graphql-explorer and run:

Validate that the issue is also resolved for SaaS:

{
  namespace(fullPath: "<GROUP-FULL-PATH>") {
    addOnEligibleUsers(addOnType: CODE_SUGGESTIONS, search: "Test") {
      nodes {
        id
        username
        name
        publicEmail
        avatarUrl
        webUrl
        lastActivityOn
        lastLoginAt
        addOnAssignments(
          addOnPurchaseIds: ["gid://gitlab/GitlabSubscriptions::AddOnPurchase/<ADD-ON-PURCHASE-ID>"]
        ) {
          nodes {
            addOnPurchase {
              name
            }
          }
        }
      }
    }
  }
}

Ensure the bug is resolved for Self-managed setup:

  • GITLAB_SIMULATE_SAAS=0 rails c
  • Feature.enable(:self_managed_code_suggestions)
  • GitlabSubscriptions::AddOnPurchase.destroy_all
add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
add_on_purchase = GitlabSubscriptions::AddOnPurchase.create!(A-S0001'
  add_on: add_on, expires_on: 1.month.from_now, quantity: 5, purchase_xid: 'A-S0001'
) # No Namespace to simulate SM
add_on_purchase_id = add_on_purchase.to_global_id.to_s
  • Run a SM server gdk stop rails-web && GITLAB_RAILS_RACK_TIMEOUT_ENABLE_LOGGING=false PUMA_SINGLE_MODE=true GITLAB_SIMULATE_SAAS=0 gdk rails s
  • Fetch eligible users, go to http://gdk.test:3000/-/graphql-explorer and run:

Validate that the issue is also resolved for self-managed instances by following the steps outlined in https://gitlab.com/gitlab-org/gitlab/-/issues/434287#steps-to-reproduce.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Mohamed Hamda

Merge request reports