From d8ebc429dc8f199c8642ffb3d61875f8fc7f0197 Mon Sep 17 00:00:00 2001 From: Allison Browne <abrowne@gitlab.com> Date: Mon, 16 May 2022 10:57:47 +0000 Subject: [PATCH] Rename from Ci::Minutes::Quota to Ci::Minutes::Usage --- .rubocop_todo/layout/hash_alignment.yml | 2 +- app/helpers/namespaces_helper.rb | 2 +- ee/app/helpers/ee/namespaces_helper.rb | 14 ++-- ee/app/models/ci/minutes/context.rb | 6 +- ee/app/models/ci/minutes/notification.rb | 2 +- .../models/ci/minutes/{quota.rb => usage.rb} | 12 +-- ee/app/models/ee/ci/pending_build.rb | 2 +- ee/app/models/ee/ci/runner.rb | 2 +- ee/app/models/ee/namespace.rb | 8 +- ee/app/models/ee/project.rb | 10 +-- ee/app/models/ee/user.rb | 4 +- ee/app/policies/ee/group_policy.rb | 2 +- ee/app/policies/ee/project_policy.rb | 2 +- ...{quota_presenter.rb => usage_presenter.rb} | 34 ++++----- ee/app/serializers/ee/build_detail_entity.rb | 4 +- .../ci/minutes/refresh_cached_data_service.rb | 2 +- .../ee/ci/queue/build_queue_service.rb | 4 +- .../ee/ci/queue/pending_builds_strategy.rb | 2 +- .../projects/_shared_runner_status.html.haml | 2 +- .../_additional_minutes_status.html.haml | 10 +-- .../_shared_runner_status.html.haml | 8 +- ...tra_shared_runners_minutes_quota.html.haml | 12 +-- .../namespaces/pipelines_quota/_list.haml | 18 ++--- .../ee/gitlab/ci/matching/runner_matcher.rb | 2 +- ee/lib/gitlab/ci/minutes/cached_quota.rb | 2 +- ee/lib/gitlab/ci/minutes/cost_factor.rb | 2 +- ee/spec/features/admin/admin_groups_spec.rb | 58 +++++++++++++++ .../admin_reset_pipeline_minutes_spec.rb | 6 +- .../ci_shared_runner_warnings_spec.rb | 4 +- ee/spec/helpers/ee/namespaces_helper_spec.rb | 25 ++++--- .../gitlab/ci/matching/runner_matcher_spec.rb | 4 +- .../ci/minutes/runners_availability_spec.rb | 4 +- .../minutes/namespace_monthly_usage_spec.rb | 2 +- .../minutes/{quota_spec.rb => usage_spec.rb} | 74 +++++++++++++------ ee/spec/models/ee/ci/pending_build_spec.rb | 2 +- ee/spec/models/ee/ci/runner_spec.rb | 4 +- ee/spec/models/ee/user_spec.rb | 4 +- ee/spec/models/project_spec.rb | 6 +- ee/spec/policies/group_policy_spec.rb | 4 +- ee/spec/policies/project_policy_spec.rb | 4 +- ...senter_spec.rb => usage_presenter_spec.rb} | 24 +++--- ee/spec/requests/api/namespaces_spec.rb | 2 +- .../refresh_cached_data_service_spec.rb | 2 +- .../track_live_consumption_service_spec.rb | 4 +- .../drop_not_runnable_builds_service_spec.rb | 8 +- spec/helpers/namespaces_helper_spec.rb | 4 +- 46 files changed, 250 insertions(+), 165 deletions(-) rename ee/app/models/ci/minutes/{quota.rb => usage.rb} (88%) rename ee/app/presenters/ci/minutes/{quota_presenter.rb => usage_presenter.rb} (51%) create mode 100644 ee/spec/features/admin/admin_groups_spec.rb rename ee/spec/models/ci/minutes/{quota_spec.rb => usage_spec.rb} (77%) rename ee/spec/presenters/ci/minutes/{quota_presenter_spec.rb => usage_presenter_spec.rb} (93%) diff --git a/.rubocop_todo/layout/hash_alignment.yml b/.rubocop_todo/layout/hash_alignment.yml index 137f6cb7a0592..79527f794e93f 100644 --- a/.rubocop_todo/layout/hash_alignment.yml +++ b/.rubocop_todo/layout/hash_alignment.yml @@ -337,7 +337,7 @@ Layout/HashAlignment: - 'ee/app/helpers/ee/feature_flags_helper.rb' - 'ee/app/helpers/ee/sorting_helper.rb' - 'ee/app/models/allowed_email_domain.rb' - - 'ee/app/models/ci/minutes/quota.rb' + - 'ee/app/models/ci/minutes/usage.rb' - 'ee/app/models/ee/application_setting.rb' - 'ee/app/models/elastic/reindexing_task.rb' - 'ee/app/models/gitlab_subscriptions/features.rb' diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index 8914c974f6cd4..a50629b799616 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -88,7 +88,7 @@ def namespaces_as_json(selected = :current_user) }.to_json end - def pipeline_usage_quota_app_data(namespace) + def pipeline_usage_app_data(namespace) { namespace_actual_plan_name: namespace.actual_plan_name, namespace_path: namespace.full_path, diff --git a/ee/app/helpers/ee/namespaces_helper.rb b/ee/app/helpers/ee/namespaces_helper.rb index c6f3e49e6d4be..3760a75c431e5 100644 --- a/ee/app/helpers/ee/namespaces_helper.rb +++ b/ee/app/helpers/ee/namespaces_helper.rb @@ -4,9 +4,9 @@ module EE module NamespacesHelper extend ::Gitlab::Utils::Override - def ci_minutes_report(quota_report) - content_tag(:span, class: "shared_runners_limit_#{quota_report.status}") do - "#{quota_report.used} / #{quota_report.limit}" + def ci_minutes_report(usage_report) + content_tag(:span, class: "shared_runners_limit_#{usage_report.status}") do + "#{usage_report.used} / #{usage_report.limit}" end end @@ -67,15 +67,15 @@ def show_minute_limit_banner?(namespace) namespace.root_ancestor.free_plan? && !minute_limit_banner_dismissed? end - override :pipeline_usage_quota_app_data - def pipeline_usage_quota_app_data(namespace) + override :pipeline_usage_app_data + def pipeline_usage_app_data(namespace) return super unless ::Gitlab::CurrentSettings.should_check_namespace_plan? - minutes_quota_presenter = ::Ci::Minutes::QuotaPresenter.new(namespace.ci_minutes_quota) + minutes_usage_presenter = ::Ci::Minutes::UsagePresenter.new(namespace.ci_minutes_usage) super.merge( ci_minutes: { - any_project_enabled: minutes_quota_presenter.any_project_enabled?.to_s + any_project_enabled: minutes_usage_presenter.any_project_enabled?.to_s }, buy_additional_minutes_path: buy_additional_minutes_path(namespace), buy_additional_minutes_target: buy_addon_target_attr(namespace) diff --git a/ee/app/models/ci/minutes/context.rb b/ee/app/models/ci/minutes/context.rb index bda8cebf305a1..c361eb1338d9c 100644 --- a/ee/app/models/ci/minutes/context.rb +++ b/ee/app/models/ci/minutes/context.rb @@ -13,13 +13,13 @@ def initialize(project, namespace) end def percent_total_minutes_remaining - quota.percent_total_minutes_remaining + usage.percent_total_minutes_remaining end private - def quota - @quota ||= ::Ci::Minutes::Quota.new(namespace) + def usage + @usage ||= ::Ci::Minutes::Usage.new(namespace) end end end diff --git a/ee/app/models/ci/minutes/notification.rb b/ee/app/models/ci/minutes/notification.rb index c4913ffa6a591..aa2f52ae0d4d1 100644 --- a/ee/app/models/ci/minutes/notification.rb +++ b/ee/app/models/ci/minutes/notification.rb @@ -20,7 +20,7 @@ def show?(current_user, cookies = false) return false unless @context.namespace return false if alert_has_been_dismissed?(cookies) - Ability.allowed?(current_user, :read_ci_minutes_quota, @context.namespace) + Ability.allowed?(current_user, :read_ci_minutes_usage, @context.namespace) end def text diff --git a/ee/app/models/ci/minutes/quota.rb b/ee/app/models/ci/minutes/usage.rb similarity index 88% rename from ee/app/models/ci/minutes/quota.rb rename to ee/app/models/ci/minutes/usage.rb index 2f983b3ab3951..189bd2cc3a82a 100644 --- a/ee/app/models/ci/minutes/quota.rb +++ b/ee/app/models/ci/minutes/usage.rb @@ -6,7 +6,7 @@ module Ci module Minutes - class Quota + class Usage include Gitlab::Utils::StrongMemoize attr_reader :namespace, :limit @@ -16,16 +16,16 @@ def initialize(namespace) @limit = ::Ci::Minutes::Limit.new(namespace) end - def enabled? + def limit_enabled? limit.enabled? end def minutes_used_up? - enabled? && total_minutes_used >= limit.total + limit_enabled? && total_minutes_used >= limit.total end def percent_total_minutes_remaining - return 0 unless limit.enabled? + return 0 unless limit_enabled? 100 * total_minutes_remaining.to_i / limit.total end @@ -44,7 +44,7 @@ def reset_date # === private to view === def monthly_minutes_used_up? - return false unless enabled? + return false unless limit_enabled? monthly_minutes_used >= limit.monthly end @@ -54,7 +54,7 @@ def monthly_minutes_used end def purchased_minutes_used_up? - return false unless enabled? + return false unless limit_enabled? limit.any_purchased? && purchased_minutes_used >= limit.purchased end diff --git a/ee/app/models/ee/ci/pending_build.rb b/ee/app/models/ee/ci/pending_build.rb index a9f4466efd51a..d3e91104c1d74 100644 --- a/ee/app/models/ee/ci/pending_build.rb +++ b/ee/app/models/ee/ci/pending_build.rb @@ -23,7 +23,7 @@ def args_from_build(build) def minutes_exceeded?(project) ::Ci::Runner.any_shared_runners_with_enabled_cost_factor?(project) && - project.ci_minutes_quota.minutes_used_up? + project.ci_minutes_usage.minutes_used_up? end end end diff --git a/ee/app/models/ee/ci/runner.rb b/ee/app/models/ee/ci/runner.rb index 18ac0bd968528..5d6b81a350e1c 100644 --- a/ee/app/models/ee/ci/runner.rb +++ b/ee/app/models/ee/ci/runner.rb @@ -27,7 +27,7 @@ def cost_factor_enabled?(project) # TODO: remove this method when ci_queuing_use_denormalized_data_strategy # feature flag is removed - def visibility_levels_without_minutes_quota + def visibility_levels_without_minutes_usage ::Gitlab::VisibilityLevel.options.values.reject do |visibility_level| cost_factor.for_visibility(visibility_level) > 0 end diff --git a/ee/app/models/ee/namespace.rb b/ee/app/models/ee/namespace.rb index 9668e6aa0c3e3..1eb53af94e816 100644 --- a/ee/app/models/ee/namespace.rb +++ b/ee/app/models/ee/namespace.rb @@ -251,15 +251,15 @@ def sync_membership_lock_with_parent end end - def ci_minutes_quota - strong_memoize(:ci_minutes_quota) do - ::Ci::Minutes::Quota.new(self) + def ci_minutes_usage + strong_memoize(:ci_minutes_usage) do + ::Ci::Minutes::Usage.new(self) end end # The same method name is used also at project level def shared_runners_minutes_limit_enabled? - any_project_with_shared_runners_enabled? && ci_minutes_quota.enabled? + any_project_with_shared_runners_enabled? && ci_minutes_usage.limit_enabled? end def any_project_with_shared_runners_enabled? diff --git a/ee/app/models/ee/project.rb b/ee/app/models/ee/project.rb index acee2c023117f..e45d3bbf176c9 100644 --- a/ee/app/models/ee/project.rb +++ b/ee/app/models/ee/project.rb @@ -192,7 +192,7 @@ def lock_for_confirmation!(id) delegate :shared_runners_seconds, to: :statistics, allow_nil: true - delegate :ci_minutes_quota, to: :shared_runners_limit_namespace + delegate :ci_minutes_usage, to: :shared_runners_limit_namespace delegate :merge_pipelines_enabled, :merge_pipelines_enabled=, to: :ci_cd_settings, allow_nil: true delegate :merge_trains_enabled, :merge_trains_enabled=, to: :ci_cd_settings, allow_nil: true @@ -367,11 +367,11 @@ def can_override_approvers? end def ci_minutes_used - ci_minutes_usage.amount_used.to_i + ci_minutes_project_usage.amount_used.to_i end def shared_runners_available? - super && !ci_minutes_quota.minutes_used_up? + super && !ci_minutes_usage.minutes_used_up? end def link_pool_repository @@ -867,8 +867,8 @@ def inactive? private - def ci_minutes_usage - strong_memoize(:ci_minutes_usage) do + def ci_minutes_project_usage + strong_memoize(:ci_minutes_project_usage) do ::Ci::Minutes::ProjectMonthlyUsage.find_or_create_current(project_id: id) end end diff --git a/ee/app/models/ee/user.rb b/ee/app/models/ee/user.rb index acfea56a87495..5125dcd78b946 100644 --- a/ee/app/models/ee/user.rb +++ b/ee/app/models/ee/user.rb @@ -465,9 +465,9 @@ def requires_credit_card?(project) return false unless created_after_credit_card_release_day?(project) root_namespace = project.root_namespace - ci_quota = root_namespace.ci_minutes_quota + ci_usage = root_namespace.ci_minutes_usage - return false if ci_quota.enabled? && ci_quota.limit.any_purchased? + return false if ci_usage.limit_enabled? && ci_usage.limit.any_purchased? if root_namespace.free_plan? ::Feature.enabled?(:ci_require_credit_card_on_free_plan, project) diff --git a/ee/app/policies/ee/group_policy.rb b/ee/app/policies/ee/group_policy.rb index 99570183c5a42..ddc3780f29e4a 100644 --- a/ee/app/policies/ee/group_policy.rb +++ b/ee/app/policies/ee/group_policy.rb @@ -333,7 +333,7 @@ module GroupPolicy enable :read_group_compliance_dashboard enable :read_group_credentials_inventory enable :admin_group_credentials_inventory - enable :read_ci_minutes_quota + enable :read_ci_minutes_usage end rule { (admin | owner) & group_merge_request_approval_settings_enabled }.policy do diff --git a/ee/app/policies/ee/project_policy.rb b/ee/app/policies/ee/project_policy.rb index e47b82cde9f73..b3f62ecdc4c97 100644 --- a/ee/app/policies/ee/project_policy.rb +++ b/ee/app/policies/ee/project_policy.rb @@ -188,7 +188,7 @@ module ProjectPolicy end rule { can?(:owner_access) }.policy do - enable :read_ci_minutes_quota + enable :read_ci_minutes_usage end rule { can?(:reporter_access) & iterations_available }.policy do diff --git a/ee/app/presenters/ci/minutes/quota_presenter.rb b/ee/app/presenters/ci/minutes/usage_presenter.rb similarity index 51% rename from ee/app/presenters/ci/minutes/quota_presenter.rb rename to ee/app/presenters/ci/minutes/usage_presenter.rb index 244a0e34dc494..0359128abd64e 100644 --- a/ee/app/presenters/ci/minutes/quota_presenter.rb +++ b/ee/app/presenters/ci/minutes/usage_presenter.rb @@ -2,65 +2,65 @@ module Ci module Minutes - class QuotaPresenter < Gitlab::View::Presenter::Simple + class UsagePresenter < Gitlab::View::Presenter::Simple include Gitlab::Utils::StrongMemoize - presents Quota, as: :quota + presents Usage, as: :usage Report = Struct.new(:used, :limit, :status) # Status of the monthly allowance being used. def monthly_minutes_report - Report.new(quota.monthly_minutes_used, minutes_limit, report_status) + Report.new(usage.monthly_minutes_used, minutes_limit, report_status) end def monthly_percent_used - return 0 unless quota.enabled? - return 0 if quota.limit.monthly == 0 + return 0 unless usage.limit_enabled? + return 0 if usage.limit.monthly == 0 - 100 * quota.monthly_minutes_used.to_i / quota.limit.monthly + 100 * usage.monthly_minutes_used.to_i / usage.limit.monthly end # Status of any purchased minutes used. def purchased_minutes_report - status = quota.purchased_minutes_used_up? ? :over_quota : :under_quota - Report.new(quota.purchased_minutes_used, quota.limit.purchased, status) + status = usage.purchased_minutes_used_up? ? :over_quota : :under_quota + Report.new(usage.purchased_minutes_used, usage.limit.purchased, status) end def purchased_percent_used - return 0 unless quota.enabled? - return 0 unless quota.limit.any_purchased? + return 0 unless usage.limit_enabled? + return 0 unless usage.limit.any_purchased? - 100 * quota.purchased_minutes_used.to_i / quota.limit.purchased + 100 * usage.purchased_minutes_used.to_i / usage.limit.purchased end def display_minutes_available_data? - display_shared_runners_data? && quota.limit.enabled? + display_shared_runners_data? && usage.limit_enabled? end def display_shared_runners_data? - quota.namespace.root? && any_project_enabled? + usage.namespace.root? && any_project_enabled? end def any_project_enabled? strong_memoize(:any_project_enabled) do - quota.namespace.any_project_with_shared_runners_enabled? + usage.namespace.any_project_with_shared_runners_enabled? end end private def report_status - return :disabled unless quota.enabled? + return :disabled unless usage.limit_enabled? - quota.monthly_minutes_used_up? ? :over_quota : :under_quota + usage.monthly_minutes_used_up? ? :over_quota : :under_quota end def minutes_limit return _('Not supported') unless display_shared_runners_data? if display_minutes_available_data? - quota.limit.monthly + usage.limit.monthly else _('Unlimited') end diff --git a/ee/app/serializers/ee/build_detail_entity.rb b/ee/app/serializers/ee/build_detail_entity.rb index 82680e93fc05d..6a21b5410584d 100644 --- a/ee/app/serializers/ee/build_detail_entity.rb +++ b/ee/app/serializers/ee/build_detail_entity.rb @@ -8,11 +8,11 @@ module BuildDetailEntity expose :runners do expose :quota, if: -> (*) { project.shared_runners_minutes_limit_enabled? } do expose :used do |runner| - project.ci_minutes_quota.total_minutes_used + project.ci_minutes_usage.total_minutes_used end expose :limit do |runner| - project.ci_minutes_quota.limit.total + project.ci_minutes_usage.limit.total end end end diff --git a/ee/app/services/ci/minutes/refresh_cached_data_service.rb b/ee/app/services/ci/minutes/refresh_cached_data_service.rb index 3206262589546..ea220bdb90858 100644 --- a/ee/app/services/ci/minutes/refresh_cached_data_service.rb +++ b/ee/app/services/ci/minutes/refresh_cached_data_service.rb @@ -29,7 +29,7 @@ def reset_ci_minutes_cache! def update_pending_builds! return unless ::Ci::PendingBuild.maintain_denormalized_data? - minutes_exceeded = @root_namespace.ci_minutes_quota.minutes_used_up? + minutes_exceeded = @root_namespace.ci_minutes_usage.minutes_used_up? all_namespace_ids = @root_namespace.self_and_descendant_ids.ids all_namespace_ids.in_groups_of(BATCH_SIZE, minutes_exceeded) do |namespace_ids| diff --git a/ee/app/services/ee/ci/queue/build_queue_service.rb b/ee/app/services/ee/ci/queue/build_queue_service.rb index 5a5770e3ae7db..2edacd7af4b1e 100644 --- a/ee/app/services/ee/ci/queue/build_queue_service.rb +++ b/ee/app/services/ee/ci/queue/build_queue_service.rb @@ -20,7 +20,7 @@ def builds_for_shared_runner # rubocop: disable CodeReuse/ActiveRecord def enforce_minutes_based_on_cost_factors(relation) if strategy.use_denormalized_data_strategy? - strategy.enforce_minutes_quota(relation) + strategy.enforce_minutes_limit(relation) else enforce_minutes_using_legacy_data(relation) end @@ -35,7 +35,7 @@ def enforce_minutes_using_legacy_data(relation) end visibility_relation = ::CommitStatus.where( - projects: { visibility_level: runner.visibility_levels_without_minutes_quota }) + projects: { visibility_level: runner.visibility_levels_without_minutes_usage }) enforce_limits_relation = ::CommitStatus.where('EXISTS (?)', builds_check_limit) diff --git a/ee/app/services/ee/ci/queue/pending_builds_strategy.rb b/ee/app/services/ee/ci/queue/pending_builds_strategy.rb index 9ce511bec69cf..23bf8f461abab 100644 --- a/ee/app/services/ee/ci/queue/pending_builds_strategy.rb +++ b/ee/app/services/ee/ci/queue/pending_builds_strategy.rb @@ -6,7 +6,7 @@ module Queue module PendingBuildsStrategy extend ActiveSupport::Concern - def enforce_minutes_quota(relation) + def enforce_minutes_limit(relation) relation.with_ci_minutes_available end end diff --git a/ee/app/views/admin/projects/_shared_runner_status.html.haml b/ee/app/views/admin/projects/_shared_runner_status.html.haml index 3e10f20463a11..aa1027308f040 100644 --- a/ee/app/views/admin/projects/_shared_runner_status.html.haml +++ b/ee/app/views/admin/projects/_shared_runner_status.html.haml @@ -5,7 +5,7 @@ - if project.shared_runners_enabled? Enabled - if project.shared_runners_minutes_limit_enabled? - - limit = project.ci_minutes_quota.limit.total + - limit = project.ci_minutes_usage.limit.total (Limited to #{limit} pipeline minutes per month) - else (Unlimited pipeline minutes) diff --git a/ee/app/views/namespaces/_additional_minutes_status.html.haml b/ee/app/views/namespaces/_additional_minutes_status.html.haml index 70e27b377d251..8a7cf9fdf736f 100644 --- a/ee/app/views/namespaces/_additional_minutes_status.html.haml +++ b/ee/app/views/namespaces/_additional_minutes_status.html.haml @@ -1,13 +1,13 @@ - return unless Gitlab.com? - namespace = local_assigns.fetch(:namespace) -- minutes_quota = namespace.ci_minutes_quota -- minutes_quota_presenter = Ci::Minutes::QuotaPresenter.new(minutes_quota) -- return unless minutes_quota.enabled? +- minutes_usage = namespace.ci_minutes_usage +- minutes_usage_presenter = Ci::Minutes::UsagePresenter.new(minutes_usage) +- return unless minutes_usage.limit_enabled? -- if minutes_quota_presenter.display_shared_runners_data? +- if minutes_usage_presenter.display_shared_runners_data? %li %span.light= _('Additional minutes:') %strong - = ci_minutes_report(minutes_quota_presenter.purchased_minutes_report) + = ci_minutes_report(minutes_usage_presenter.purchased_minutes_report) diff --git a/ee/app/views/namespaces/_shared_runner_status.html.haml b/ee/app/views/namespaces/_shared_runner_status.html.haml index cb99645a50ae2..f524907ddafbd 100644 --- a/ee/app/views/namespaces/_shared_runner_status.html.haml +++ b/ee/app/views/namespaces/_shared_runner_status.html.haml @@ -1,10 +1,10 @@ - namespace = local_assigns.fetch(:namespace) -- minutes_quota = namespace.ci_minutes_quota -- minutes_quota_presenter = Ci::Minutes::QuotaPresenter.new(minutes_quota) +- minutes_usage = namespace.ci_minutes_usage +- minutes_usage_presenter = Ci::Minutes::UsagePresenter.new(minutes_usage) -- if minutes_quota_presenter.display_shared_runners_data? +- if minutes_usage_presenter.display_shared_runners_data? %li %span.light= _('Quota of CI/CD minutes:') %strong - = ci_minutes_report(minutes_quota_presenter.monthly_minutes_report) + = ci_minutes_report(minutes_usage_presenter.monthly_minutes_report) = link_to sprite_icon('question-o'), help_page_path('ci/pipelines/cicd_minutes'), target: '_blank', rel: 'noopener noreferrer' diff --git a/ee/app/views/namespaces/pipelines_quota/_extra_shared_runners_minutes_quota.html.haml b/ee/app/views/namespaces/pipelines_quota/_extra_shared_runners_minutes_quota.html.haml index 76139e6ce8481..0994f55a7be1f 100644 --- a/ee/app/views/namespaces/pipelines_quota/_extra_shared_runners_minutes_quota.html.haml +++ b/ee/app/views/namespaces/pipelines_quota/_extra_shared_runners_minutes_quota.html.haml @@ -1,17 +1,17 @@ - return unless Gitlab.com? -- minutes_quota = namespace.ci_minutes_quota -- minutes_quota_presenter = Ci::Minutes::QuotaPresenter.new(minutes_quota) -- return unless minutes_quota_presenter.display_minutes_available_data? && minutes_quota_presenter.purchased_minutes_report.limit > 0 +- minutes_usage = namespace.ci_minutes_usage +- minutes_usage_presenter = Ci::Minutes::UsagePresenter.new(minutes_usage) +- return unless minutes_usage_presenter.display_minutes_available_data? && minutes_usage_presenter.purchased_minutes_report.limit > 0 .row .col-sm-6 %strong = _("Additional minutes") %div{ data: { qa_selector: "additional_ci_minutes" } } - = ci_minutes_report(minutes_quota_presenter.purchased_minutes_report) + = ci_minutes_report(minutes_usage_presenter.purchased_minutes_report) minutes = link_to sprite_icon('question-o'), help_page_path('ci/pipelines/cicd_minutes', anchor: 'purchase-additional-cicd-minutes-free-saas'), target: '_blank', rel: 'noopener noreferrer' .col-sm-6.right - #{minutes_quota_presenter.purchased_percent_used}% used - = ci_minutes_progress_bar(minutes_quota_presenter.purchased_percent_used) + #{minutes_usage_presenter.purchased_percent_used}% used + = ci_minutes_progress_bar(minutes_usage_presenter.purchased_percent_used) diff --git a/ee/app/views/namespaces/pipelines_quota/_list.haml b/ee/app/views/namespaces/pipelines_quota/_list.haml index 7a6d6a9d11798..73d89ba68ee98 100644 --- a/ee/app/views/namespaces/pipelines_quota/_list.haml +++ b/ee/app/views/namespaces/pipelines_quota/_list.haml @@ -1,7 +1,7 @@ - namespace = locals.fetch(:namespace) - projects = locals.fetch(:projects) -- minutes_quota = namespace.ci_minutes_quota -- minutes_quota_presenter = Ci::Minutes::QuotaPresenter.new(minutes_quota) +- minutes_usage = namespace.ci_minutes_usage +- minutes_usage_presenter = Ci::Minutes::UsagePresenter.new(minutes_usage) .pipeline-quota.container-fluid @@ -17,25 +17,25 @@ .row .col-sm-6 %strong - - last_reset = minutes_quota.reset_date + - last_reset = minutes_usage.reset_date - if last_reset = sprintf(s_('UsageQuota|CI/CD minutes usage since %{timeElapsed}'), { timeElapsed: last_reset.strftime('%b %d, %Y') }) - else = s_('UsageQuota|Current period usage') %div{ data: { qa_selector: "plan_ci_minutes" } } - = ci_minutes_report(minutes_quota_presenter.monthly_minutes_report) + = ci_minutes_report(minutes_usage_presenter.monthly_minutes_report) minutes = link_to sprite_icon('question-o'), help_page_path('ci/pipelines/cicd_minutes'), target: '_blank', 'aria-label': _('Shared runners help link') .col-sm-6.right - - if minutes_quota_presenter.display_minutes_available_data? - #{minutes_quota_presenter.monthly_percent_used}% used - - elsif !minutes_quota_presenter.any_project_enabled? + - if minutes_usage_presenter.display_minutes_available_data? + #{minutes_usage_presenter.monthly_percent_used}% used + - elsif !minutes_usage_presenter.any_project_enabled? 0% used - else = s_('UsageQuota|Unlimited') - = ci_minutes_progress_bar(minutes_quota_presenter.monthly_percent_used) + = ci_minutes_progress_bar(minutes_usage_presenter.monthly_percent_used) = render 'namespaces/pipelines_quota/extra_shared_runners_minutes_quota', namespace: namespace @@ -50,7 +50,7 @@ = s_('UsageQuota|CI/CD minutes usage') %tbody - - if !minutes_quota_presenter.any_project_enabled? + - if !minutes_usage_presenter.any_project_enabled? %tr %td{ colspan: 2 } .nothing-here-block diff --git a/ee/lib/ee/gitlab/ci/matching/runner_matcher.rb b/ee/lib/ee/gitlab/ci/matching/runner_matcher.rb index c178e65a38f09..51d98882fcd2c 100644 --- a/ee/lib/ee/gitlab/ci/matching/runner_matcher.rb +++ b/ee/lib/ee/gitlab/ci/matching/runner_matcher.rb @@ -26,7 +26,7 @@ def cost_factor def minutes_used_up?(build_matcher) build_matcher .project - .ci_minutes_quota + .ci_minutes_usage .minutes_used_up? end end diff --git a/ee/lib/gitlab/ci/minutes/cached_quota.rb b/ee/lib/gitlab/ci/minutes/cached_quota.rb index cd2d7de820f24..d0fdbac8bddf4 100644 --- a/ee/lib/gitlab/ci/minutes/cached_quota.rb +++ b/ee/lib/gitlab/ci/minutes/cached_quota.rb @@ -56,7 +56,7 @@ def cache_key private def uncached_current_balance - root_namespace.ci_minutes_quota.current_balance.to_f + root_namespace.ci_minutes_usage.current_balance.to_f end end end diff --git a/ee/lib/gitlab/ci/minutes/cost_factor.rb b/ee/lib/gitlab/ci/minutes/cost_factor.rb index 4c8ba675286e9..48d5a00d9d06e 100644 --- a/ee/lib/gitlab/ci/minutes/cost_factor.rb +++ b/ee/lib/gitlab/ci/minutes/cost_factor.rb @@ -25,7 +25,7 @@ def disabled?(project) def for_project(project) return DISABLED unless @runner_matcher.instance_type? - return DISABLED unless project.ci_minutes_quota.enabled? + return DISABLED unless project.ci_minutes_usage.limit_enabled? runner_cost_factor = for_visibility(project.visibility_level) diff --git a/ee/spec/features/admin/admin_groups_spec.rb b/ee/spec/features/admin/admin_groups_spec.rb new file mode 100644 index 0000000000000..8c6996c44e4f9 --- /dev/null +++ b/ee/spec/features/admin/admin_groups_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Admin Groups' do + include ::Ci::MinutesHelpers + + let_it_be(:group) { create :group } + let_it_be(:admin) { create(:admin) } + let_it_be(:project, reload: true) { create(:project, namespace: group) } + + before do + sign_in(admin) + gitlab_enable_admin_mode_sign_in(admin) + end + + describe 'show a group' do + context 'with minutes' do + before do + project.update!(shared_runners_enabled: true) + set_ci_minutes_used(group, 300) + group.update!(shared_runners_minutes_limit: 400) + end + + context 'when gitlab saas', :saas do + it 'renders minute report' do + visit admin_group_path(group) + + expect(page).to have_content('Quota of CI/CD minutes: 300 / 400') + end + + it 'renders additional minutes' do + group.update!(extra_shared_runners_minutes_limit: 100) + + visit admin_group_path(group) + + expect(page).to have_content('Additional minutes:') + end + end + + context 'when self-managed' do + it 'renders minute report' do + visit admin_group_path(group) + + expect(page).not_to have_content('Quota of CI/CD minutes: 300 / 400') + end + + it 'does not render additional minutes' do + group.update!(extra_shared_runners_minutes_limit: 100) + + visit admin_group_path(group) + + expect(page).not_to have_content('Additional minutes:') + end + end + end + end +end diff --git a/ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb b/ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb index e7669c9c399f8..737d63c66259c 100644 --- a/ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb +++ b/ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb @@ -28,9 +28,9 @@ expect(page).to have_selector('.gl-toast') expect(page).to have_current_path(%r(#{namespace.path}), ignore_query: true) - expect(namespace.reload.ci_minutes_quota.total_minutes_used).to eq(0) - expect(namespace.ci_minutes_quota.reset_date.month).to eq(time.month) - expect(namespace.ci_minutes_quota.reset_date.year).to eq(time.year) + expect(namespace.reload.ci_minutes_usage.total_minutes_used).to eq(0) + expect(namespace.ci_minutes_usage.reset_date.month).to eq(time.month) + expect(namespace.ci_minutes_usage.reset_date.year).to eq(time.year) end end end diff --git a/ee/spec/features/ci_shared_runner_warnings_spec.rb b/ee/spec/features/ci_shared_runner_warnings_spec.rb index 0994644a7c903..e767263d77f56 100644 --- a/ee/spec/features/ci_shared_runner_warnings_spec.rb +++ b/ee/spec/features/ci_shared_runner_warnings_spec.rb @@ -47,7 +47,7 @@ before do group.update!(shared_runners_minutes_limit: minutes_limit) - allow_any_instance_of(::Ci::Minutes::Quota).to receive(:total_minutes_used).and_return(minutes_used) + allow_any_instance_of(::Ci::Minutes::Usage).to receive(:total_minutes_used).and_return(minutes_used) end it 'displays a warning message on pipelines page' do @@ -147,7 +147,7 @@ before do group.update!(shared_runners_minutes_limit: minutes_limit) - allow_any_instance_of(::Ci::Minutes::Quota).to receive(:total_minutes_used).and_return(minutes_used) + allow_any_instance_of(::Ci::Minutes::Usage).to receive(:total_minutes_used).and_return(minutes_used) end it 'displays a warning message on group information page' do diff --git a/ee/spec/helpers/ee/namespaces_helper_spec.rb b/ee/spec/helpers/ee/namespaces_helper_spec.rb index 1812e38f3b1f4..4f3f9bc5bcf0a 100644 --- a/ee/spec/helpers/ee/namespaces_helper_spec.rb +++ b/ee/spec/helpers/ee/namespaces_helper_spec.rb @@ -41,13 +41,13 @@ end describe '#ci_minutes_report' do - let(:quota) { Ci::Minutes::Quota.new(user_group) } - let(:quota_presenter) { Ci::Minutes::QuotaPresenter.new(quota) } + let(:usage) { Ci::Minutes::Usage.new(user_group) } + let(:usage_presenter) { Ci::Minutes::UsagePresenter.new(usage) } describe 'rendering monthly minutes report' do - let(:report) { quota_presenter.monthly_minutes_report } + let(:report) { usage_presenter.monthly_minutes_report } - context "when ci minutes quota is not enabled" do + context "when ci minutes usage is not enabled" do before do user_group.update!(shared_runners_minutes_limit: 0) end @@ -88,7 +88,7 @@ end describe 'rendering purchased minutes report' do - let(:report) { Ci::Minutes::QuotaPresenter.new(quota).purchased_minutes_report } + let(:report) { usage_presenter.purchased_minutes_report } context 'when extra minutes are assigned' do before do @@ -275,31 +275,32 @@ end end - describe '#pipeline_usage_quota_app_data' do - context 'Gitlab SaaS', :saas do + describe '#pipeline_usage_app_data' do + context 'when gitlab sass', :saas do before do + allow(Gitlab).to receive(:com?).and_return(true) stub_ee_application_setting(should_check_namespace_plan: true) end it 'returns a hash with SaaS data' do - minutes_quota_presenter = ::Ci::Minutes::QuotaPresenter.new(user_group.ci_minutes_quota) + minutes_usage_presenter = ::Ci::Minutes::UsagePresenter.new(user_group.ci_minutes_usage) - expect(helper.pipeline_usage_quota_app_data(user_group)).to eql({ + expect(helper.pipeline_usage_app_data(user_group)).to eql({ namespace_actual_plan_name: user_group.actual_plan_name, namespace_path: user_group.full_path, namespace_id: user_group.id, user_namespace: user_group.user_namespace?.to_s, page_size: Kaminari.config.default_per_page, - ci_minutes: { any_project_enabled: minutes_quota_presenter.any_project_enabled?.to_s }, + ci_minutes: { any_project_enabled: minutes_usage_presenter.any_project_enabled?.to_s }, buy_additional_minutes_path: EE::SUBSCRIPTIONS_MORE_MINUTES_URL, buy_additional_minutes_target: '_blank' }) end end - context 'Gitlab Self-Managed' do + context 'when gitlab self managed' do it 'returns a hash without SaaS data' do - expect(helper.pipeline_usage_quota_app_data(user_group)).to eql({ + expect(helper.pipeline_usage_app_data(user_group)).to eql({ namespace_actual_plan_name: user_group.actual_plan_name, namespace_path: user_group.full_path, namespace_id: user_group.id, diff --git a/ee/spec/lib/ee/gitlab/ci/matching/runner_matcher_spec.rb b/ee/spec/lib/ee/gitlab/ci/matching/runner_matcher_spec.rb index bfcefe2a7c4b7..1857dd2827295 100644 --- a/ee/spec/lib/ee/gitlab/ci/matching/runner_matcher_spec.rb +++ b/ee/spec/lib/ee/gitlab/ci/matching/runner_matcher_spec.rb @@ -64,8 +64,8 @@ before do allow(project) - .to receive(:ci_minutes_quota) - .and_return(double(minutes_used_up?: quota_minutes_used_up, enabled?: true)) + .to receive(:ci_minutes_usage) + .and_return(double(minutes_used_up?: quota_minutes_used_up, limit_enabled?: true)) end it { is_expected.to eq(result) } diff --git a/ee/spec/lib/gitlab/ci/minutes/runners_availability_spec.rb b/ee/spec/lib/gitlab/ci/minutes/runners_availability_spec.rb index 51d564ebc2a9e..05df0def9d56c 100644 --- a/ee/spec/lib/gitlab/ci/minutes/runners_availability_spec.rb +++ b/ee/spec/lib/gitlab/ci/minutes/runners_availability_spec.rb @@ -11,7 +11,7 @@ let(:minutes) { described_class.new(project) } describe '#available?' do - where(:shared_runners_enabled, :minutes_quota, :private_runner_available, :result) do + where(:shared_runners_enabled, :minutes_usage, :private_runner_available, :result) do true | :with_not_used_build_minutes_limit | false | true true | :with_not_used_build_minutes_limit | true | true true | :with_used_build_minutes_limit | false | false @@ -23,7 +23,7 @@ end with_them do - let!(:namespace) { create(:namespace, minutes_quota) } + let!(:namespace) { create(:namespace, minutes_usage) } let!(:project) { create(:project, namespace: namespace, shared_runners_enabled: shared_runners_enabled) } let!(:private_runner) { create(:ci_runner, :project, :online, projects: [project], active: private_runner_available) } diff --git a/ee/spec/models/ci/minutes/namespace_monthly_usage_spec.rb b/ee/spec/models/ci/minutes/namespace_monthly_usage_spec.rb index 74ad9277ce3e1..5538ad4917fb7 100644 --- a/ee/spec/models/ci/minutes/namespace_monthly_usage_spec.rb +++ b/ee/spec/models/ci/minutes/namespace_monthly_usage_spec.rb @@ -145,7 +145,7 @@ let(:build) { create(:ci_build, :created, pipeline: pipeline) } before do - namespace.clear_memoization(:ci_minutes_quota) + namespace.clear_memoization(:ci_minutes_usage) create(:ci_runner, :instance_type) end diff --git a/ee/spec/models/ci/minutes/quota_spec.rb b/ee/spec/models/ci/minutes/usage_spec.rb similarity index 77% rename from ee/spec/models/ci/minutes/quota_spec.rb rename to ee/spec/models/ci/minutes/usage_spec.rb index 987ec387a5eb5..b3ae080834ea2 100644 --- a/ee/spec/models/ci/minutes/quota_spec.rb +++ b/ee/spec/models/ci/minutes/usage_spec.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Ci::Minutes::Quota do +RSpec.describe Ci::Minutes::Usage do using RSpec::Parameterized::TableSyntax let_it_be_with_reload(:namespace) do create(:group, namespace_statistics: create(:namespace_statistics)) end - let(:quota) { described_class.new(namespace) } + let(:usage) { described_class.new(namespace) } describe '#enabled?' do let(:project) { create(:project, namespace: namespace) } - subject { quota.enabled? } + subject { usage.limit_enabled? } context 'when namespace is root' do context 'when namespace has any project with shared runners enabled' do @@ -64,9 +64,9 @@ end describe '#minutes_used_up?' do - subject { quota.minutes_used_up? } + subject { usage.minutes_used_up? } - where(:limit_enabled, :monthly_limit, :purchased_limit, :minutes_used, :result, :title) do + where(:limit_enabled, :monthly_limit, :purchased_limit, :minutes_used, :result, :case_name) do false | 0 | 0 | 40 | false | 'limit not enabled' true | 0 | 200 | 40 | false | 'monthly limit not set and purchased limit set and low usage' true | 200 | 0 | 40 | false | 'monthly limit set and purchased limit not set and usage below monthly' @@ -80,10 +80,17 @@ end with_them do - let(:namespace) { create(:namespace, :with_ci_minutes, ci_minutes_limit: monthly_limit, ci_minutes_used: minutes_used) } + let(:namespace) do + create( + :namespace, + :with_ci_minutes, + ci_minutes_limit: monthly_limit, + ci_minutes_used: minutes_used + ) + end before do - allow(quota).to receive(:enabled?).and_return(limit_enabled) + allow(usage).to receive(:enabled?).and_return(limit_enabled) namespace.extra_shared_runners_minutes_limit = purchased_limit end @@ -94,7 +101,7 @@ describe '#total_minutes_used' do let(:namespace) { create(:namespace, :with_ci_minutes, ci_minutes_used: minutes_used) } - subject { quota.total_minutes_used } + subject { usage.total_minutes_used } where(:minutes_used, :expected_minutes) do nil | 0 @@ -110,7 +117,7 @@ end describe '#percent_total_minutes_remaining' do - subject { quota.percent_total_minutes_remaining } + subject { usage.percent_total_minutes_remaining } where(:total_minutes_used, :monthly_minutes, :purchased_minutes, :result) do 0 | 0 | 0 | 0 @@ -122,7 +129,14 @@ end with_them do - let(:namespace) { create(:namespace, :with_ci_minutes, ci_minutes_used: total_minutes_used, ci_minutes_limit: monthly_minutes) } + let(:namespace) do + create( + :namespace, + :with_ci_minutes, + ci_minutes_used: total_minutes_used, + ci_minutes_limit: monthly_minutes + ) + end before do allow(namespace).to receive(:extra_shared_runners_minutes_limit).and_return(purchased_minutes) @@ -133,32 +147,39 @@ end describe '#monthly_minutes_used_up?' do - subject { quota.monthly_minutes_used_up? } + subject { usage.monthly_minutes_used_up? } - context 'when quota is enabled' do + context 'when usage is enabled' do let(:total_minutes) { 1000 } - let(:namespace) { create(:namespace, :with_ci_minutes, ci_minutes_limit: total_minutes, ci_minutes_used: total_minutes_used) } + let(:namespace) do + create( + :namespace, + :with_ci_minutes, + ci_minutes_used: total_minutes_used, + ci_minutes_limit: total_minutes + ) + end - context 'when monthly minutes quota greater than monthly minutes used' do + context 'when monthly minutes usage greater than monthly minutes used' do let(:total_minutes_used) { total_minutes - 1 } it { is_expected.to be_falsey } end - context 'when monthly minutes quota less than monthly minutes used' do + context 'when monthly minutes usage less than monthly minutes used' do let(:total_minutes_used) { total_minutes + 1 } it { is_expected.to be_truthy } end - context 'when monthly minutes quota equals monthly minutes used' do + context 'when monthly minutes usage equals monthly minutes used' do let(:total_minutes_used) { total_minutes } it { is_expected.to be_truthy } end end - context 'when quota is disabled' do + context 'when usage is disabled' do before do allow(namespace).to receive(:shared_runners_minutes_limit).and_return(0) end @@ -168,9 +189,9 @@ end describe '#purchased_minutes_used_up?' do - subject { quota.purchased_minutes_used_up? } + subject { usage.purchased_minutes_used_up? } - context 'when quota is enabled' do + context 'when usage is enabled' do before do allow(namespace).to receive(:shared_runners_minutes_limit).and_return(1000) end @@ -193,7 +214,14 @@ end with_them do - let(:namespace) { create(:namespace, :with_ci_minutes, ci_minutes_limit: monthly_minutes, ci_minutes_used: total_minutes_used) } + let(:namespace) do + create( + :namespace, + :with_ci_minutes, + ci_minutes_limit: monthly_minutes, + ci_minutes_used: total_minutes_used + ) + end before do allow(namespace).to receive(:extra_shared_runners_minutes_limit).and_return(purchased_minutes) @@ -204,7 +232,7 @@ end end - context 'when quota is disabled' do + context 'when usage is disabled' do before do allow(namespace).to receive(:shared_runners_minutes_limit).and_return(0) end @@ -214,9 +242,7 @@ end describe '#reset_date' do - let(:quota) { described_class.new(namespace) } - - subject(:reset_date) { quota.reset_date } + subject(:reset_date) { usage.reset_date } around do |example| travel_to(Date.new(2021, 07, 14)) { example.run } diff --git a/ee/spec/models/ee/ci/pending_build_spec.rb b/ee/spec/models/ee/ci/pending_build_spec.rb index 9893b844fad84..3799887e34088 100644 --- a/ee/spec/models/ee/ci/pending_build_spec.rb +++ b/ee/spec/models/ee/ci/pending_build_spec.rb @@ -49,7 +49,7 @@ context 'when ci minutes are not available' do before do - allow_next_instance_of(::Ci::Minutes::Quota) do |instance| + allow_next_instance_of(::Ci::Minutes::Usage) do |instance| allow(instance).to receive(:minutes_used_up?).and_return(true) end end diff --git a/ee/spec/models/ee/ci/runner_spec.rb b/ee/spec/models/ee/ci/runner_spec.rb index 8f70a7adf3d9d..bc1821e06e8ac 100644 --- a/ee/spec/models/ee/ci/runner_spec.rb +++ b/ee/spec/models/ee/ci/runner_spec.rb @@ -131,8 +131,8 @@ end end - describe '#visibility_levels_without_minutes_quota' do - subject { runner.visibility_levels_without_minutes_quota } + describe '#visibility_levels_without_minutes_usage' do + subject { runner.visibility_levels_without_minutes_usage } context 'with group type runner' do let(:runner) { create(:ci_runner, :group) } diff --git a/ee/spec/models/ee/user_spec.rb b/ee/spec/models/ee/user_spec.rb index a0bba805ac0e4..b1998c4d2fd57 100644 --- a/ee/spec/models/ee/user_spec.rb +++ b/ee/spec/models/ee/user_spec.rb @@ -1712,7 +1712,7 @@ allow(project.namespace).to receive(:free_plan?).and_return(plan == :free) allow(project.namespace).to receive(:trial?).and_return(plan == :trial) project.namespace.update!(extra_shared_runners_minutes_limit: addon_mins) - project.namespace.clear_memoization(:ci_minutes_quota) + project.namespace.clear_memoization(:ci_minutes_usage) project.update!(shared_runners_enabled: shared_runners_enabled) stub_feature_flags( @@ -1766,7 +1766,7 @@ allow(project.namespace).to receive(:free_plan?).and_return(plan == :free) allow(project.namespace).to receive(:trial?).and_return(plan == :trial) project.namespace.update!(extra_shared_runners_minutes_limit: addon_mins) - project.namespace.clear_memoization(:ci_minutes_quota) + project.namespace.clear_memoization(:ci_minutes_usage) stub_feature_flags( ci_require_credit_card_on_free_plan: feature_flags.include?(:free), ci_require_credit_card_on_trial_plan: feature_flags.include?(:trial), diff --git a/ee/spec/models/project_spec.rb b/ee/spec/models/project_spec.rb index 0414e71d0e0d9..90077f2444af3 100644 --- a/ee/spec/models/project_spec.rb +++ b/ee/spec/models/project_spec.rb @@ -12,7 +12,7 @@ describe 'associations' do it { is_expected.to delegate_method(:shared_runners_seconds).to(:statistics) } - it { is_expected.to delegate_method(:ci_minutes_quota).to(:shared_runners_limit_namespace) } + it { is_expected.to delegate_method(:ci_minutes_usage).to(:shared_runners_limit_namespace) } it { is_expected.to delegate_method(:shared_runners_minutes_limit_enabled?).to(:shared_runners_limit_namespace) } it { is_expected.to delegate_method(:pipeline_configuration_full_path).to(:compliance_management_framework) } @@ -3109,7 +3109,7 @@ def stub_default_url_options(host) subject { project.available_shared_runners } before do - allow(project).to receive(:ci_minutes_quota) + allow(project).to receive(:ci_minutes_usage) .and_return(double('quota', minutes_used_up?: minutes_used_up)) end @@ -3142,7 +3142,7 @@ def stub_default_url_options(host) subject { project.all_available_runners } before do - allow(project).to receive(:ci_minutes_quota) + allow(project).to receive(:ci_minutes_usage) .and_return(double('quota', minutes_used_up?: minutes_used_up)) end diff --git a/ee/spec/policies/group_policy_spec.rb b/ee/spec/policies/group_policy_spec.rb index cacd56490e785..d0a13a742df7b 100644 --- a/ee/spec/policies/group_policy_spec.rb +++ b/ee/spec/policies/group_policy_spec.rb @@ -1470,10 +1470,10 @@ def stub_group_saml_config(enabled) end end - describe ':read_ci_minutes_quota' do + describe ':read_ci_minutes_usage' do using RSpec::Parameterized::TableSyntax - let(:policy) { :read_ci_minutes_quota } + let(:policy) { :read_ci_minutes_usage } where(:role, :admin_mode, :allowed) do :guest | nil | false diff --git a/ee/spec/policies/project_policy_spec.rb b/ee/spec/policies/project_policy_spec.rb index 9c72cb0cc9577..c14b6afe8e134 100644 --- a/ee/spec/policies/project_policy_spec.rb +++ b/ee/spec/policies/project_policy_spec.rb @@ -1498,10 +1498,10 @@ end end - describe ':read_ci_minutes_quota' do + describe ':read_ci_minutes_usage' do using RSpec::Parameterized::TableSyntax - let(:policy) { :read_ci_minutes_quota } + let(:policy) { :read_ci_minutes_usage } where(:role, :admin_mode, :allowed) do :guest | nil | false diff --git a/ee/spec/presenters/ci/minutes/quota_presenter_spec.rb b/ee/spec/presenters/ci/minutes/usage_presenter_spec.rb similarity index 93% rename from ee/spec/presenters/ci/minutes/quota_presenter_spec.rb rename to ee/spec/presenters/ci/minutes/usage_presenter_spec.rb index 40da009e7822e..e302ec26b9a68 100644 --- a/ee/spec/presenters/ci/minutes/quota_presenter_spec.rb +++ b/ee/spec/presenters/ci/minutes/usage_presenter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::Minutes::QuotaPresenter do +RSpec.describe Ci::Minutes::UsagePresenter do include ::Ci::MinutesHelpers using RSpec::Parameterized::TableSyntax @@ -11,14 +11,14 @@ create(:group, namespace_statistics: create(:namespace_statistics)) end - let(:quota) { Ci::Minutes::Quota.new(namespace) } + let(:usage) { Ci::Minutes::Usage.new(namespace) } - subject(:presenter) { described_class.new(quota) } + subject(:presenter) { described_class.new(usage) } describe '#monthly_minutes_report' do - context 'when the quota is not enabled' do + context 'when the usage is not enabled' do before do - allow(quota).to receive(:enabled?).and_return(false) + allow(usage).to receive(:limit_enabled?).and_return(false) allow(namespace).to receive(:root?).and_return(namespace_eligible) allow(namespace).to receive(:any_project_with_shared_runners_enabled?).and_return(true) end @@ -66,7 +66,7 @@ context 'when limited' do before do - allow(presenter).to receive(:enabled?).and_return(true) + allow(presenter).to receive(:limit_enabled?).and_return(true) allow(namespace).to receive(:any_project_with_shared_runners_enabled?).and_return(true) namespace.shared_runners_minutes_limit = 100 end @@ -76,7 +76,7 @@ set_ci_minutes_used(namespace, 30) end - it 'returns report with under quota' do + it 'returns report with under usage' do report = presenter.monthly_minutes_report expect(report.limit).to eq 100 @@ -104,7 +104,7 @@ describe '#purchased_minutes_report' do context 'when limit enabled' do before do - allow(quota).to receive(:enabled?).and_return(true) + allow(usage).to receive(:limit_enabled?).and_return(true) namespace.shared_runners_minutes_limit = 200 end @@ -195,7 +195,7 @@ describe '#monthly_percent_used' do subject { presenter.monthly_percent_used } - where(:limit_enabled, :monthly_limit, :purchased_limit, :minutes_used, :result, :title) do + where(:limit_enabled, :monthly_limit, :purchased_limit, :minutes_used, :result, :case_name) do false | 200 | 0 | 40 | 0 | 'limit not enabled' true | 200 | 0 | 0 | 0 | 'monthly limit set and no usage' true | 200 | 0 | 40 | 20 | 'monthly limit set and usage lower than 100%' @@ -210,7 +210,7 @@ with_them do before do - allow(quota).to receive(:enabled?).and_return(limit_enabled) + allow(usage).to receive(:limit_enabled?).and_return(limit_enabled) allow(namespace).to receive(:any_project_with_shared_runners_enabled?).and_return(true) namespace.shared_runners_minutes_limit = monthly_limit namespace.extra_shared_runners_minutes_limit = purchased_limit @@ -226,7 +226,7 @@ describe '#purchased_percent_used' do subject { presenter.purchased_percent_used } - where(:limit_enabled, :monthly_limit, :purchased_limit, :minutes_used, :result, :title) do + where(:limit_enabled, :monthly_limit, :purchased_limit, :minutes_used, :result, :case_name) do false | 0 | 0 | 40 | 0 | 'limit not enabled' true | 0 | 200 | 40 | 20 | 'monthly limit not set and purchased limit set and low usage' true | 200 | 0 | 40 | 0 | 'monthly limit set and purchased limit not set and usage below monthly' @@ -241,7 +241,7 @@ with_them do before do - allow(quota).to receive(:enabled?).and_return(limit_enabled) + allow(usage).to receive(:limit_enabled?).and_return(limit_enabled) namespace.shared_runners_minutes_limit = monthly_limit namespace.extra_shared_runners_minutes_limit = purchased_limit set_ci_minutes_used(namespace, minutes_used) diff --git a/ee/spec/requests/api/namespaces_spec.rb b/ee/spec/requests/api/namespaces_spec.rb index aa99eccf7029a..3dbd2c3fa64e5 100644 --- a/ee/spec/requests/api/namespaces_spec.rb +++ b/ee/spec/requests/api/namespaces_spec.rb @@ -270,7 +270,7 @@ end it 'updates pending builds data since adding extra minutes the quota is not used up anymore' do - minutes_exceeded = group1.ci_minutes_quota.minutes_used_up? + minutes_exceeded = group1.ci_minutes_usage.minutes_used_up? expect(minutes_exceeded).to eq(true) pending_build = create(:ci_pending_build, namespace: group1, minutes_exceeded: minutes_exceeded) diff --git a/ee/spec/services/ci/minutes/refresh_cached_data_service_spec.rb b/ee/spec/services/ci/minutes/refresh_cached_data_service_spec.rb index 479b945af8fff..ca01990c4e56e 100644 --- a/ee/spec/services/ci/minutes/refresh_cached_data_service_spec.rb +++ b/ee/spec/services/ci/minutes/refresh_cached_data_service_spec.rb @@ -31,7 +31,7 @@ context 'when user purchases more ci minutes for a given namespace' do before do - allow_next_instance_of(::Ci::Minutes::Quota) do |instance| + allow_next_instance_of(::Ci::Minutes::Usage) do |instance| allow(instance).to receive(:minutes_used_up?).and_return(false) end end diff --git a/ee/spec/services/ci/minutes/track_live_consumption_service_spec.rb b/ee/spec/services/ci/minutes/track_live_consumption_service_spec.rb index 18ce5c904aa6f..5868eb0d4c24a 100644 --- a/ee/spec/services/ci/minutes/track_live_consumption_service_spec.rb +++ b/ee/spec/services/ci/minutes/track_live_consumption_service_spec.rb @@ -82,8 +82,8 @@ context 'when namespace has unlimited minutes' do before do - quota = double('quota', enabled?: false) - allow(project).to receive(:ci_minutes_quota).and_return(quota) + usage = double('usage', limit_enabled?: false) + allow(project).to receive(:ci_minutes_usage).and_return(usage) end it_behaves_like 'returns early', 'Cost factor not enabled for build' diff --git a/ee/spec/services/ci/pipeline_creation/drop_not_runnable_builds_service_spec.rb b/ee/spec/services/ci/pipeline_creation/drop_not_runnable_builds_service_spec.rb index ff1c59649df23..c1d1105d86dae 100644 --- a/ee/spec/services/ci/pipeline_creation/drop_not_runnable_builds_service_spec.rb +++ b/ee/spec/services/ci/pipeline_creation/drop_not_runnable_builds_service_spec.rb @@ -39,8 +39,8 @@ shared_examples 'limit exceeded' do before do - allow(pipeline.project).to receive(:ci_minutes_quota) - .and_return(double('quota', minutes_used_up?: true, enabled?: true)) + allow(pipeline.project).to receive(:ci_minutes_usage) + .and_return(double('usage', minutes_used_up?: true, limit_enabled?: true)) end it 'drops the job with ci_quota_exceeded reason' do @@ -95,8 +95,8 @@ context 'when the CI quota is exceeded' do before do - allow(pipeline.project).to receive(:ci_minutes_quota) - .and_return(double('quota', minutes_used_up?: true, enabled?: true)) + allow(pipeline.project).to receive(:ci_minutes_usage) + .and_return(double('usage', minutes_used_up?: true, limit_enabled?: true)) end it_behaves_like 'jobs allowed to run' diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb index cb09c2f89e1c5..39f0e1c15f5b9 100644 --- a/spec/helpers/namespaces_helper_spec.rb +++ b/spec/helpers/namespaces_helper_spec.rb @@ -269,9 +269,9 @@ end end - describe '#pipeline_usage_quota_app_data' do + describe '#pipeline_usage_app_data' do it 'returns a hash with necessary data for the frontend' do - expect(helper.pipeline_usage_quota_app_data(user_group)).to eql({ + expect(helper.pipeline_usage_app_data(user_group)).to eql({ namespace_actual_plan_name: user_group.actual_plan_name, namespace_path: user_group.full_path, namespace_id: user_group.id, -- GitLab