Commit 235dd4e6 authored by Robert May's avatar Robert May

Merge branch 'ci-default-enable-ci_build_metadata_config' into 'master'

Enable writes to CI builds metadata table by default

See merge request gitlab-org/gitlab!66163
parents f8de35f7 61293c61
...@@ -38,11 +38,7 @@ module Security ...@@ -38,11 +38,7 @@ module Security
def execute def execute
return [] if @job_types.empty? return [] if @job_types.empty?
if Feature.enabled?(:ci_build_metadata_config, pipeline.project, default_enabled: :yaml) find_jobs
find_jobs
else
find_jobs_legacy
end
end end
private private
...@@ -51,19 +47,6 @@ module Security ...@@ -51,19 +47,6 @@ module Security
@pipeline.builds.with_secure_reports_from_config_options(@job_types) @pipeline.builds.with_secure_reports_from_config_options(@job_types)
end end
def find_jobs_legacy
# the query doesn't guarantee accuracy, so we verify it here
legacy_jobs_query.select do |job|
@job_types.find { |job_type| job.options.dig(:artifacts, :reports, job_type) }
end
end
def legacy_jobs_query
@job_types.map do |job_type|
@pipeline.builds.with_secure_reports_from_options(job_type)
end.reduce(&:or)
end
def valid_job_types?(job_types) def valid_job_types?(job_types)
(job_types - self.class.allowed_job_types).empty? (job_types - self.class.allowed_job_types).empty?
end end
......
...@@ -76,14 +76,8 @@ module Ci ...@@ -76,14 +76,8 @@ module Ci
end end
def write_metadata_attribute(legacy_key, metadata_key, value) def write_metadata_attribute(legacy_key, metadata_key, value)
# save to metadata or this model depending on the state of feature flag ensure_metadata.write_attribute(metadata_key, value)
if Feature.enabled?(:ci_build_metadata_config, project, default_enabled: :yaml) write_attribute(legacy_key, nil)
ensure_metadata.write_attribute(metadata_key, value)
write_attribute(legacy_key, nil)
else
write_attribute(legacy_key, value)
metadata&.write_attribute(metadata_key, nil)
end
end end
end end
end end
......
---
name: ci_build_metadata_config
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/7238
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/330954
milestone: '11.7'
type: development
group: group::pipeline execution
default_enabled: false
...@@ -151,25 +151,6 @@ RSpec.describe Projects::Security::ConfigurationPresenter do ...@@ -151,25 +151,6 @@ RSpec.describe Projects::Security::ConfigurationPresenter do
) )
end end
it 'works with both legacy and current job formats' do
stub_feature_flags(ci_build_metadata_config: false)
create(:ci_build, :sast, pipeline: pipeline)
expect(Gitlab::Json.parse(subject[:features])).to contain_exactly(
security_scan(:dast, configured: false),
security_scan(:dast_profiles, configured: true),
security_scan(:sast, configured: true),
security_scan(:container_scanning, configured: false),
security_scan(:cluster_image_scanning, configured: false),
security_scan(:dependency_scanning, configured: false),
security_scan(:license_scanning, configured: false),
security_scan(:secret_detection, configured: false),
security_scan(:coverage_fuzzing, configured: false),
security_scan(:api_fuzzing, configured: false)
)
end
it 'detects security jobs even when the job has more than one report' do it 'detects security jobs even when the job has more than one report' do
config = { artifacts: { reports: { other_job: ['gl-other-report.json'], sast: ['gl-sast-report.json'] } } } config = { artifacts: { reports: { other_job: ['gl-other-report.json'], sast: ['gl-sast-report.json'] } } }
complicated_job = build_stubbed(:ci_build, options: config) complicated_job = build_stubbed(:ci_build, options: config)
......
...@@ -53,24 +53,8 @@ RSpec.describe Gitlab::Ci::Build::AutoRetry do ...@@ -53,24 +53,8 @@ RSpec.describe Gitlab::Ci::Build::AutoRetry do
context 'with retries max config option' do context 'with retries max config option' do
let(:build) { create(:ci_build, options: { retry: { max: 1 } }) } let(:build) { create(:ci_build, options: { retry: { max: 1 } }) }
context 'when build_metadata_config is set' do it 'returns the number of configured max retries' do
before do expect(result).to eq 1
stub_feature_flags(ci_build_metadata_config: true)
end
it 'returns the number of configured max retries' do
expect(result).to eq 1
end
end
context 'when build_metadata_config is not set' do
before do
stub_feature_flags(ci_build_metadata_config: false)
end
it 'returns the number of configured max retries' do
expect(result).to eq 1
end
end end
end end
......
...@@ -2214,34 +2214,12 @@ RSpec.describe Ci::Build do ...@@ -2214,34 +2214,12 @@ RSpec.describe Ci::Build do
expect(build.options['image']).to be_nil expect(build.options['image']).to be_nil
end end
context 'when ci_build_metadata_config is set' do it 'persist data in build metadata' do
before do expect(build.metadata.read_attribute(:config_options)).to eq(options.symbolize_keys)
stub_feature_flags(ci_build_metadata_config: true)
end
it 'persist data in build metadata' do
expect(build.metadata.read_attribute(:config_options)).to eq(options.symbolize_keys)
end
it 'does not persist data in build' do
expect(build.read_attribute(:options)).to be_nil
end
end end
context 'when ci_build_metadata_config is disabled' do it 'does not persist data in build' do
let(:build) { create(:ci_build, pipeline: pipeline) } expect(build.read_attribute(:options)).to be_nil
before do
stub_feature_flags(ci_build_metadata_config: false)
end
it 'persist data in build' do
expect(build.read_attribute(:options)).to eq(options.symbolize_keys)
end
it 'does not persist data in build metadata' do
expect(build.metadata.read_attribute(:config_options)).to be_nil
end
end end
context 'when options include artifacts:expose_as' do context 'when options include artifacts:expose_as' do
...@@ -3613,36 +3591,14 @@ RSpec.describe Ci::Build do ...@@ -3613,36 +3591,14 @@ RSpec.describe Ci::Build do
end end
end end
context 'when ci_build_metadata_config is set' do it_behaves_like 'having consistent representation'
before do
stub_feature_flags(ci_build_metadata_config: true)
end
it_behaves_like 'having consistent representation'
it 'persist data in build metadata' do it 'persist data in build metadata' do
expect(build.metadata.read_attribute(:config_variables)).not_to be_nil expect(build.metadata.read_attribute(:config_variables)).not_to be_nil
end
it 'does not persist data in build' do
expect(build.read_attribute(:yaml_variables)).to be_nil
end
end end
context 'when ci_build_metadata_config is disabled' do it 'does not persist data in build' do
before do expect(build.read_attribute(:yaml_variables)).to be_nil
stub_feature_flags(ci_build_metadata_config: false)
end
it_behaves_like 'having consistent representation'
it 'persist data in build' do
expect(build.read_attribute(:yaml_variables)).not_to be_nil
end
it 'does not persist data in build metadata' do
expect(build.metadata.read_attribute(:config_variables)).to be_nil
end
end end
end end
...@@ -4788,51 +4744,21 @@ RSpec.describe Ci::Build do ...@@ -4788,51 +4744,21 @@ RSpec.describe Ci::Build do
subject { build.send(:write_metadata_attribute, :options, :config_options, options) } subject { build.send(:write_metadata_attribute, :options, :config_options, options) }
context 'when ci_build_metadata_config is set' do context 'when data in build is already set' do
before do before do
stub_feature_flags(ci_build_metadata_config: true) build.write_attribute(:options, existing_options)
end end
context 'when data in build is already set' do it 'does set metadata options' do
before do subject
build.write_attribute(:options, existing_options)
end
it 'does set metadata options' do
subject
expect(build.metadata.read_attribute(:config_options)).to eq(options)
end
it 'does reset build options' do
subject
expect(build.read_attribute(:options)).to be_nil
end
end
end
context 'when ci_build_metadata_config is disabled' do expect(build.metadata.read_attribute(:config_options)).to eq(options)
before do
stub_feature_flags(ci_build_metadata_config: false)
end end
context 'when data in build metadata is already set' do it 'does reset build options' do
before do subject
build.ensure_metadata.write_attribute(:config_options, existing_options)
end
it 'does set metadata options' do
subject
expect(build.read_attribute(:options)).to eq(options)
end
it 'does reset build options' do
subject
expect(build.metadata.read_attribute(:config_options)).to be_nil expect(build.read_attribute(:options)).to be_nil
end
end end
end end
end end
......
...@@ -68,20 +68,6 @@ RSpec.shared_examples ::Security::JobsFinder do |default_job_types| ...@@ -68,20 +68,6 @@ RSpec.shared_examples ::Security::JobsFinder do |default_job_types|
end end
end end
context 'when using legacy CI build metadata config storage' do it_behaves_like 'JobsFinder core functionality'
before do
stub_feature_flags(ci_build_metadata_config: false)
end
it_behaves_like 'JobsFinder core functionality'
end
context 'when using the new CI build metadata config storage' do
before do
stub_feature_flags(ci_build_metadata_config: true)
end
it_behaves_like 'JobsFinder core functionality'
end
end end
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