Expire the add-on cache on assignment change
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
- Enable the code suggestions API FF
Feature.enable(:code_suggestions_completion_api)
- Enable the code suggestions purchase FF
::Feature.enable(:purchase_code_suggestions)
- Enable the code suggestions assignment FF
::Feature.enable(:code_suggestions_user_assignments)
- Enable code suggestions in your GDK user's profile (http://localhost:3000/-/profile/preferences)
- Enable code suggestions for a group that user is a member of (http://localhost:3000/groups/group-path/-/edit)
- Purchase an Ultimate or Premium subscription for the namespace
- 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')
- Make a request to the code suggestions endpoint
- Expected response
{"message":"404 Not Found"}%
(user does not have access to the add-on)
- Expected response
- Assign your user the add-on (http://localhost:3000/groups/group-path/-/usage_quotas#code-suggestions-usage-tab)
- 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"
)
- Expected response
- Un-assign the add-on (http://localhost:3000/groups/group-path/-/usage_quotas#code-suggestions-usage-tab)
- 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.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Josianne Hyson