summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-10-03 13:02:43 +0000
committerDouwe Maan <douwe@gitlab.com>2018-10-03 13:02:43 +0000
commit8672eac592dd14602f45af7e0541bc05e8629dc8 (patch)
treeea99ce595909549cfb2528a4d3c8561ff7508615
parent36898558600ff3e43c918eb3d96066934499b632 (diff)
parent1e662293e8fc2f2eba9657dd27449e966736a14a (diff)
downloadgitlab-ce-8672eac592dd14602f45af7e0541bc05e8629dc8.tar.gz
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
-rw-r--r--changelogs/unreleased/45016-add-web-ide-commits-to-usage-ping.yml5
-rw-r--r--lib/api/commits.rb3
-rw-r--r--lib/gitlab/usage_data.rb7
-rw-r--r--lib/gitlab/web_ide_commits_counter.rb17
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb1
-rw-r--r--spec/lib/gitlab/web_ide_commits_counter_spec.rb19
-rw-r--r--spec/requests/api/commits_spec.rb6
7 files changed, 58 insertions, 0 deletions
diff --git a/changelogs/unreleased/45016-add-web-ide-commits-to-usage-ping.yml b/changelogs/unreleased/45016-add-web-ide-commits-to-usage-ping.yml
new file mode 100644
index 00000000000..a7f24742588
--- /dev/null
+++ b/changelogs/unreleased/45016-add-web-ide-commits-to-usage-ping.yml
@@ -0,0 +1,5 @@
+---
+title: Adds Web IDE commits to usage ping
+merge_request: 22007
+author:
+type: added
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index f0db1318146..ff927d1aa3c 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -110,6 +110,9 @@ module API
if result[:status] == :success
commit_detail = user_project.repository.commit(result[:result])
+
+ Gitlab::WebIdeCommitsCounter.increment if find_user_from_warden
+
present commit_detail, with: Entities::CommitDetail
else
render_api_error!(result[:message], 400)
diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb
index f7d8ee571cd..5097c3253c9 100644
--- a/lib/gitlab/usage_data.rb
+++ b/lib/gitlab/usage_data.rb
@@ -10,6 +10,7 @@ module Gitlab
.merge(features_usage_data)
.merge(components_usage_data)
.merge(cycle_analytics_usage_data)
+ .merge(usage_counters)
end
def to_json(force_refresh: false)
@@ -106,6 +107,12 @@ module Gitlab
}
end
+ def usage_counters
+ {
+ web_ide_commits: Gitlab::WebIdeCommitsCounter.total_count
+ }
+ end
+
def components_usage_data
{
gitlab_pages: { enabled: Gitlab.config.pages.enabled, version: Gitlab::Pages::VERSION },
diff --git a/lib/gitlab/web_ide_commits_counter.rb b/lib/gitlab/web_ide_commits_counter.rb
new file mode 100644
index 00000000000..1cd9b5295b9
--- /dev/null
+++ b/lib/gitlab/web_ide_commits_counter.rb
@@ -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
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index 1ec1fe10744..d669c42ab4a 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -46,6 +46,7 @@ describe Gitlab::UsageData do
git
database
avg_cycle_analytics
+ web_ide_commits
))
end
diff --git a/spec/lib/gitlab/web_ide_commits_counter_spec.rb b/spec/lib/gitlab/web_ide_commits_counter_spec.rb
new file mode 100644
index 00000000000..c51889a1c63
--- /dev/null
+++ b/spec/lib/gitlab/web_ide_commits_counter_spec.rb
@@ -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
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index f3fb88474a4..06ccf383362 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -278,6 +278,12 @@ describe API::Commits do
}
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
post api(url, user), valid_c_params