Skip to content

Expire the add-on cache on assignment change

Josianne Hyson requested to merge jh/expire_cache_for_add_on_assignment into master

What does this MR do and why?

Addresses: https://gitlab.com/gitlab-org/gitlab/-/issues/430937+

Expire the add-on cache on assignment change

When the user's add-on assignment state changes we want to expire the cache key that's used in the API. This allows the user to immediately gain or lose access when their assignment state changes. Previously, this could have taken up to an hour to refresh.

How to set up and validate locally

Start the GDK and CustomersDot

  1. Enable the code suggestions API FF Feature.enable(:code_suggestions_completion_api)
  2. Enable the code suggestions purchase FF ::Feature.enable(:purchase_code_suggestions)
  3. Enable the code suggestions assignment FF ::Feature.enable(:code_suggestions_user_assignments)
  4. Enable code suggestions in your GDK user's profile (http://localhost:3000/-/profile/preferences)
  5. Enable code suggestions for a group that user is a member of (http://localhost:3000/groups/group-path/-/edit)
  6. Purchase an Ultimate or Premium subscription for the namespace
  7. Create an add-on purchase for the namespace
    GitlabSubscriptions::AddOnPurchase.create!(add_on: GitlabSubscriptions::AddOn.find_or_create_by!(name: :code_suggestions), namespace: <namespace-id>, expires_on: 1.year.from_now, quantity: 10, purchase_xid: 'A-1234')
  8. Make a request to the code suggestions endpoint
    • Expected response {"message":"404 Not Found"}% (user does not have access to the add-on)
  9. Assign your user the add-on (http://localhost:3000/groups/group-path/-/usage_quotas#code-suggestions-usage-tab)
  10. Make a request to the code suggestions endpoint
    • Expected response {"error":"Forbidden by auth provider"}% (it fails trying to make the request to "https://codesuggestions.gitlab.com/v2/code/completions")
  11. Un-assign the add-on (http://localhost:3000/groups/group-path/-/usage_quotas#code-suggestions-usage-tab)
  12. Make a request to the code suggestions endpoint
  • Expected response {"message":"404 Not Found"}% (user does not have access to the add-on)

Example code suggestions endpoint request:

curl --request POST --header "PRIVATE-TOKEN: <PERSONAL-ACCESS-TOKEN>" --header 'Content-Type: application/json' --data '{"prompt_version":"1","current_file":{"file_name":"dog.js","content_above_cursor":"class Car:\n    def __init__(self, make, model, year, color):\n        self.make = make\n        self.model = model\n        self.year = year\n        self.color = color\n        self.is_running = False\n        self.speed = 0\n    \n    def start(self):\n        if not self.is_running:\n            self.is_running = True\n            print(\"The car is now running.\")\n        else:\n            print(\"The car is already running.\")\n    \n    def stop(self):\n        if self.is_running:\n            self.is_running = False\n            self.speed = 0\n            print(\"The car has stopped.\")\n        else:\n            print(\"The car is already stopped.\")\n    \n    def accelerate(self, increment):","content_below_cursor":""},"project_id":"23"}' http://localhost:3000/api/v4/code_suggestions/completions

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 Josianne Hyson

Merge request reports