Commit 19f862ec authored by Josianne Hyson's avatar Josianne Hyson

Add Usage count for issue imports via CSV

We want to be able to report on how many different users are importing
issues via the CSV importer. Add this metric to the Usage Data so that
we can tell how popular this feature is.

MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/44742
Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/235732
parent 47429f01
......@@ -10,6 +10,7 @@ module Issues
end
def execute
record_import_attempt
process_csv
email_results_to_user
......@@ -18,6 +19,10 @@ module Issues
private
def record_import_attempt
CsvIssueImport.create!(user: @user, project: @project)
end
def process_csv
csv_data = @csv_io.open(&:read).force_encoding(Encoding::UTF_8)
......
---
title: Add usage ping for unique users importing issues via CSV
merge_request: 44742
author:
type: changed
......@@ -574,7 +574,8 @@ module Gitlab
issues_imported: {
jira: distinct_count(::JiraImportState.where(time_period), :user_id),
fogbugz: projects_imported_count('fogbugz', time_period),
phabricator: projects_imported_count('phabricator', time_period)
phabricator: projects_imported_count('phabricator', time_period),
csv: distinct_count(CsvIssueImport.where(time_period), :user_id)
},
groups_imported: distinct_count(::GroupImportState.where(time_period), :user_id)
}
......
# frozen_string_literal: true
FactoryBot.define do
factory :csv_issue_import do
project
user
end
end
......@@ -207,6 +207,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
jira_project = create(:project, creator_id: user.id)
create(:jira_import_state, :finished, project: jira_project)
create(:csv_issue_import, user: user)
end
expect(described_class.usage_activity_by_stage_manage({})).to include(
......@@ -224,7 +226,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
issues_imported: {
jira: 2,
fogbugz: 2,
phabricator: 2
phabricator: 2,
csv: 2
}
}
)
......@@ -243,7 +246,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
issues_imported: {
jira: 1,
fogbugz: 1,
phabricator: 1
phabricator: 1,
csv: 1
}
}
)
......
......@@ -13,6 +13,14 @@ RSpec.describe Issues::ImportCsvService do
described_class.new(user, project, uploader).execute
end
shared_examples_for 'an issue importer' do
it 'records the import attempt' do
expect { subject }
.to change { CsvIssueImport.where(project: project, user: user).count }
.by 1
end
end
describe '#execute' do
context 'invalid file' do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
......@@ -23,6 +31,8 @@ RSpec.describe Issues::ImportCsvService do
expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true)
end
it_behaves_like 'an issue importer'
end
context 'with a file generated by Gitlab CSV export' do
......@@ -44,6 +54,8 @@ RSpec.describe Issues::ImportCsvService do
description: 'Test Description'
)
end
it_behaves_like 'an issue importer'
end
context 'comma delimited file' do
......@@ -65,6 +77,8 @@ RSpec.describe Issues::ImportCsvService do
description: 'Description'
)
end
it_behaves_like 'an issue importer'
end
context 'tab delimited file with error row' do
......@@ -86,6 +100,8 @@ RSpec.describe Issues::ImportCsvService do
description: 'World'
)
end
it_behaves_like 'an issue importer'
end
context 'semicolon delimited file with CRLF' do
......@@ -107,6 +123,8 @@ RSpec.describe Issues::ImportCsvService do
description: 'World'
)
end
it_behaves_like 'an issue importer'
end
end
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