Commit 8384dadb authored by Adam Hegyi's avatar Adam Hegyi Committed by Peter Leitzen

Track usage data for CA and PA features

- Track page view counts for Group Cycle Analytics.
- Setup counter for Productivity Analytics and track page view counts.
- Add changelog entry
parent a9090c96
...@@ -11,5 +11,9 @@ class Analytics::ApplicationController < ApplicationController ...@@ -11,5 +11,9 @@ class Analytics::ApplicationController < ApplicationController
before_action(*args) { render_404 unless Feature.enabled?(flag) } before_action(*args) { render_404 unless Feature.enabled?(flag) }
end end
private_class_method :check_feature_flag def self.increment_usage_counter(counter_klass, counter, *args)
before_action(*args) { counter_klass.count(counter) }
end
private_class_method :check_feature_flag, :increment_usage_counter
end end
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
class Analytics::CycleAnalyticsController < Analytics::ApplicationController class Analytics::CycleAnalyticsController < Analytics::ApplicationController
check_feature_flag Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG check_feature_flag Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG
increment_usage_counter Gitlab::UsageDataCounters::CycleAnalyticsCounter, :views, only: :show
end end
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
class Analytics::ProductivityAnalyticsController < Analytics::ApplicationController class Analytics::ProductivityAnalyticsController < Analytics::ApplicationController
check_feature_flag Gitlab::Analytics::PRODUCTIVITY_ANALYTICS_FEATURE_FLAG check_feature_flag Gitlab::Analytics::PRODUCTIVITY_ANALYTICS_FEATURE_FLAG
increment_usage_counter Gitlab::UsageDataCounters::ProductivityAnalyticsCounter,
:views, only: :show, if: -> { request.format.html? }
before_action :load_group before_action :load_group
before_action :load_project before_action :load_project
......
---
title: Track page view counts for Cycle Analytics and Productivity Analytics features
merge_request: 16431
author:
type: added
...@@ -9,6 +9,16 @@ describe Analytics::CycleAnalyticsController do ...@@ -9,6 +9,16 @@ describe Analytics::CycleAnalyticsController do
sign_in(user) sign_in(user)
end end
describe 'usage counter' do
it 'increments usage counter' do
expect(Gitlab::UsageDataCounters::CycleAnalyticsCounter).to receive(:count).with(:views)
get(:show)
expect(response).to be_successful
end
end
describe 'GET show' do describe 'GET show' do
it 'renders `show` template' do it 'renders `show` template' do
stub_feature_flags(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG => true) stub_feature_flags(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG => true)
......
...@@ -11,6 +11,30 @@ describe Analytics::ProductivityAnalyticsController do ...@@ -11,6 +11,30 @@ describe Analytics::ProductivityAnalyticsController do
stub_licensed_features(productivity_analytics: true) stub_licensed_features(productivity_analytics: true)
end end
describe 'usage counter' do
let(:group) { create :group }
before do
group.add_owner(current_user)
end
it 'increments usage counter' do
expect(Gitlab::UsageDataCounters::ProductivityAnalyticsCounter).to receive(:count).with(:views)
get :show, format: :html
expect(response).to be_successful
end
it "doesn't increment the usage counter when JSON request is sent" do
expect(Gitlab::UsageDataCounters::ProductivityAnalyticsCounter).not_to receive(:count).with(:views)
get :show, format: :json
expect(response).to be_successful
end
end
describe 'GET show' do describe 'GET show' do
subject { get :show } subject { get :show }
...@@ -19,7 +43,7 @@ describe Analytics::ProductivityAnalyticsController do ...@@ -19,7 +43,7 @@ describe Analytics::ProductivityAnalyticsController do
subject subject
expect(response.code).to eq '404' expect(response).to have_gitlab_http_status(404)
end end
it 'authorizes for ability to view analytics' do it 'authorizes for ability to view analytics' do
...@@ -27,12 +51,13 @@ describe Analytics::ProductivityAnalyticsController do ...@@ -27,12 +51,13 @@ describe Analytics::ProductivityAnalyticsController do
subject subject
expect(response.code).to eq '403' expect(response).to have_gitlab_http_status(403)
end end
it 'renders show template' do it 'renders show template' do
subject subject
expect(response).to be_successful
expect(response).to render_template :show expect(response).to render_template :show
end end
...@@ -66,7 +91,7 @@ describe Analytics::ProductivityAnalyticsController do ...@@ -66,7 +91,7 @@ describe Analytics::ProductivityAnalyticsController do
it 'renders 404' do it 'renders 404' do
subject subject
expect(response.code).to eq '404' expect(response).to have_gitlab_http_status(404)
end end
end end
...@@ -76,7 +101,7 @@ describe Analytics::ProductivityAnalyticsController do ...@@ -76,7 +101,7 @@ describe Analytics::ProductivityAnalyticsController do
it 'renders 404' do it 'renders 404' do
subject subject
expect(response.code).to eq '404' expect(response).to have_gitlab_http_status(404)
end end
end end
......
...@@ -142,6 +142,7 @@ module Gitlab ...@@ -142,6 +142,7 @@ module Gitlab
Gitlab::UsageDataCounters::SnippetCounter, Gitlab::UsageDataCounters::SnippetCounter,
Gitlab::UsageDataCounters::SearchCounter, Gitlab::UsageDataCounters::SearchCounter,
Gitlab::UsageDataCounters::CycleAnalyticsCounter, Gitlab::UsageDataCounters::CycleAnalyticsCounter,
Gitlab::UsageDataCounters::ProductivityAnalyticsCounter,
Gitlab::UsageDataCounters::SourceCodeCounter, Gitlab::UsageDataCounters::SourceCodeCounter,
Gitlab::UsageDataCounters::MergeRequestCounter Gitlab::UsageDataCounters::MergeRequestCounter
] ]
......
# frozen_string_literal: true
module Gitlab::UsageDataCounters
class ProductivityAnalyticsCounter < BaseCounter
KNOWN_EVENTS = %w[views].freeze
PREFIX = 'productivity_analytics'
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::UsageDataCounters::ProductivityAnalyticsCounter do
it_behaves_like 'a redis usage counter', 'ProductivityAnalytics', :views
it_behaves_like 'a redis usage counter with totals', :productivity_analytics, views: 3
end
...@@ -62,6 +62,7 @@ describe Gitlab::UsageData do ...@@ -62,6 +62,7 @@ describe Gitlab::UsageData do
influxdb_metrics_enabled influxdb_metrics_enabled
prometheus_metrics_enabled prometheus_metrics_enabled
cycle_analytics_views cycle_analytics_views
productivity_analytics_views
)) ))
expect(subject).to include( expect(subject).to include(
...@@ -79,6 +80,7 @@ describe Gitlab::UsageData do ...@@ -79,6 +80,7 @@ describe Gitlab::UsageData do
web_ide_merge_requests: a_kind_of(Integer), web_ide_merge_requests: a_kind_of(Integer),
navbar_searches: a_kind_of(Integer), navbar_searches: a_kind_of(Integer),
cycle_analytics_views: a_kind_of(Integer), cycle_analytics_views: a_kind_of(Integer),
productivity_analytics_views: a_kind_of(Integer),
source_code_pushes: a_kind_of(Integer) source_code_pushes: 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