Commit 3e716f36 authored by Imre Farkas's avatar Imre Farkas

Merge branch '227884-log-search-related-keywords' into 'master'

Log extra metadata about searches

Closes #227884

See merge request gitlab-org/gitlab!38020
parents 6b120d08 eb68a596
......@@ -114,4 +114,15 @@ class SearchController < ApplicationController
Gitlab::UsageDataCounters::SearchCounter.count(:navbar_searches)
end
def append_info_to_payload(payload)
super
# Merging to :metadata will ensure these are logged as top level keys
payload[:metadata] || {}
payload[:metadata]['meta.search.group_id'] = params[:group_id]
payload[:metadata]['meta.search.project_id'] = params[:project_id]
payload[:metadata]['meta.search.search'] = params[:search]
payload[:metadata]['meta.search.scope'] = params[:scope]
end
end
......@@ -216,4 +216,23 @@ RSpec.describe SearchController do
it_behaves_like 'when the user cannot read cross project', :autocomplete, { term: 'hello' }
it_behaves_like 'with external authorization service enabled', :autocomplete, { term: 'hello' }
end
describe '#append_info_to_payload' do
it 'appends search metadata for logging' do
last_payload = nil
original_append_info_to_payload = controller.method(:append_info_to_payload)
expect(controller).to receive(:append_info_to_payload) do |payload|
original_append_info_to_payload.call(payload)
last_payload = payload
end
get :show, params: { scope: 'issues', search: 'hello world', group_id: '123', project_id: '456' }
expect(last_payload[:metadata]['meta.search.group_id']).to eq('123')
expect(last_payload[:metadata]['meta.search.project_id']).to eq('456')
expect(last_payload[:metadata]['meta.search.search']).to eq('hello world')
expect(last_payload[:metadata]['meta.search.scope']).to eq('issues')
end
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