Commit 8672eac5 authored by Douwe Maan's avatar Douwe Maan

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
parents 36898558 1e662293
---
title: Adds Web IDE commits to usage ping
merge_request: 22007
author:
type: added
...@@ -110,6 +110,9 @@ module API ...@@ -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)
......
...@@ -10,6 +10,7 @@ module Gitlab ...@@ -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 ...@@ -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 },
......
# 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
...@@ -46,6 +46,7 @@ describe Gitlab::UsageData do ...@@ -46,6 +46,7 @@ describe Gitlab::UsageData do
git git
database database
avg_cycle_analytics avg_cycle_analytics
web_ide_commits
)) ))
end end
......
# 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
...@@ -278,6 +278,12 @@ describe API::Commits do ...@@ -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
......
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