rperf 0.7.0 → 0.9.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.
@@ -1,4 +1,5 @@
1
1
  require "rperf"
2
+ require "active_support/concern"
2
3
 
3
4
  module Rperf::ActiveJobMiddleware
4
5
  extend ActiveSupport::Concern
data/lib/rperf/rack.rb CHANGED
@@ -1,13 +1,35 @@
1
- require "rperf"
1
+ require_relative "../rperf"
2
2
 
3
3
  class Rperf::RackMiddleware
4
- def initialize(app, label_key: :endpoint)
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)
5
14
  @app = app
6
15
  @label_key = label_key
16
+ @label_proc = label
7
17
  end
8
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
+
9
22
  def call(env)
10
- endpoint = "#{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"
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
11
33
  Rperf.profile(@label_key => endpoint) do
12
34
  @app.call(env)
13
35
  end
data/lib/rperf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rperf
2
- VERSION = "0.7.0"
2
+ VERSION = "0.9.0"
3
3
  end