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