Add Event Tracking for Duo Code Review Responses
What does this MR do and why?
Addresses #523216 (closed)
This MR defines and instruments events and relevant metrics for Duo Code Review responses.
Responses tracked:
- When Duo Code Review posts a diff comment (i.e. code suggestions)
- When Duo Code Review encounters error during review
- When Duo Code Review finds no issue in the MR to comment on
- When Duo Code Review finds no changes in the MR to review
Related
- Add Event Tracking for Duo Code Review Requests (!190058 - merged)
- Add Event Tracking for User Interactions with D... (!190553 - merged)
How to set up and validate events locally
-
In the terminal, start events monitor from the
gitlab
folder with event names:-
Command:
rails runner scripts/internal_events/monitor.rb encounter_duo_code_review_error_during_review find_no_issues_duo_code_review_after_review find_nothing_to_review_duo_code_review_on_mr post_comment_duo_code_review_on_diff
-
Command:
There's a known problem with OpenSSL::ssl::SSLError
when starting the events monitor. If you encounter this, simply change the value of scheme in snowplow_micro.rb
to 'http'
as a work around.
-
Prepare Test Environment
- Create an MR with code issues using the sample snippet below for ease
- Ensure Duo Code Review is properly configured in your local GitLab instance
-
Trigger Review Events
-
Request a review from Duo Code Review via:
- The Reviewer panel dropdown menu, or
- Commenting with
/assign_reviewer @GitLabDuo
-
-
Verify Event Tracking
Confirm the following events appear in the events monitor:
Event | Trigger Method |
---|---|
post_comment_duo_code_review_on_diff |
When Duo adds comments or suggestions to the diff |
find_no_issues_duo_code_review_after_review |
Re-request a review on an already-reviewed MR |
find_nothing_to_review_duo_code_review_on_mr |
Re-request a review on an already-reviewed MR |
encounter_duo_code_review_error_during_review |
When review process encounters an error |
Code with bug example
# A simple student management system with obvious errors
class Student
def initialize(name, age, grade # Missing closing parenthesis
@name == name # Using equality operator instead of assignment
@age = age
@grade = grade
end
def to_s
"#{@name} is #{@age} years old in grade #{@grade}"
# Method to check if student is passing
def passing? # Missing 'end' for previous method
@grade >= 60
end
end
# Class to manage a collection of students
class Classroom
def intialize(name, teacher) # Typo in method name (should be initialize)
@name = name
@teacher = teacher
@students = []
def add_student(student) # Missing 'end' for previous method
if student.instance_of(Student) # Missing question mark on instance_of?
@students << students # Using wrong variable name (should be student)
puts "Added #{student.name} to classroom" # No accessor method defined for name
return true
else
return false
end
end
def average_grade
total = 0
@students.each do |student|
total += student.grade # No accessor method defined for grade
total / @students.size # Division by zero error if no students, missing 'end' for each block
end
def to_s
result = "Classroom: #{@name}, Teacher: #{@teacher}\n"
result += "Students:\n"
@students.each do |student|
result += "- #{student}\n"
end
result
# Missing 'end' for class
# Create a classroom and add students
classroom = Classroom.new("Math 101", "Mr. Smith")
# Create some students
student1 = Student.new("John Doe", 15, 85)
student2 = Student.new("Jane Smith", 16, 92
student3 = Student.new("Bob Johnson" 14, 78) # Missing comma
classroom.add_student(student1); # Unnecessary semicolon
classroom.add_student(student2);
classroom.add_student(student3);
puts classroom
puts "Class average: #{classroom.avarage_grade}" # Typo in method name
# Check if each student is passing
classroom.students.each do |student| # No accessor method for students
if student.passing?
puts "#{student.name} is passing."
else
puts "#{student.name} is failing."
end # Missing 'end' for if block
Screenshot
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.