<commit_before>require 'travis/api/app'
require 'metriks'

class Travis::Api::App
  class Middleware
    class Metriks < Middleware
      include Helpers::Accept

      before do
        env['metriks.request.start'] ||= Time.now.utc
      end

      after do
        if queue_start = time(env['HTTP_X_QUEUE_START']) || time(env['HTTP_X_REQUEST_START'])
          time = env['metriks.request.start'] - queue_start
          ::Metriks.timer('api.request_queue').update(time)
        end

        if response.status < 400
          time = Time.now.utc - env['metriks.request.start']
          if headers['X-Pattern'].present? and headers['X-Endpoint'].present?
            name = "#{(headers['X-Endpoint'].split("::", 5).last.gsub(/::/, ".")).downcase}#{headers['X-Pattern'].gsub(/[\/]/, '.').gsub(/[:\?\*]/, "_")}"
            metric = "api.request.endpoint.#{name}"
            ::Metriks.timer(metric).update(time)
            ::Metriks.timer('api.requests').update(time)
          end
          ::Metriks.meter("api.request.#{request.request_method.downcase}").mark<commit_msg>Revert "also support X-Request-Start"<commit_after>require 'travis/api/app'
require 'metriks'

class Travis::Api::App
  class Middleware
    class Metriks < Middleware
      include Helpers::Accept

      before do
        env['metriks.request.start'] ||= Time.now.utc
      end

      after do
        if queue_start = time(env['HTTP_X_QUEUE_START'])
          time = env['metriks.request.start'] - queue_start
          ::Metriks.timer('api.request_queue').update(time)
        end

        if response.status < 400
          time = Time.now.utc - env['metriks.request.start']
          if headers['X-Pattern'].present? and headers['X-Endpoint'].present?
            name = "#{(headers['X-Endpoint'].split("::", 5).last.gsub(/::/, ".")).downcase}#{headers['X-Pattern'].gsub(/[\/]/, '.').gsub(/[:\?\*]/, "_")}"
            metric = "api.request.endpoint.#{name}"
            ::Metriks.timer(metric).update(time)
            ::Metriks.timer('api.requests').update(time)
          end
          ::Metriks.meter("api.request.#{request.request_method.downcase}").mark
{'fraction_non_alphanumeric': 0.18496029892573565, 'fraction_numerical': 0.0037365716954694066, 'mean_word_length': 2.6552901023890785, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2480115', 'n_tokens_mistral': 699, 'n_tokens_neox': 684, 'n_words': 101}