Commit 3ed1feaa authored by Sean McGivern's avatar Sean McGivern

Merge branch '4547-measure-multi-file-editor-usage-on-gitlab-com' into 'master'

Resolve "Measure multi-file editor usage on GitLab.com"

Closes #4547

See merge request gitlab-org/gitlab-ee!4226
parents 14d57792 589096dc
---
title: Add multi-file editor usage metrics
merge_request: 4226
author:
type: added
module Gitlab
module Metrics
class MultiFileEditor
delegate :total, to: :commit_stats, prefix: :line_changes
def initialize(project, current_user, commit)
@project, @current_user, @commit = project, current_user, commit
end
def log
return unless ::License.feature_available?(:ide)
Rails.logger.info("Web editor usage - #{metric_info}")
end
private
def files_total
@commit.diffs.size
end
def commit_stats
@commit.stats
end
def metric_info
"ide_usage_project_id: #{@project.id}, ide_usage_user: #{@current_user.id}, ide_usage_line_count: #{line_changes_total}, ide_usage_file_count: #{files_total}"
end
end
end
end
......@@ -70,6 +70,11 @@ module API
if result[:status] == :success
commit_detail = user_project.repository.commit(result[:result])
if find_user_from_warden
::Gitlab::Metrics::MultiFileEditor.new(user_project, current_user, commit_detail).log
end
present commit_detail, with: Entities::CommitDetail
else
render_api_error!(result[:message], 400)
......
require 'spec_helper'
describe Gitlab::Metrics::MultiFileEditor do
set(:project) { create(:project, :repository) }
let(:user) { create(:user) }
subject { described_class.new(project, user, project.commit('b83d6e391c22777fca1ed3012fce84f633d7fed0')) }
describe '.log' do
it 'has the right log info' do
stub_licensed_features(ide: true)
info = "Web editor usage - ide_usage_project_id: #{project.id}, ide_usage_user: #{user.id}, ide_usage_line_count: 1, ide_usage_file_count: 1"
expect(Rails.logger).to receive(:info).with(info)
subject.log
end
it 'does not log any info if IDE is disabled' do
info = "Web editor usage - ide_usage_project_id: #{project.id}, ide_usage_user: #{user.id}, ide_usage_line_count: 1, ide_usage_file_count: 1"
expect(Rails.logger).not_to receive(:info).with(info)
subject.log
end
end
end
......@@ -245,6 +245,14 @@ describe API::Commits do
expect(json_response['committer_email']).to eq(user.email)
end
it 'does not call the metrics using access token authentication' do
stub_licensed_features(ide: true)
post api(url, user), valid_c_params
expect_any_instance_of(::Gitlab::Metrics::MultiFileEditor).not_to receive(:record)
end
it 'returns a 400 bad request if file exists' do
post api(url, user), invalid_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