Commit 588b07aa authored by Maxime Orefice's avatar Maxime Orefice

Add group_id to coverage data

This commit adds a new group_id column to
ci_daily_build_group_report_result table. This will allow us to
aggregate daily coverage data at the group level.
parent 9c8d6d8e
...@@ -14,7 +14,8 @@ module Ci ...@@ -14,7 +14,8 @@ module Ci
ref_path: pipeline.source_ref_path, ref_path: pipeline.source_ref_path,
date: pipeline.created_at.to_date, date: pipeline.created_at.to_date,
last_pipeline_id: pipeline.id, last_pipeline_id: pipeline.id,
default_branch: pipeline.default_branch? default_branch: pipeline.default_branch?,
group_id: pipeline.project&.group&.id
} }
aggregate(pipeline.builds.with_coverage).map do |group_name, group| aggregate(pipeline.builds.with_coverage).map do |group_name, group|
......
---
title: Add group_id to ci_daily_build_group_report_result
merge_request: 53494
author:
type: added
# frozen_string_literal: true
class AddGroupIdToCiDailyBuildGroupReportResults < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column(:ci_daily_build_group_report_results, :group_id, :bigint)
end
end
# frozen_string_literal: true
class AddIndexGroupIdToCiDailyBuildGroupReportResults < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_ci_daily_build_group_report_results_on_group_id'
disable_ddl_transaction!
def up
add_concurrent_index(:ci_daily_build_group_report_results, :group_id, name: INDEX_NAME)
add_concurrent_foreign_key(:ci_daily_build_group_report_results, :namespaces, column: :group_id)
end
def down
remove_foreign_key_if_exists(:ci_daily_build_group_report_results, column: :group_id)
remove_concurrent_index_by_name(:ci_daily_build_group_report_results, INDEX_NAME)
end
end
2a40acf9a3ac2716120388cfe79be13130e4587286d215596e9c75097af1e436
\ No newline at end of file
845636d8a0c6e9b6b39194cb44ffeceea3464023c22fadb2a4da44fed5dd973f
\ No newline at end of file
...@@ -10379,7 +10379,8 @@ CREATE TABLE ci_daily_build_group_report_results ( ...@@ -10379,7 +10379,8 @@ CREATE TABLE ci_daily_build_group_report_results (
ref_path text NOT NULL, ref_path text NOT NULL,
group_name text NOT NULL, group_name text NOT NULL,
data jsonb NOT NULL, data jsonb NOT NULL,
default_branch boolean DEFAULT false NOT NULL default_branch boolean DEFAULT false NOT NULL,
group_id bigint
); );
CREATE SEQUENCE ci_daily_build_group_report_results_id_seq CREATE SEQUENCE ci_daily_build_group_report_results_id_seq
...@@ -21455,6 +21456,8 @@ CREATE INDEX index_ci_builds_project_id_and_status_for_live_jobs_partial2 ON ci_ ...@@ -21455,6 +21456,8 @@ CREATE INDEX index_ci_builds_project_id_and_status_for_live_jobs_partial2 ON ci_
CREATE UNIQUE INDEX index_ci_builds_runner_session_on_build_id ON ci_builds_runner_session USING btree (build_id); CREATE UNIQUE INDEX index_ci_builds_runner_session_on_build_id ON ci_builds_runner_session USING btree (build_id);
CREATE INDEX index_ci_daily_build_group_report_results_on_group_id ON ci_daily_build_group_report_results USING btree (group_id);
CREATE INDEX index_ci_daily_build_group_report_results_on_last_pipeline_id ON ci_daily_build_group_report_results USING btree (last_pipeline_id); CREATE INDEX index_ci_daily_build_group_report_results_on_last_pipeline_id ON ci_daily_build_group_report_results USING btree (last_pipeline_id);
CREATE INDEX index_ci_daily_build_group_report_results_on_project_and_date ON ci_daily_build_group_report_results USING btree (project_id, date DESC) WHERE ((default_branch = true) AND ((data -> 'coverage'::text) IS NOT NULL)); CREATE INDEX index_ci_daily_build_group_report_results_on_project_and_date ON ci_daily_build_group_report_results USING btree (project_id, date DESC) WHERE ((default_branch = true) AND ((data -> 'coverage'::text) IS NOT NULL));
...@@ -24540,6 +24543,9 @@ ALTER TABLE ONLY system_note_metadata ...@@ -24540,6 +24543,9 @@ ALTER TABLE ONLY system_note_metadata
ALTER TABLE ONLY vulnerability_remediations ALTER TABLE ONLY vulnerability_remediations
ADD CONSTRAINT fk_fc61a535a0 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; ADD CONSTRAINT fk_fc61a535a0 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_daily_build_group_report_results
ADD CONSTRAINT fk_fd1858fefd FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY merge_requests ALTER TABLE ONLY merge_requests
ADD CONSTRAINT fk_fd82eae0b9 FOREIGN KEY (head_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE SET NULL; ADD CONSTRAINT fk_fd82eae0b9 FOREIGN KEY (head_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE SET NULL;
......
...@@ -7,8 +7,13 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do ...@@ -7,8 +7,13 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do
let!(:rspec_job) { create(:ci_build, pipeline: pipeline, name: '3/3 rspec', coverage: 80) } let!(:rspec_job) { create(:ci_build, pipeline: pipeline, name: '3/3 rspec', coverage: 80) }
let!(:karma_job) { create(:ci_build, pipeline: pipeline, name: '2/2 karma', coverage: 90) } let!(:karma_job) { create(:ci_build, pipeline: pipeline, name: '2/2 karma', coverage: 90) }
let!(:extra_job) { create(:ci_build, pipeline: pipeline, name: 'extra', coverage: nil) } let!(:extra_job) { create(:ci_build, pipeline: pipeline, name: 'extra', coverage: nil) }
let!(:group) { create(:group, :private) }
let(:coverages) { Ci::DailyBuildGroupReportResult.all } let(:coverages) { Ci::DailyBuildGroupReportResult.all }
before do
pipeline.project.group = group
end
it 'creates daily code coverage record for each job in the pipeline that has coverage value' do it 'creates daily code coverage record for each job in the pipeline that has coverage value' do
described_class.new.execute(pipeline) described_class.new.execute(pipeline)
...@@ -19,7 +24,8 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do ...@@ -19,7 +24,8 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do
ref_path: pipeline.source_ref_path, ref_path: pipeline.source_ref_path,
group_name: rspec_job.group_name, group_name: rspec_job.group_name,
data: { 'coverage' => rspec_job.coverage }, data: { 'coverage' => rspec_job.coverage },
date: pipeline.created_at.to_date date: pipeline.created_at.to_date,
group_id: pipeline.project.group.id
) )
end end
...@@ -30,7 +36,8 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do ...@@ -30,7 +36,8 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do
ref_path: pipeline.source_ref_path, ref_path: pipeline.source_ref_path,
group_name: karma_job.group_name, group_name: karma_job.group_name,
data: { 'coverage' => karma_job.coverage }, data: { 'coverage' => karma_job.coverage },
date: pipeline.created_at.to_date date: pipeline.created_at.to_date,
group_id: pipeline.project.group.id
) )
end end
...@@ -155,6 +162,10 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do ...@@ -155,6 +162,10 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do
let!(:some_job) { create(:ci_build, pipeline: new_pipeline, name: 'foo') } let!(:some_job) { create(:ci_build, pipeline: new_pipeline, name: 'foo') }
before do
new_pipeline.project.group = group
end
it 'does nothing' do it 'does nothing' do
expect { described_class.new.execute(new_pipeline) }.not_to raise_error expect { described_class.new.execute(new_pipeline) }.not_to raise_error
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment