Skip to content

Commit

Permalink
log stat on group creates
Browse files Browse the repository at this point in the history
test plan
 - spec should pass

fixes VICE-900

Change-Id: I18b8bb35c58d3fc5b7db3835f28ef7d69ac116d7
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/249543
Reviewed-by: Matthew Lemon <mlemon@instructure.com>
QA-Review: Matthew Lemon <mlemon@instructure.com>
Product-Review: Matthew Lemon <mlemon@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
  • Loading branch information
roor0 committed Oct 7, 2020
1 parent 85e2c18 commit 136091b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/models/group_and_membership_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,20 @@ def group_from_row(row)
group ||= group_category.groups.where(sis_source_id: group_sis_id).take if group_sis_id
if group_name
group ||= group_category.groups.where(name: group_name).take
group ||= group_category.groups.create!(name: group_name, context: group_category.context)
group ||= create_new_group(group_name)
end
seen_groups[key] ||= group
group
end

def create_new_group(name)
InstStatsd::Statsd.increment('groups.auto_create',
tags: { split_type: 'csv',
root_account_id: group_category.root_account&.global_id,
root_account_name: group_category.root_account&.name })
group_category.groups.create!(name: name, context: group_category.context)
end

def group_key(group_id, group_sis_id, group_name)
key = []
key << "id:#{group_id}" if group_id
Expand Down
10 changes: 10 additions & 0 deletions spec/models/group_and_membership_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,15 @@ def import_csv_data(data)
expect(gc1.groups.count).to eq 1
expect(@user.groups.pluck(:name)).to eq ["manual group"]
end

it 'should log stat on new groups' do
allow(InstStatsd::Statsd).to receive(:increment)
expect(InstStatsd::Statsd).to receive(:increment).with("groups.auto_create",
tags: { split_type: 'csv',
root_account_id: gc1.root_account&.global_id,
root_account_name: gc1.root_account&.name })
import_csv_data(%{user_id,group_name
user_4,anugroup})
end
end
end

0 comments on commit 136091b

Please sign in to comment.