Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4811

Output controller runtime stats in milliseconds as per Rails requirements

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 8.0.1
    • Affects Version/s: 7.0.5
    • Component/s: Dev Exp
    • Environment:
      Rails 6.0
    • Fully Compatible

      The controller runtime stats integration always reports 0ms. This is due to a mixup between mongo-ruby and Rails and how they measure time.

      Specifically, Rails (and ActiveSupport) assume that event.duration is in milliseconds. However, mongo-ruby produces events with .duration in seconds.

      What actually happens:

      Completed 200 OK in 7ms (Views: 0.1ms | MongoDB: 0.0ms | Allocations: 2345)

      What should happen:

      Completed 200 OK in 7ms (Views: 0.1ms | MongoDB: 1.9ms | Allocations: 2345)

      Possible fixes:

      1) in railties/controller_runtime.rb, change line 63:

      def _completed e
        Collector.runtime += e.duration * 1000
      end

      This simply converts inbound seconds to milliseconds so that the value is rendered properly in log_process_action() (line 44).

      2) Make event.duration conform to the ActiveSupport spec by converting everything to ms. This would make it easier to add custom logging subscribers to mongo-ruby events. Presently all subscribers would have to *1000 just like the default subscriber mentioned in (1).

      This is, of course, a much farther reaching change, so perhaps (1) is more appropriate, especially for a patch release.

       

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            tmorgan thomas morgan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: