Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
parent
e99d2e196c
commit
4dd542c935
|
|
@ -19,6 +19,11 @@ module Ci
|
|||
validates :target_project, presence: true
|
||||
validate :not_self_referential_link
|
||||
|
||||
enum direction: {
|
||||
outbound: 0,
|
||||
inbound: 1
|
||||
}
|
||||
|
||||
def self.for_source_and_target(source_project, target_project)
|
||||
self.find_by(source_project: source_project, target_project: target_project)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -131,14 +131,14 @@ module CounterAttribute
|
|||
end
|
||||
|
||||
def update_counters_with_lease(increments)
|
||||
detect_race_on_record(log_fields: increments.merge({ caller: __method__ })) do
|
||||
detect_race_on_record(log_fields: { caller: __method__, attributes: increments.keys }) do
|
||||
self.class.update_counters(id, increments)
|
||||
end
|
||||
end
|
||||
|
||||
def reset_counter!(attribute)
|
||||
if counter_attribute_enabled?(attribute)
|
||||
detect_race_on_record(log_fields: { caller: __method__ }) do
|
||||
detect_race_on_record(log_fields: { caller: __method__, attributes: attribute }) do
|
||||
update!(attribute => 0)
|
||||
clear_counter!(attribute)
|
||||
end
|
||||
|
|
@ -219,13 +219,25 @@ module CounterAttribute
|
|||
def detect_race_on_record(log_fields: {})
|
||||
return yield unless Feature.enabled?(:counter_attribute_db_lease_for_update, project)
|
||||
|
||||
in_lock(database_lock_key, retries: 2) do
|
||||
# Ensure attributes is always an array before we log
|
||||
log_fields[:attributes] = Array(log_fields[:attributes])
|
||||
|
||||
Gitlab::AppLogger.info(
|
||||
message: 'Acquiring lease for project statistics update',
|
||||
project_statistics_id: id,
|
||||
project_id: project.id,
|
||||
**log_fields,
|
||||
**Gitlab::ApplicationContext.current
|
||||
)
|
||||
|
||||
in_lock(database_lock_key, retries: 0) do
|
||||
yield
|
||||
end
|
||||
rescue Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError
|
||||
Gitlab::AppLogger.warn(
|
||||
message: 'Concurrent update to project statistics detected',
|
||||
message: 'Concurrent project statistics update detected',
|
||||
project_statistics_id: id,
|
||||
project_id: project.id,
|
||||
**log_fields,
|
||||
**Gitlab::ApplicationContext.current
|
||||
)
|
||||
|
|
|
|||
|
|
@ -50,17 +50,16 @@ class ProjectStatistics < ApplicationRecord
|
|||
def refresh!(only: [])
|
||||
return if Gitlab::Database.read_only?
|
||||
|
||||
COLUMNS_TO_REFRESH.each do |column, generator|
|
||||
if only.empty? || only.include?(column)
|
||||
public_send("update_#{column}") # rubocop:disable GitlabSecurity/PublicSend
|
||||
end
|
||||
columns_to_update = only.empty? ? COLUMNS_TO_REFRESH : COLUMNS_TO_REFRESH & only
|
||||
columns_to_update.each do |column|
|
||||
public_send("update_#{column}") # rubocop:disable GitlabSecurity/PublicSend
|
||||
end
|
||||
|
||||
if only.empty? || only.any? { |column| NAMESPACE_RELATABLE_COLUMNS.include?(column) }
|
||||
schedule_namespace_aggregation_worker
|
||||
end
|
||||
|
||||
detect_race_on_record(log_fields: { caller: __method__ }) do
|
||||
detect_race_on_record(log_fields: { caller: __method__, attributes: columns_to_update }) do
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
|
@ -114,7 +113,7 @@ class ProjectStatistics < ApplicationRecord
|
|||
end
|
||||
|
||||
def refresh_storage_size!
|
||||
detect_race_on_record(log_fields: { caller: __method__ }) do
|
||||
detect_race_on_record(log_fields: { caller: __method__, attributes: :storage_size }) do
|
||||
update!(storage_size: STORAGE_SIZE_SUM)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddInboundCiJobTokenProjectScopeLinks < Gitlab::Database::Migration[2.0]
|
||||
enable_lock_retries!
|
||||
|
||||
def up
|
||||
add_column :ci_job_token_project_scope_links, :direction, :integer, limit: 2, default: 0, null: false
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :ci_job_token_project_scope_links, :direction
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
4685b471f00f8ef5e8d8e521c50dc276c757c9f9caa50b1aa20c1f98b8b008c5
|
||||
|
|
@ -12833,7 +12833,8 @@ CREATE TABLE ci_job_token_project_scope_links (
|
|||
source_project_id bigint NOT NULL,
|
||||
target_project_id bigint NOT NULL,
|
||||
added_by_id bigint,
|
||||
created_at timestamp with time zone NOT NULL
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
direction smallint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
CREATE SEQUENCE ci_job_token_project_scope_links_id_seq
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ dependency_scanning:
|
|||
artifacts:
|
||||
paths:
|
||||
- "**/gl-sbom-*.cdx.json"
|
||||
reports:
|
||||
cyclonedx: "**/gl-sbom-*.cdx.json"
|
||||
|
||||
.gemnasium-shared-rule:
|
||||
exists:
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ dependency_scanning:
|
|||
artifacts:
|
||||
paths:
|
||||
- "**/gl-sbom-*.cdx.json"
|
||||
reports:
|
||||
cyclonedx: "**/gl-sbom-*.cdx.json"
|
||||
|
||||
.gemnasium-shared-rule:
|
||||
exists:
|
||||
|
|
|
|||
|
|
@ -89,6 +89,12 @@ RSpec.describe Ci::JobToken::ProjectScopeLink do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'enums' do
|
||||
let(:directions) { { outbound: 0, inbound: 1 } }
|
||||
|
||||
it { is_expected.to define_enum_for(:direction).with_values(directions) }
|
||||
end
|
||||
|
||||
context 'loose foreign key on ci_job_token_project_scope_links.source_project_id' do
|
||||
it_behaves_like 'cleanup by a loose foreign key' do
|
||||
let!(:parent) { create(:project) }
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ RSpec.describe Ci::PipelineArtifacts::CoverageReportService do
|
|||
end
|
||||
|
||||
it 'logs relevant information' do
|
||||
allow(Gitlab::AppLogger).to receive(:info).and_call_original
|
||||
expect(Gitlab::AppLogger).to receive(:info).with({
|
||||
project_id: project.id,
|
||||
pipeline_id: pipeline.id,
|
||||
|
|
|
|||
|
|
@ -104,7 +104,14 @@ RSpec.shared_examples_for CounterAttribute do |counter_attributes|
|
|||
model.delayed_increment_counter(incremented_attribute, -3)
|
||||
end
|
||||
|
||||
it 'updates the record and logs it' do
|
||||
it 'updates the record and logs it', :aggregate_failures do
|
||||
expect(Gitlab::AppLogger).to receive(:info).with(
|
||||
hash_including(
|
||||
message: 'Acquiring lease for project statistics update',
|
||||
attributes: [incremented_attribute]
|
||||
)
|
||||
)
|
||||
|
||||
expect(Gitlab::AppLogger).to receive(:info).with(
|
||||
hash_including(
|
||||
message: 'Flush counter attribute to database',
|
||||
|
|
|
|||
Loading…
Reference in New Issue