Skip to content

Draft: Use build finished_at to add duration to the correct usage stats

Tianwen Chen requested to merge 420395-fix into master

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:

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

  1. 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)
  2. 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.

Related to #420395

Edited by Tianwen Chen

Merge request reports