Merge branch '45016-add-web-ide-commits-to-usage-ping' into 'master'

Adds Web IDE commits to usage ping

Closes #45016

See merge request gitlab-org/gitlab-ce!22007
This commit is contained in:
Douwe Maan 2018-10-03 13:02:43 +00:00
commit 8672eac592
7 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
title: Adds Web IDE commits to usage ping
merge_request: 22007
author:
type: added

View File

@ -110,6 +110,9 @@ module API
if result[:status] == :success if result[:status] == :success
commit_detail = user_project.repository.commit(result[:result]) commit_detail = user_project.repository.commit(result[:result])
Gitlab::WebIdeCommitsCounter.increment if find_user_from_warden
present commit_detail, with: Entities::CommitDetail present commit_detail, with: Entities::CommitDetail
else else
render_api_error!(result[:message], 400) render_api_error!(result[:message], 400)

View File

@ -10,6 +10,7 @@ module Gitlab
.merge(features_usage_data) .merge(features_usage_data)
.merge(components_usage_data) .merge(components_usage_data)
.merge(cycle_analytics_usage_data) .merge(cycle_analytics_usage_data)
.merge(usage_counters)
end end
def to_json(force_refresh: false) def to_json(force_refresh: false)
@ -106,6 +107,12 @@ module Gitlab
} }
end end
def usage_counters
{
web_ide_commits: Gitlab::WebIdeCommitsCounter.total_count
}
end
def components_usage_data def components_usage_data
{ {
gitlab_pages: { enabled: Gitlab.config.pages.enabled, version: Gitlab::Pages::VERSION }, gitlab_pages: { enabled: Gitlab.config.pages.enabled, version: Gitlab::Pages::VERSION },

View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Gitlab
module WebIdeCommitsCounter
WEB_IDE_COMMITS_KEY = "WEB_IDE_COMMITS_COUNT".freeze
class << self
def increment
Gitlab::Redis::SharedState.with { |redis| redis.incr(WEB_IDE_COMMITS_KEY) }
end
def total_count
Gitlab::Redis::SharedState.with { |redis| redis.get(WEB_IDE_COMMITS_KEY).to_i }
end
end
end
end

View File

@ -46,6 +46,7 @@ describe Gitlab::UsageData do
git git
database database
avg_cycle_analytics avg_cycle_analytics
web_ide_commits
)) ))
end end

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::WebIdeCommitsCounter, :clean_gitlab_redis_shared_state do
describe '.increment' do
it 'increments the web ide commits counter by 1' do
expect do
described_class.increment
end.to change { described_class.total_count }.from(0).to(1)
end
end
describe '.total_count' do
it 'returns the total amount of web ide commits' do
expect(described_class.total_count).to eq(0)
end
end
end

View File

@ -278,6 +278,12 @@ describe API::Commits do
} }
end end
it 'does not increment the usage counters using access token authentication' do
expect(::Gitlab::WebIdeCommitsCounter).not_to receive(:increment)
post api(url, user), valid_c_params
end
it 'a new file in project repo' do it 'a new file in project repo' do
post api(url, user), valid_c_params post api(url, user), valid_c_params