Draft: Use build finished_at to add duration to the correct usage stats
What does this MR do and why?
This MR changes to use build's finished_at
to add duration to the correct monthly usage stats.
Currently, the duration is being added to the month of Time.current
at:
- for
namespace_usage
at https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/services/ci/minutes/update_project_and_namespace_usage_service.rb#L62 - for
project_usage
at https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/services/ci/minutes/update_project_and_namespace_usage_service.rb#L69
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
-
Run the following code in Rails console
build = FactoryBot.create(:ci_build, started_at: '2023-10-30T23:00:00Z', finished_at: '2023-10-30T23:59:00Z') project = Project.first namespace = project.namespace service = Ci::Minutes::UpdateProjectAndNamespaceUsageService.new(project.id, namespace.id, build.id) service.execute(888, 888 * 60)
-
Check if the duration is added to monthly usage for
2023-10-01
project_stats = Ci::Minutes::ProjectMonthlyUsage.find_by_date('2023-10-01') project_stats.inspect namespace_stats = Ci::Minutes::NamespaceMonthlyUsage.find_by_date('2023-10-01') namespace_stats.inspect
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.
Related to #420395