Added navbar searches usage ping counter
Added usage ping counter when the user makes a search through the navbar search component.
This commit is contained in:
parent
77926ea025
commit
26e9efc011
|
@ -31,6 +31,8 @@ class SearchController < ApplicationController
|
|||
render_commits if @scope == 'commits'
|
||||
eager_load_user_status if @scope == 'users'
|
||||
|
||||
increment_navbar_searches_counter
|
||||
|
||||
check_single_commit_result
|
||||
end
|
||||
|
||||
|
@ -70,4 +72,10 @@ class SearchController < ApplicationController
|
|||
redirect_to project_commit_path(@project, only_commit) if found_by_commit_sha
|
||||
end
|
||||
end
|
||||
|
||||
def increment_navbar_searches_counter
|
||||
return if params[:nav_source] != 'navbar'
|
||||
|
||||
Gitlab::UsageDataCounters::SearchCounter.increment_navbar_searches_count
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,5 +45,6 @@
|
|||
- if @snippet || @snippets
|
||||
= hidden_field_tag :snippets, true
|
||||
= hidden_field_tag :repository_ref, @ref
|
||||
= hidden_field_tag :nav_source, 'navbar'
|
||||
= button_tag 'Go' if ENV['RAILS_ENV'] == 'test'
|
||||
.search-autocomplete-opts.hide{ :'data-autocomplete-path' => search_autocomplete_path, :'data-autocomplete-project-id' => @project.try(:id), :'data-autocomplete-project-ref' => @ref }
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Added navbar searches usage ping counter
|
||||
merge_request: 30953
|
||||
author:
|
||||
type: changed
|
|
@ -137,8 +137,11 @@ module Gitlab
|
|||
|
||||
# @return [Array<#totals>] An array of objects that respond to `#totals`
|
||||
def usage_data_counters
|
||||
[Gitlab::UsageDataCounters::WikiPageCounter,
|
||||
Gitlab::UsageDataCounters::WebIdeCounter]
|
||||
[
|
||||
Gitlab::UsageDataCounters::WikiPageCounter,
|
||||
Gitlab::UsageDataCounters::WebIdeCounter,
|
||||
Gitlab::UsageDataCounters::SearchCounter
|
||||
]
|
||||
end
|
||||
|
||||
def components_usage_data
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Gitlab
|
||||
module UsageDataCounters
|
||||
class SearchCounter
|
||||
extend RedisCounter
|
||||
|
||||
NAVBAR_SEARCHES_COUNT_KEY = 'NAVBAR_SEARCHES_COUNT'
|
||||
|
||||
class << self
|
||||
def increment_navbar_searches_count
|
||||
increment(NAVBAR_SEARCHES_COUNT_KEY)
|
||||
end
|
||||
|
||||
def total_navbar_searches_count
|
||||
total_count(NAVBAR_SEARCHES_COUNT_KEY)
|
||||
end
|
||||
|
||||
def totals
|
||||
{
|
||||
navbar_searches: total_navbar_searches_count
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,6 +9,15 @@ describe 'Global search' do
|
|||
before do
|
||||
project.add_maintainer(user)
|
||||
sign_in(user)
|
||||
|
||||
visit dashboard_projects_path
|
||||
end
|
||||
|
||||
it 'increases usage ping searches counter' do
|
||||
expect(Gitlab::UsageDataCounters::SearchCounter).to receive(:increment_navbar_searches_count)
|
||||
|
||||
fill_in "search", with: "foobar"
|
||||
click_button "Go"
|
||||
end
|
||||
|
||||
describe 'I search through the issues and I see pagination' do
|
||||
|
@ -18,8 +27,6 @@ describe 'Global search' do
|
|||
end
|
||||
|
||||
it "has a pagination" do
|
||||
visit dashboard_projects_path
|
||||
|
||||
fill_in "search", with: "initial"
|
||||
click_button "Go"
|
||||
|
||||
|
@ -29,8 +36,6 @@ describe 'Global search' do
|
|||
end
|
||||
|
||||
it 'closes the dropdown on blur', :js do
|
||||
visit dashboard_projects_path
|
||||
|
||||
fill_in 'search', with: "a"
|
||||
dropdown = find('.js-dashboard-search-options')
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::UsageDataCounters::SearchCounter, :clean_gitlab_redis_shared_state do
|
||||
it 'increments counter and return the total count' do
|
||||
expect(described_class.total_navbar_searches_count).to eq(0)
|
||||
|
||||
2.times { described_class.increment_navbar_searches_count }
|
||||
|
||||
expect(described_class.total_navbar_searches_count).to eq(2)
|
||||
end
|
||||
end
|
|
@ -67,7 +67,8 @@ describe Gitlab::UsageData do
|
|||
wiki_pages_delete: a_kind_of(Integer),
|
||||
web_ide_views: a_kind_of(Integer),
|
||||
web_ide_commits: a_kind_of(Integer),
|
||||
web_ide_merge_requests: a_kind_of(Integer)
|
||||
web_ide_merge_requests: a_kind_of(Integer),
|
||||
navbar_searches: a_kind_of(Integer)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue