Fix Commits in New Projects in New Groups with Namespace Storage Limits
What does this MR do and why?
When namespace storage limits are enabled, commits cannot be made to projects in new groups.
This fixes the issue.
Fixes https://gitlab.com/gitlab-org/gitlab/-/issues/365389
How to set up and validate locally
Enable Namespace Storage Limits
- Make sure the
automatic_purchased_storage_allocation
andenforce_namespace_storage_limit
application settings are both enabled (true
).
gitlabhq_development=# SELECT automatic_purchased_storage_allocation, enforce_namespace_storage_limit FROM application_settings;
automatic_purchased_storage_allocation | enforce_namespace_storage_limit
----------------------------------------+---------------------------------
t | t
(1 row)
gitlabhq_development=#
- Enable the
:namespace_storage_limit
,:enforce_storage_limit_for_paid
,:enforce_storage_limit_for_free
, and:namespace_storage_limit_bypass_date_check
feature flags in a rails console.
[1] pry(main)> [:namespace_storage_limit, :enforce_storage_limit_for_paid, :enforce_storage_limit_for_free, :namespace_storage_limit_bypass_date_check].map { |f| Feature.enable(f) }
[...]
[2] pry(main)>
- Apply the following patch to your local gitlab instance. This patch disables some caching around storage size and storage limits.
diff --git a/ee/app/models/ee/namespace/root_storage_size.rb b/ee/app/models/ee/namespace/root_storage_size.rb
index fd612db00ec..b37918bdfbc 100644
--- a/ee/app/models/ee/namespace/root_storage_size.rb
+++ b/ee/app/models/ee/namespace/root_storage_size.rb
@@ -26,16 +26,16 @@ def usage_ratio
end
def current_size
- @current_size ||= Rails.cache.fetch(['namespaces', root_namespace.id, CURRENT_SIZE_CACHE_KEY], expires_in: EXPIRATION_TIME) do
+ # @current_size ||= Rails.cache.fetch(['namespaces', root_namespace.id, CURRENT_SIZE_CACHE_KEY], expires_in: EXPIRATION_TIME) do
root_namespace.root_storage_statistics&.storage_size
- end
+ # end
end
def limit
- @limit ||= Rails.cache.fetch(['namespaces', root_namespace.id, LIMIT_CACHE_KEY], expires_in: EXPIRATION_TIME) do
+ # @limit ||= Rails.cache.fetch(['namespaces', root_namespace.id, LIMIT_CACHE_KEY], expires_in: EXPIRATION_TIME) do
root_namespace.actual_limits.storage_size_limit.megabytes +
root_namespace.additional_purchased_storage_size.megabytes
- end
+ # end
end
def remaining_storage_percentage
- Restart your GDK simulating saas mode with
$ GITLAB_SIMULATE_SAAS=1 gdk start
.
Before
These are the steps to replicate the issue described in https://gitlab.com/gitlab-org/gitlab/-/issues/365389.
- Enable namespace storage limits
- Create a new group.
- Create a project in the group. Make sure the "initialize with a readme" checkbox is checked.
- Observe that the project is not created with a readme.
- Try to make a commit via the Web IDE. Observe that a 500 error is returned.
-
git clone
the project. Create a commit and try to push the commit. The push is rejected with a 500 error. - Open a rails console and see that the group has no
root_storage_statistics
withGroup.find(id).root_storage_statistics
.
After
This is the correct behavior after the fix in this MR.
- Enable namespace storage limits
- Create a new group.
- Create a project in the group. Make sure the "initialize with a readme" checkbox is checked.
- Observe that the project is created with a readme.
- Try to make a commit via the Web IDE. Observe that this works.
-
git clone
the project. Create a commit and try to push the commit. The push is accepted. - Open a rails console and see that the group has a
root_storage_statistics
withGroup.find(id).root_storage_statistics
.
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 Jason Goodman