Commit 9a0d86b7 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'yorick/loose-fk-metrics' into 'master'

Add Prometheus metrics for loose foreign keys

See merge request gitlab-org/gitlab!73192
parents 5f30b95f 3076b649
......@@ -12,14 +12,24 @@ module LooseForeignKeys
@delete_count_by_table = Hash.new { |h, k| h[k] = 0 }
@update_count_by_table = Hash.new { |h, k| h[k] = 0 }
@start_time = monotonic_time
@deletes_counter = Gitlab::Metrics.counter(
:loose_foreign_key_deletions,
'The number of loose foreign key deletions'
)
@updates_counter = Gitlab::Metrics.counter(
:loose_foreign_key_updates,
'The number of loose foreign key updates'
)
end
def add_deletions(table, count)
@delete_count_by_table[table] += count
@deletes_counter.increment({ table: table }, count)
end
def add_updates(table, count)
@update_count_by_table[table] += count
@updates_counter.increment({ table: table }, count)
end
def over_limit?
......
......@@ -50,6 +50,26 @@ RSpec.describe LooseForeignKeys::ModificationTracker do
end
end
describe '#add_deletions' do
it 'increments a Prometheus counter' do
counter = Gitlab::Metrics.registry.get(:loose_foreign_key_deletions)
subject.add_deletions(:users, 4)
expect(counter.get(table: :users)).to eq(4)
end
end
describe '#add_updates' do
it 'increments a Prometheus counter' do
counter = Gitlab::Metrics.registry.get(:loose_foreign_key_updates)
subject.add_updates(:users, 4)
expect(counter.get(table: :users)).to eq(4)
end
end
describe '#stats' do
it 'exposes stats' do
freeze_time do
......
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