Commit 650038f6 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'track-usage-data-for-analytics-features' into 'master'

Track usage data for analytics features

See merge request gitlab-org/gitlab-ee!16431
parents a9090c96 8384dadb
......@@ -11,5 +11,9 @@ class Analytics::ApplicationController < ApplicationController
before_action(*args) { render_404 unless Feature.enabled?(flag) }
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
......@@ -2,4 +2,5 @@
class Analytics::CycleAnalyticsController < Analytics::ApplicationController
check_feature_flag Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG
increment_usage_counter Gitlab::UsageDataCounters::CycleAnalyticsCounter, :views, only: :show
end
......@@ -2,6 +2,8 @@
class Analytics::ProductivityAnalyticsController < Analytics::ApplicationController
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_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
sign_in(user)
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
it 'renders `show` template' do
stub_feature_flags(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG => true)
......
......@@ -11,6 +11,30 @@ describe Analytics::ProductivityAnalyticsController do
stub_licensed_features(productivity_analytics: true)
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
subject { get :show }
......@@ -19,7 +43,7 @@ describe Analytics::ProductivityAnalyticsController do
subject
expect(response.code).to eq '404'
expect(response).to have_gitlab_http_status(404)
end
it 'authorizes for ability to view analytics' do
......@@ -27,12 +51,13 @@ describe Analytics::ProductivityAnalyticsController do
subject
expect(response.code).to eq '403'
expect(response).to have_gitlab_http_status(403)
end
it 'renders show template' do
subject
expect(response).to be_successful
expect(response).to render_template :show
end
......@@ -66,7 +91,7 @@ describe Analytics::ProductivityAnalyticsController do
it 'renders 404' do
subject
expect(response.code).to eq '404'
expect(response).to have_gitlab_http_status(404)
end
end
......@@ -76,7 +101,7 @@ describe Analytics::ProductivityAnalyticsController do
it 'renders 404' do
subject
expect(response.code).to eq '404'
expect(response).to have_gitlab_http_status(404)
end
end
......
......@@ -142,6 +142,7 @@ module Gitlab
Gitlab::UsageDataCounters::SnippetCounter,
Gitlab::UsageDataCounters::SearchCounter,
Gitlab::UsageDataCounters::CycleAnalyticsCounter,
Gitlab::UsageDataCounters::ProductivityAnalyticsCounter,
Gitlab::UsageDataCounters::SourceCodeCounter,
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
influxdb_metrics_enabled
prometheus_metrics_enabled
cycle_analytics_views
productivity_analytics_views
))
expect(subject).to include(
......@@ -79,6 +80,7 @@ describe Gitlab::UsageData do
web_ide_merge_requests: a_kind_of(Integer),
navbar_searches: 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)
)
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