rperf 0.6.0 → 0.8.0

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.
@@ -5,7 +5,7 @@ module Rperf::ActiveJobMiddleware
5
5
 
6
6
  included do
7
7
  around_perform do |job, block|
8
- Rperf.label(job: job.class.name) do
8
+ Rperf.profile(job: job.class.name) do
9
9
  block.call
10
10
  end
11
11
  end
data/lib/rperf/rack.rb ADDED
@@ -0,0 +1,37 @@
1
+ require_relative "../rperf"
2
+
3
+ class Rperf::RackMiddleware
4
+ # Options:
5
+ # label_key: - Symbol key for the endpoint label (default: :endpoint)
6
+ # label: - Proc(env) -> String to customize the label value.
7
+ # Default: "METHOD /path" with dynamic segments normalized
8
+ # (numeric IDs → :id, UUIDs → :uuid) to keep label cardinality low.
9
+ # Set label: :raw to use PATH_INFO as-is (not recommended for
10
+ # routes with dynamic segments — each unique path persists in
11
+ # memory for the profiling session).
12
+ #
13
+ def initialize(app, label_key: :endpoint, label: nil)
14
+ @app = app
15
+ @label_key = label_key
16
+ @label_proc = label
17
+ end
18
+
19
+ UUID_RE = %r{/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}i
20
+ NUMERIC_RE = %r{/\d+}
21
+
22
+ def call(env)
23
+ endpoint = if @label_proc == :raw
24
+ "#{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
25
+ elsif @label_proc
26
+ @label_proc.call(env)
27
+ else
28
+ path = env["PATH_INFO"]
29
+ .gsub(UUID_RE, "/:uuid")
30
+ .gsub(NUMERIC_RE, "/:id")
31
+ "#{env["REQUEST_METHOD"]} #{path}"
32
+ end
33
+ Rperf.profile(@label_key => endpoint) do
34
+ @app.call(env)
35
+ end
36
+ end
37
+ end
data/lib/rperf/sidekiq.rb CHANGED
@@ -2,7 +2,7 @@ require "rperf"
2
2
 
3
3
  class Rperf::SidekiqMiddleware
4
4
  def call(_worker, job, _queue)
5
- Rperf.label(job: job["class"]) do
5
+ Rperf.profile(job: job["class"]) do
6
6
  yield
7
7
  end
8
8
  end
data/lib/rperf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rperf
2
- VERSION = "0.6.0"
2
+ VERSION = "0.8.0"
3
3
  end