Commit 19e5bd5c authored by Andreas Brandl's avatar Andreas Brandl

Temporary instrumention for internal id lock

This adds a temporary counter `gitlab_internal_id_for_update_lock`
tracking the number of `ROW SHARE` locks on internal id records.

The counter has an additional dimension `usage` which indicates
what kind of internal id lock scope was used. Also, `changed` indicates
whether or not the actual counter value changed with the attempted
update.

This is a preparation for
https://gitlab.com/gitlab-org/gitlab/issues/30515
parent 5f2b202a
......@@ -16,6 +16,8 @@
# * Add `usage` value to enum
# * (Optionally) add columns to `internal_ids` if needed for scope.
class InternalId < ApplicationRecord
include Gitlab::Utils::StrongMemoize
belongs_to :project
belongs_to :namespace
......@@ -47,10 +49,18 @@ class InternalId < ApplicationRecord
def update_and_save(&block)
lock!
yield
update_and_save_counter.increment(usage: usage, changed: last_value_changed?)
save!
last_value
end
# Temporary instrumentation to track for-update locks
def update_and_save_counter
strong_memoize(:update_and_save_counter) do
Gitlab::Metrics.counter(:gitlab_internal_id_for_update_lock, 'Number of ROW SHARE (FOR UPDATE) locks on individual records from internal_ids')
end
end
class << self
def track_greatest(subject, scope, usage, new_value, init)
return new_value unless available?
......
......@@ -71,6 +71,7 @@ describe Ci::CreatePipelineService do
expect(Gitlab::Metrics).to receive(:counter)
.with(:pipelines_created_total, "Counter of pipelines created")
.and_call_original
allow(Gitlab::Metrics).to receive(:counter).and_call_original # allow other counters
pipeline
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