add logging of avg module duration for course pace

Closes LS-3333

Test Plan: passes jenkins

Change-Id: I9ebe359daa7b5c8426a47fa2a7836eeda3889f73
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/298568
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jackson Howe <jackson.howe@instructure.com>
QA-Review: Jackson Howe <jackson.howe@instructure.com>
Product-Review: Robin Kuss <rkuss@instructure.com>
This commit is contained in:
Robin Kuss 2022-08-15 14:26:48 -05:00
parent 2327acbe05
commit b7d6c18c8a
2 changed files with 58 additions and 1 deletions

View File

@ -41,6 +41,7 @@ class CoursePace < ActiveRecord::Base
after_create :log_pace_counts
after_save :log_exclude_weekends_counts, if: :logging_for_weekends_required?
after_save :log_average_item_duration
validates :course_id, presence: true
validate :valid_secondary_context
@ -302,4 +303,11 @@ class CoursePace < ActiveRecord::Base
InstStatsd::Statsd.decrement("course_pacing.weekends_excluded") unless saved_change_to_id?
end
end
def log_average_item_duration
return if course_pace_module_items.empty?
average_duration = course_pace_module_items.pluck(:duration).sum / course_pace_module_items.length
InstStatsd::Statsd.count("course_pacing.average_assignment_duration", average_duration)
end
end

View File

@ -547,7 +547,7 @@ describe CoursePace do
end
end
context "course pace publish logs statsd for exclude weekends" do
context "course pace publish logs statsd for various values" do
before :once do
course_with_student active_all: true
@course.root_account.enable_feature!(:course_paces)
@ -597,5 +597,54 @@ describe CoursePace do
expect(InstStatsd::Statsd).to have_received(:increment).with("course_pacing.weekends_excluded")
expect(InstStatsd::Statsd).to have_received(:decrement).with("course_pacing.weekends_excluded")
end
it "logs the average module item duration as a count" do
allow(InstStatsd::Statsd).to receive(:count)
course_pace = @course.course_paces.create!(workflow_state: "active")
course_pace_module_item = course_pace.course_pace_module_items.create! module_item: @tag
course_pace_module_item.update duration: 2
course_pace.publish
expect(InstStatsd::Statsd).to have_received(:count).with("course_pacing.average_assignment_duration", 2)
end
it "logs updated average module item duration as a count when new assignment added" do
allow(InstStatsd::Statsd).to receive(:count)
course_pace = @course.course_paces.create!(workflow_state: "active")
course_pace_module_item = course_pace.course_pace_module_items.create! module_item: @tag
course_pace_module_item.update duration: 2
course_pace.publish
assignment = @course.assignments.create!
new_tag = assignment.context_module_tags.create! context_module: @module, context: @course, tag_type: "context_module"
new_course_pace_module_item = course_pace.course_pace_module_items.create! module_item: new_tag
new_course_pace_module_item.update duration: 4
course_pace.publish
expect(InstStatsd::Statsd).to have_received(:count).with("course_pacing.average_assignment_duration", 3)
end
it "doesn't log when no context modules exist" do
allow(InstStatsd::Statsd).to receive(:count)
course_pace = @course.course_paces.create!(workflow_state: "active")
course_pace.publish
expect(InstStatsd::Statsd).not_to have_received(:count).with("course_pacing.average_assignment_duration", 0)
end
it "logs when no context modules item duration is o" do
allow(InstStatsd::Statsd).to receive(:count)
course_pace = @course.course_paces.create!(workflow_state: "active")
course_pace_module_item = course_pace.course_pace_module_items.create! module_item: @tag
course_pace_module_item.update duration: 0
course_pace.publish
expect(InstStatsd::Statsd).to have_received(:count).with("course_pacing.average_assignment_duration", 0)
end
end
end