diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2019-07-19 18:56:25 +0200 |
---|---|---|
committer | Paul Slaughter <pslaughter@gitlab.com> | 2019-07-29 03:47:12 -0500 |
commit | 2769388bdbfc3f705072a18afea8a1689e9c5a24 (patch) | |
tree | 3ea28ca881d8b3b805725b9498893cd1226c323e | |
parent | aa0d8b4cbac34c3aac20fbb45c676e0c8d22f1f9 (diff) | |
download | gitlab-ce-fj-navbar-searches-usage-ping-counter.tar.gz |
Added navbar searches usage ping counterfj-navbar-searches-usage-ping-counter
Added usage ping counter when the user makes
a search through the navbar search component.
-rw-r--r-- | app/controllers/search_controller.rb | 8 | ||||
-rw-r--r-- | app/views/layouts/_search.html.haml | 1 | ||||
-rw-r--r-- | changelogs/unreleased/fj-navbar-searches-usage-ping-counter.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/usage_data.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/usage_data_counters/search_counter.rb | 27 | ||||
-rw-r--r-- | spec/features/global_search_spec.rb | 13 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/search_counter_spec.rb | 13 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 3 |
8 files changed, 70 insertions, 7 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 8c674be58c5..13741548687 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -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 diff --git a/app/views/layouts/_search.html.haml b/app/views/layouts/_search.html.haml index c62dce880c0..9cac8266eaf 100644 --- a/app/views/layouts/_search.html.haml +++ b/app/views/layouts/_search.html.haml @@ -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 } diff --git a/changelogs/unreleased/fj-navbar-searches-usage-ping-counter.yml b/changelogs/unreleased/fj-navbar-searches-usage-ping-counter.yml new file mode 100644 index 00000000000..ab7c1697fd6 --- /dev/null +++ b/changelogs/unreleased/fj-navbar-searches-usage-ping-counter.yml @@ -0,0 +1,5 @@ +--- +title: Added navbar searches usage ping counter +merge_request: 30953 +author: +type: changed diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index db1086c9cae..d5657c474c8 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -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 diff --git a/lib/gitlab/usage_data_counters/search_counter.rb b/lib/gitlab/usage_data_counters/search_counter.rb new file mode 100644 index 00000000000..5f0735347e1 --- /dev/null +++ b/lib/gitlab/usage_data_counters/search_counter.rb @@ -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 diff --git a/spec/features/global_search_spec.rb b/spec/features/global_search_spec.rb index 3efbeddb7aa..a7ccc6f7d7b 100644 --- a/spec/features/global_search_spec.rb +++ b/spec/features/global_search_spec.rb @@ -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') diff --git a/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb new file mode 100644 index 00000000000..50a9f980dc7 --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb @@ -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 diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 2289d906944..6d0a2098b2e 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -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 |