Skip to content

Fix Commits in New Projects in New Groups with Namespace Storage Limits

Jason Goodman requested to merge fix-new-group-nss-enabled-no-commits into master

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

  1. Make sure the automatic_purchased_storage_allocation and enforce_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=# 
  1. 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)> 
  1. 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
  1. 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.

  1. Enable namespace storage limits
  2. Create a new group.
  3. Create a project in the group. Make sure the "initialize with a readme" checkbox is checked.
  4. Observe that the project is not created with a readme.
  5. Try to make a commit via the Web IDE. Observe that a 500 error is returned.
  6. git clone the project. Create a commit and try to push the commit. The push is rejected with a 500 error.
  7. Open a rails console and see that the group has no root_storage_statistics with Group.find(id).root_storage_statistics.

After

This is the correct behavior after the fix in this MR.

  1. Enable namespace storage limits
  2. Create a new group.
  3. Create a project in the group. Make sure the "initialize with a readme" checkbox is checked.
  4. Observe that the project is created with a readme.
  5. Try to make a commit via the Web IDE. Observe that this works.
  6. git clone the project. Create a commit and try to push the commit. The push is accepted.
  7. Open a rails console and see that the group has a root_storage_statistics with Group.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.

Edited by Jason Goodman

Merge request reports