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 ...@@ -10,6 +10,7 @@ module Issues
end end
def execute def execute
record_import_attempt
process_csv process_csv
email_results_to_user email_results_to_user
...@@ -18,6 +19,10 @@ module Issues ...@@ -18,6 +19,10 @@ module Issues
private private
def record_import_attempt
CsvIssueImport.create!(user: @user, project: @project)
end
def process_csv def process_csv
csv_data = @csv_io.open(&:read).force_encoding(Encoding::UTF_8) 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 ...@@ -574,7 +574,8 @@ module Gitlab
issues_imported: { issues_imported: {
jira: distinct_count(::JiraImportState.where(time_period), :user_id), jira: distinct_count(::JiraImportState.where(time_period), :user_id),
fogbugz: projects_imported_count('fogbugz', time_period), 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) 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 ...@@ -207,6 +207,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
jira_project = create(:project, creator_id: user.id) jira_project = create(:project, creator_id: user.id)
create(:jira_import_state, :finished, project: jira_project) create(:jira_import_state, :finished, project: jira_project)
create(:csv_issue_import, user: user)
end end
expect(described_class.usage_activity_by_stage_manage({})).to include( expect(described_class.usage_activity_by_stage_manage({})).to include(
...@@ -224,7 +226,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -224,7 +226,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
issues_imported: { issues_imported: {
jira: 2, jira: 2,
fogbugz: 2, fogbugz: 2,
phabricator: 2 phabricator: 2,
csv: 2
} }
} }
) )
...@@ -243,7 +246,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -243,7 +246,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
issues_imported: { issues_imported: {
jira: 1, jira: 1,
fogbugz: 1, fogbugz: 1,
phabricator: 1 phabricator: 1,
csv: 1
} }
} }
) )
......
...@@ -13,6 +13,14 @@ RSpec.describe Issues::ImportCsvService do ...@@ -13,6 +13,14 @@ RSpec.describe Issues::ImportCsvService do
described_class.new(user, project, uploader).execute described_class.new(user, project, uploader).execute
end 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 describe '#execute' do
context 'invalid file' do context 'invalid file' do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') } let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
...@@ -23,6 +31,8 @@ RSpec.describe Issues::ImportCsvService do ...@@ -23,6 +31,8 @@ RSpec.describe Issues::ImportCsvService do
expect(subject[:success]).to eq(0) expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true) expect(subject[:parse_error]).to eq(true)
end end
it_behaves_like 'an issue importer'
end end
context 'with a file generated by Gitlab CSV export' do context 'with a file generated by Gitlab CSV export' do
...@@ -44,6 +54,8 @@ RSpec.describe Issues::ImportCsvService do ...@@ -44,6 +54,8 @@ RSpec.describe Issues::ImportCsvService do
description: 'Test Description' description: 'Test Description'
) )
end end
it_behaves_like 'an issue importer'
end end
context 'comma delimited file' do context 'comma delimited file' do
...@@ -65,6 +77,8 @@ RSpec.describe Issues::ImportCsvService do ...@@ -65,6 +77,8 @@ RSpec.describe Issues::ImportCsvService do
description: 'Description' description: 'Description'
) )
end end
it_behaves_like 'an issue importer'
end end
context 'tab delimited file with error row' do context 'tab delimited file with error row' do
...@@ -86,6 +100,8 @@ RSpec.describe Issues::ImportCsvService do ...@@ -86,6 +100,8 @@ RSpec.describe Issues::ImportCsvService do
description: 'World' description: 'World'
) )
end end
it_behaves_like 'an issue importer'
end end
context 'semicolon delimited file with CRLF' do context 'semicolon delimited file with CRLF' do
...@@ -107,6 +123,8 @@ RSpec.describe Issues::ImportCsvService do ...@@ -107,6 +123,8 @@ RSpec.describe Issues::ImportCsvService do
description: 'World' description: 'World'
) )
end end
it_behaves_like 'an issue importer'
end end
end 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