Skip to content

Add Event Tracking for User Interactions with Duo Code Review

What does this MR do and why?

Addresses #523216 (closed)

This MR defines and instruments events and relevant metrics specifically for when users interact with Duo Code Review beyond requesting for a code review.

Interactions tracked:

  1. When a user mentions @GitLabDuo in an MR comment
  2. When a user posts a thumbs up (of any skin tone) on a Duo Code Review comment
  3. When a user posts a thumbs down (of any skin tone) on a Duo Code Review comment

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 mention_gitlabduo_in_mr_comment react_thumbs_up_on_duo_code_review_comment react_thumbs_down_on_duo_code_review_comment

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

    • Interact with Duo Code Review using the comment box or a DCR-provided diff:

      • Mention @GitLabDuo <insert_your_question>
      • React to any of Duo Code Review's comment with a thumbs up AND thumbs down (test out different skin tones)
  3. Verify Event Tracking

Confirm the following events appear in the events monitor:

Event Trigger Method
mention_gitlabduo_in_mr_comment When @GitLabDuo is mentioned in the comments or suggestions diff
react_thumbs_up_on_duo_code_review_comment When a user reacts with 👍🏾 (of any skin tone) to @GitLabDuo's suggestion/response
react_thumbs_down_on_duo_code_review_comment When a user reacts with 👎🏾 (of any skin tone) to @GitLabDuo's suggestion/response
  1. Verify Non Tracking Scenarios

    • Events are not tracked for any emoji except for 👍🏾 or 👎🏾. For example, ❤️ , 🙇, , etc.
    • Events are not tracked for any mentions other than @GitLabDuo

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

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