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
def execute
return [] if @job_types.empty?
if Feature.enabled?(:ci_build_metadata_config, pipeline.project, default_enabled: :yaml)
find_jobs
else
find_jobs_legacy
end
find_jobs
end
private
......@@ -51,19 +47,6 @@ module Security
@pipeline.builds.with_secure_reports_from_config_options(@job_types)
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)
(job_types - self.class.allowed_job_types).empty?
end
......
......@@ -76,14 +76,8 @@ module Ci
end
def write_metadata_attribute(legacy_key, metadata_key, value)
# save to metadata or this model depending on the state of feature flag
if Feature.enabled?(:ci_build_metadata_config, project, default_enabled: :yaml)
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
ensure_metadata.write_attribute(metadata_key, value)
write_attribute(legacy_key, nil)
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
)
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
config = { artifacts: { reports: { other_job: ['gl-other-report.json'], sast: ['gl-sast-report.json'] } } }
complicated_job = build_stubbed(:ci_build, options: config)
......
......@@ -53,24 +53,8 @@ RSpec.describe Gitlab::Ci::Build::AutoRetry do
context 'with retries max config option' do
let(:build) { create(:ci_build, options: { retry: { max: 1 } }) }
context 'when build_metadata_config is set' do
before do
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
it 'returns the number of configured max retries' do
expect(result).to eq 1
end
end
......
......@@ -2214,34 +2214,12 @@ RSpec.describe Ci::Build do
expect(build.options['image']).to be_nil
end
context 'when ci_build_metadata_config is set' do
before do
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
it 'persist data in build metadata' do
expect(build.metadata.read_attribute(:config_options)).to eq(options.symbolize_keys)
end
context 'when ci_build_metadata_config is disabled' do
let(:build) { create(:ci_build, pipeline: pipeline) }
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
it 'does not persist data in build' do
expect(build.read_attribute(:options)).to be_nil
end
context 'when options include artifacts:expose_as' do
......@@ -3613,36 +3591,14 @@ RSpec.describe Ci::Build do
end
end
context 'when ci_build_metadata_config is set' do
before do
stub_feature_flags(ci_build_metadata_config: true)
end
it_behaves_like 'having consistent representation'
it_behaves_like 'having consistent representation'
it 'persist data in build metadata' do
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
it 'persist data in build metadata' do
expect(build.metadata.read_attribute(:config_variables)).not_to be_nil
end
context 'when ci_build_metadata_config is disabled' do
before do
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
it 'does not persist data in build' do
expect(build.read_attribute(:yaml_variables)).to be_nil
end
end
......@@ -4788,51 +4744,21 @@ RSpec.describe Ci::Build do
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
stub_feature_flags(ci_build_metadata_config: true)
build.write_attribute(:options, existing_options)
end
context 'when data in build is already set' do
before do
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
it 'does set metadata options' do
subject
context 'when ci_build_metadata_config is disabled' do
before do
stub_feature_flags(ci_build_metadata_config: false)
expect(build.metadata.read_attribute(:config_options)).to eq(options)
end
context 'when data in build metadata is already set' do
before do
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
it 'does reset build options' do
subject
expect(build.metadata.read_attribute(:config_options)).to be_nil
end
expect(build.read_attribute(:options)).to be_nil
end
end
end
......
......@@ -68,20 +68,6 @@ RSpec.shared_examples ::Security::JobsFinder do |default_job_types|
end
end
context 'when using legacy CI build metadata config storage' do
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
it_behaves_like 'JobsFinder core functionality'
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