rails-profiler 0.44.31 → 0.44.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,6 +72,8 @@ module Profiler
72
72
  dir = token_dir(name)
73
73
  stat = File.lstat(dir)
74
74
  FileUtils.rm_rf(dir) if stat.directory? && stat.mtime < cutoff
75
+ rescue Errno::ENOENT
76
+ # Normal race between concurrent workers
75
77
  rescue SystemCallError => e
76
78
  Profiler.log_error("BlobStore: could not prune #{name}", e)
77
79
  end
@@ -38,6 +38,19 @@ module Profiler
38
38
  return 0
39
39
  LUA
40
40
 
41
+ # Atomically retrieves tokens to evict: returns the first N tokens from the sorted set
42
+ # where N is the minimum of (zcard - target) and batch_size, or 0 if already below target.
43
+ GET_EXCESS_TOKENS = <<~LUA
44
+ local key = KEYS[1]
45
+ local target = tonumber(ARGV[1])
46
+ local batch_size = tonumber(ARGV[2])
47
+ local card = redis.call("zcard", key)
48
+ local excess = card - target
49
+ if excess <= 0 then return {} end
50
+ local count = math.min(excess, batch_size)
51
+ return redis.call("zrange", key, 0, count - 1)
52
+ LUA
53
+
41
54
  attr_reader :redis
42
55
 
43
56
  def initialize(options = {})
@@ -256,20 +269,24 @@ module Profiler
256
269
  return if excess <= @max_profiles - target
257
270
 
258
271
  if excess <= EVICT_BATCH
259
- remove_tokens(@redis.zrange(saved_key, 0, excess - 1) - [keep])
272
+ tokens = @redis.eval(GET_EXCESS_TOKENS, keys: [saved_key], argv: [target, EVICT_BATCH])
273
+ remove_tokens(tokens - [keep]) if tokens.any?
260
274
  else
261
275
  evicted_all = with_lock(evict_lock_key, EVICT_LOCK_SECONDS) do
262
276
  loop do
263
- excess = @redis.zcard(saved_key) - target
264
- break if excess <= 0
277
+ tokens = @redis.eval(GET_EXCESS_TOKENS, keys: [saved_key], argv: [target, INDEX_BATCH])
278
+ break if tokens.empty?
265
279
 
266
- batch = @redis.zrange(saved_key, 0, [excess, INDEX_BATCH].min - 1) - [keep]
280
+ batch = tokens - [keep]
267
281
  break if batch.empty?
268
282
 
269
283
  remove_tokens(batch)
270
284
  end
271
285
  end
272
- remove_tokens(@redis.zrange(saved_key, 0, EVICT_BATCH - 1) - [keep]) unless evicted_all
286
+ unless evicted_all
287
+ tokens = @redis.eval(GET_EXCESS_TOKENS, keys: [saved_key], argv: [target, EVICT_BATCH])
288
+ remove_tokens(tokens - [keep]) if tokens.any?
289
+ end
273
290
  end
274
291
  end
275
292
 
@@ -73,10 +73,10 @@ module Profiler
73
73
  next unless collector_data.is_a?(Hash)
74
74
 
75
75
  if collector_name.to_s == "http"
76
- requests = collector_data["requests"]
76
+ requests = collector_data["requests"] || collector_data[:requests]
77
77
  if requests
78
78
  stripped, bodies_saved = save_http_response_bodies(token, requests)
79
- collectors_meta[collector_name] = collector_data.merge("requests" => stripped)
79
+ collectors_meta[collector_name] = collector_data.reject { |key, _| key.to_s == "requests" }.merge("requests" => stripped)
80
80
  else
81
81
  collectors_meta[collector_name] = collector_data
82
82
  end
@@ -49,7 +49,7 @@ module Profiler
49
49
  token
50
50
  end
51
51
 
52
- %i[load list cleanup exists? find_by_parent find_by_replay_of delete clear].each do |name|
52
+ %i[load list cleanup exists? find_by_parent find_by_trace find_by_replay_of delete clear].each do |name|
53
53
  define_method(name) { |*, **| raise @error }
54
54
  end
55
55
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Profiler
4
- VERSION = "0.44.31"
4
+ VERSION = "0.44.33"
5
5
 
6
6
  GEM_ROOT = File.expand_path("../..", __dir__)
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.31
4
+ version: 0.44.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Duplessy