Skip to content

Change order of displayed years in CI minutes app

Jose Ivan Vargas requested to merge jivanvl-change-order-years-ci-minutes into master

What does this MR do and why?

Changes the displayed order of years inside the CI minutes usage app for the Usage Quotas on page load

#363029 (closed)

Screenshots or screen recordings

Before After
Screen_Shot_2022-05-20_at_11.34.31 Screen_Shot_2022-05-20_at_11.33.52

How to set up and validate locally

Visit Group > Settings > Usage Quotas or User -> Preferences -> Usage Quotas

Ensure the group namespace and projects have used CI/CD minutes / Shared Runners to expose data in the graphs.

Edit CI minutes

ApplicationSetting.current.update(shared_runners_minutes: 400)
project = Project.find(20)
root_namespace = project.root_namespace

namespace_usage = Ci::Minutes::NamespaceMonthlyUsage.find_or_create_current(namespace_id: root_namespace)
Ci::Minutes::NamespaceMonthlyUsage.update_counters(namespace_usage, amount_used: 100, shared_runners_duration: 100)

project_usage = Ci::Minutes::ProjectMonthlyUsage.find_or_create_current(project_id: project)
Ci::Minutes::ProjectMonthlyUsage.update_counters(project_usage, amount_used: 100, shared_runners_duration: 100)

Helper method (add to rails console)

def increase_ci_usage(project:, date:, amount_used:, shared_runners_duration:)
  date = date.utc.beginning_of_month

  project_usage = Ci::Minutes::ProjectMonthlyUsage.where(date: date).safe_find_or_create_by(project_id: project.id)
  Ci::Minutes::ProjectMonthlyUsage.update_counters(project_usage, amount_used: amount_used, shared_runners_duration: shared_runners_duration)

  root_namespace = project.root_namespace
  namespace_usage = Ci::Minutes::NamespaceMonthlyUsage.where(date: date).safe_find_or_create_by(namespace_id: root_namespace.id)
  Ci::Minutes::NamespaceMonthlyUsage.update_counters(namespace_usage, amount_used: amount_used, shared_runners_duration: shared_runners_duration)
end

Use helper method

increase_ci_usage(project: project, date: 1.month.ago, amount_used: 10, shared_runners_duration: 20)

Makre sure to call the last function from a date of a year or two ago so you can test the order

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 Jose Ivan Vargas

Merge request reports

Loading