Add timing logging to MergeRequests::RefreshService methods
What does this MR do and why?
This MR adds structured logging for the notify_about_push method in the MergeRequests::RefreshService to help identify performance bottlenecks. This addresses the performance issues reported in https://gitlab.com/gitlab-org/gitlab/-/issues/548046 where UpdateMergeRequestsWorker is not meeting the 10-second SLO targets on GitLab Dedicated instances.
This is a focused implementation that only logs the notify_about_push method and its internal operations, unlike the previous broader instrumentation from !208619 (merged) and !211201 (merged), which was removed.
What are the relevant issue numbers?
https://gitlab.com/gitlab-org/gitlab/-/issues/548046 #576798
Logging Details
The following metrics are logged to Kibana when the feature flag is enabled:
-
notify_about_push_duration_s- Total time spent in the notify_about_push method (aggregated across all MRs) -
system_note_add_commits_duration_s- Time spent creating system notes for new commits (aggregated across all MRs) -
notification_push_to_merge_request_duration_s- Time spent sending notification emails (aggregated across all MRs) -
notify_about_push_total_duration_s- Sum of all the above durations
Each duration is measured using Gitlab::Metrics::System.monotonic_time and rounded to the appropriate precision only when logging (not during aggregation) to avoid rounding errors.
Feature Flag
The logging is controlled by the :log_refresh_service_duration feature flag (wip type, default: disabled). This allows for safe rollout and testing on specific instances.
To enable:
Feature.enable(:log_refresh_service_duration, User.find_by_username('username'))
How to test
-
Enable the feature flag:
Feature.enable(:log_refresh_service_duration) -
Push commits to a branch with an open merge request
-
Check the logs in Kibana for entries with
event: 'merge_requests_refresh_service_notify_about_push' -
Verify that duration metrics are present for the notify_about_push operations
Related to #576798