Sha256: c785750733a1e7f227029374266ee96ceb59fbba01ea861ae511b4d0175006e0

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

module BuilderApm
  class RequestDataController < ApplicationController
      def index
          cursor = params[:cursor].presence&.to_f || Time.now.to_f * 1000
          limit = params[:limit].presence&.to_i || 50
          type = params[:type].presence || 'timestamps'

          purge_old_keys
          @requests = retrieve_data_from_redis_since(cursor, limit, type)
        Rails.logger.info "#{@requests.size} results gathered"
          render json: @requests
      end

      private

      def purge_old_keys
        time_limit = (Time.now - 2.hour).to_f * 1000
        redis_client.zremrangebyscore('builder_apm:timestamps', '-inf', time_limit)
        redis_client.zremrangebyscore('builder_apm:errors', '-inf', time_limit)
        redis_client.zremrangebyscore('builder_apm:n_plus_one', '-inf', time_limit)
        redis_client.zremrangebyscore('builder_apm:slow', '-inf', time_limit)
        redis_client.zremrangebyscore('builder_apm:dashboard', '-inf', time_limit)
      end

      def retrieve_data_from_redis_since(cursor, limit, type)
        data = redis_client.zrevrangebyscore("builder_apm:#{type}", cursor, "-inf", limit: [0, limit])
        data.map{ |d| JSON.parse(d) }
      end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
builder_apm-0.5.14 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.13 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.12 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.11 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.10 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.9 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.8 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.7 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.6 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.4 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.3 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.2 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.5.1 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.4.2 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.4.1 app/controllers/builder_apm/request_data_controller.rb
builder_apm-0.4.0 app/controllers/builder_apm/request_data_controller.rb