Skip to content

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:

  1. When Duo Code Review posts a diff comment (i.e. code suggestions)
  2. When Duo Code Review encounters error during review
  3. When Duo Code Review finds no issue in the MR to comment on
  4. When Duo Code Review finds no changes in the MR to review

Related

How to set up and validate events locally

  1. 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

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.

  1. 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
  2. Trigger Review Events

    • Request a review from Duo Code Review via:

      • The Reviewer panel dropdown menu, or
      • Commenting with /assign_reviewer @GitLabDuo
  3. 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

Screenshot_2025-05-07_at_18.11.34

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.

Edited by Shola Quadri

Merge request reports

Loading