diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-09-15 19:42:12 +0530 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-09-17 12:16:48 +0530 |
commit | 161804bf401cead2b06a69884d4c6622acf8dec4 (patch) | |
tree | 40338ad2240a3098187b51ec286e9a379f18f5c9 /db/fixtures/development | |
parent | 40c17f2dd9ac5279c0019c9fdcb34aaa55331260 (diff) | |
download | gitlab-ce-161804bf401cead2b06a69884d4c6622acf8dec4.tar.gz |
Add a "populate metrics directly" option to the cycle analytics seed.
- The normal seed creates all the data for cycle analytics the "right"
way. It creates issues, merge requests, commits, branches,
deployments, etc. This is good, but too slow for perf testing.
Generating a 1000 sets of records this way takes more than an hour.
- When the `CYCLE_ANALYTICS_POPULATE_METRICS_DIRECTLY` environment
variable is passed in, the seed only creates issues and merge
requests. It then adds the `metrics` for each issue and
merge request directly, to save time.
- The seed now takes about 4 minutes to run for 1000 sets of records.
Diffstat (limited to 'db/fixtures/development')
-rw-r--r-- | db/fixtures/development/17_cycle_analytics.rb | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/db/fixtures/development/17_cycle_analytics.rb b/db/fixtures/development/17_cycle_analytics.rb index 46cf0fbd805..f51d28d9ebf 100644 --- a/db/fixtures/development/17_cycle_analytics.rb +++ b/db/fixtures/development/17_cycle_analytics.rb @@ -1,4 +1,5 @@ require 'sidekiq/testing' +require './spec/support/test_env' class Gitlab::Seeder::CycleAnalytics def initialize(project, perf: false) @@ -21,10 +22,64 @@ class Gitlab::Seeder::CycleAnalytics end end + def seed_metrics! + @issue_count.times do |index| + # Issue + Timecop.travel 5.days.from_now + title = "#{FFaker::Product.brand}-#{FFaker::Product.brand}-#{rand(1000)}" + issue = Issue.create(project: @project, title: title, author: @user) + issue_metrics = issue.metrics + + # Milestones / Labels + Timecop.travel 5.days.from_now + if index.even? + issue_metrics.first_associated_with_milestone_at = rand(6..12).hours.from_now + else + issue_metrics.first_added_to_board_at = rand(6..12).hours.from_now + end + + # Commit + Timecop.travel 5.days.from_now + issue_metrics.first_mentioned_in_commit_at = rand(6..12).hours.from_now + + # MR + Timecop.travel 5.days.from_now + branch_name = "#{FFaker::Product.brand}-#{FFaker::Product.brand}-#{rand(1000)}" + @project.repository.add_branch(@user, branch_name, 'master') + merge_request = MergeRequest.create(target_project: @project, source_project: @project, source_branch: branch_name, target_branch: 'master', title: branch_name, author: @user) + merge_request_metrics = merge_request.metrics + + # MR closing issues + Timecop.travel 5.days.from_now + MergeRequestsClosingIssues.create!(issue: issue, merge_request: merge_request) + + # Merge + Timecop.travel 5.days.from_now + merge_request_metrics.merged_at = rand(6..12).hours.from_now + + # Start build + Timecop.travel 5.days.from_now + merge_request_metrics.latest_build_started_at = rand(6..12).hours.from_now + + # Finish build + Timecop.travel 5.days.from_now + merge_request_metrics.latest_build_finished_at = rand(6..12).hours.from_now + + # Deploy to production + Timecop.travel 5.days.from_now + merge_request_metrics.first_deployed_to_production_at = rand(6..12).hours.from_now + + issue_metrics.save! + merge_request_metrics.save! + + print '.' + end + end + def seed! Sidekiq::Testing.inline! do - issues = create_issues(@project) - print '.' + issues = create_issues + puts '.' # Stage 1 Timecop.travel 5.days.from_now @@ -62,7 +117,7 @@ class Gitlab::Seeder::CycleAnalytics private - def create_issues(project) + def create_issues Array.new(@issue_count) do issue_params = { title: "Cycle Analytics: #{FFaker::Lorem.sentence(6)}", @@ -182,6 +237,9 @@ Gitlab::Seeder.quiet do elsif ENV['CYCLE_ANALYTICS_PERF_TEST'] seeder = Gitlab::Seeder::CycleAnalytics.new(Project.order(:id).first, perf: true) seeder.seed! + elsif ENV['CYCLE_ANALYTICS_POPULATE_METRICS_DIRECTLY'] + seeder = Gitlab::Seeder::CycleAnalytics.new(Project.order(:id).first, perf: true) + seeder.seed_metrics! else puts "Not running the cycle analytics seed file. Use the `SEED_CYCLE_ANALYTICS` environment variable to enable it." end |