Commit 26e9efc0 authored by Francisco Javier López's avatar Francisco Javier López Committed by Paul Slaughter

Added navbar searches usage ping counter

Added usage ping counter when the user makes
a search through the navbar search component.
parent 77926ea0
...@@ -31,6 +31,8 @@ class SearchController < ApplicationController ...@@ -31,6 +31,8 @@ class SearchController < ApplicationController
render_commits if @scope == 'commits' render_commits if @scope == 'commits'
eager_load_user_status if @scope == 'users' eager_load_user_status if @scope == 'users'
increment_navbar_searches_counter
check_single_commit_result check_single_commit_result
end end
...@@ -70,4 +72,10 @@ class SearchController < ApplicationController ...@@ -70,4 +72,10 @@ class SearchController < ApplicationController
redirect_to project_commit_path(@project, only_commit) if found_by_commit_sha redirect_to project_commit_path(@project, only_commit) if found_by_commit_sha
end end
end end
def increment_navbar_searches_counter
return if params[:nav_source] != 'navbar'
Gitlab::UsageDataCounters::SearchCounter.increment_navbar_searches_count
end
end end
...@@ -45,5 +45,6 @@ ...@@ -45,5 +45,6 @@
- if @snippet || @snippets - if @snippet || @snippets
= hidden_field_tag :snippets, true = hidden_field_tag :snippets, true
= hidden_field_tag :repository_ref, @ref = hidden_field_tag :repository_ref, @ref
= hidden_field_tag :nav_source, 'navbar'
= button_tag 'Go' if ENV['RAILS_ENV'] == 'test' = 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 } .search-autocomplete-opts.hide{ :'data-autocomplete-path' => search_autocomplete_path, :'data-autocomplete-project-id' => @project.try(:id), :'data-autocomplete-project-ref' => @ref }
---
title: Added navbar searches usage ping counter
merge_request: 30953
author:
type: changed
...@@ -137,8 +137,11 @@ module Gitlab ...@@ -137,8 +137,11 @@ module Gitlab
# @return [Array<#totals>] An array of objects that respond to `#totals` # @return [Array<#totals>] An array of objects that respond to `#totals`
def usage_data_counters def usage_data_counters
[Gitlab::UsageDataCounters::WikiPageCounter, [
Gitlab::UsageDataCounters::WebIdeCounter] Gitlab::UsageDataCounters::WikiPageCounter,
Gitlab::UsageDataCounters::WebIdeCounter,
Gitlab::UsageDataCounters::SearchCounter
]
end end
def components_usage_data def components_usage_data
......
# 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 ...@@ -9,6 +9,15 @@ describe 'Global search' do
before do before do
project.add_maintainer(user) project.add_maintainer(user)
sign_in(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 end
describe 'I search through the issues and I see pagination' do describe 'I search through the issues and I see pagination' do
...@@ -18,8 +27,6 @@ describe 'Global search' do ...@@ -18,8 +27,6 @@ describe 'Global search' do
end end
it "has a pagination" do it "has a pagination" do
visit dashboard_projects_path
fill_in "search", with: "initial" fill_in "search", with: "initial"
click_button "Go" click_button "Go"
...@@ -29,8 +36,6 @@ describe 'Global search' do ...@@ -29,8 +36,6 @@ describe 'Global search' do
end end
it 'closes the dropdown on blur', :js do it 'closes the dropdown on blur', :js do
visit dashboard_projects_path
fill_in 'search', with: "a" fill_in 'search', with: "a"
dropdown = find('.js-dashboard-search-options') dropdown = find('.js-dashboard-search-options')
......
# 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 ...@@ -67,7 +67,8 @@ describe Gitlab::UsageData do
wiki_pages_delete: a_kind_of(Integer), wiki_pages_delete: a_kind_of(Integer),
web_ide_views: a_kind_of(Integer), web_ide_views: a_kind_of(Integer),
web_ide_commits: 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 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