Commit e27e5f97 authored by Adam Hegyi's avatar Adam Hegyi

Detect unsupported keyset queries with Prometheus

parent e377606b
......@@ -73,10 +73,25 @@ module Gitlab
strong_memoize(:generic_keyset_pagination_items) do
rebuilt_items_with_keyset_order, success = Gitlab::Pagination::Keyset::SimpleOrderBuilder.build(original_items)
success ? rebuilt_items_with_keyset_order : original_items
if success
rebuilt_items_with_keyset_order
else
if original_items.is_a?(ActiveRecord::Relation)
old_keyset_pagination_usage.increment({ model: original_items.model.to_s })
end
original_items
end
end
end
def old_keyset_pagination_usage
@old_keyset_pagination_usage ||= Gitlab::Metrics.counter(
:old_keyset_pagination_usage,
'The number of times the old keyset pagination code was used'
)
end
end
end
end
end
......
......@@ -77,6 +77,17 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::Connection do
expect(decoded_cursor(cursor)).to eq('id' => project.id.to_s)
end
context 'when SimpleOrderBuilder cannot build keyset paginated query' do
it 'increments the `old_keyset_pagination_usage` counter', :prometheus do
expect(Gitlab::Pagination::Keyset::SimpleOrderBuilder).to receive(:build).and_return([false, nil])
decoded_cursor(cursor)
counter = Gitlab::Metrics.registry.get(:old_keyset_pagination_usage)
expect(counter.get(model: 'Project')).to eq(1)
end
end
context 'when an order is specified' do
let(:nodes) { Project.order(:updated_at) }
......
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