rails-profiler 0.44.2 → 0.44.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46e258e22691c87c97c16eb5587ae226dadfda20087792676cd50ee0f15b889d
4
- data.tar.gz: 435872dcf60c9507d16a6f6ec2fa1a81cf9e9efa3932f9c2c32986cb3a084671
3
+ metadata.gz: ce11aa11e9b78a74592597cff00560918498f66c5305d9fc6b56c5a31016da4a
4
+ data.tar.gz: fe2cb8e6c676ea9d8ee578b50619191e6bc6615c5c61276b6b9a244f01d89da5
5
5
  SHA512:
6
- metadata.gz: 22223777d66e003f222df2a4f6e043f65331948ac5a5efd84d090b508404ebb9baa97ebc438268ddee41767416ec32b869fd685d0a712e3180550d4548f8a994
7
- data.tar.gz: 7c6c8f85a7aa7f9c00a54a03b5690ee1065da8d3e8cbd5eacf1b18be70fedf4cd824fee4cae336c48339a13749b83e92de4d14d8757a41938e9b65c3384ed3d2
6
+ metadata.gz: a34e01876ec49e00c57c9e2825826d5a3c8b932bf949e6c3096a763c342a9248fb6697ccc38b29027cff641554f2259b5ae5c2278d4aff50eba03a067003bb07
7
+ data.tar.gz: f1ff8d35947b09461d0a304b5caea8f60ec3d19da5714e98574446cd29cce72764860f522da487e59ab941cf6bc95da62ab0ea0d754693cb76a4105dd49688b2
data/CHANGELOG.md CHANGED
@@ -19,6 +19,16 @@ every commit of every tag interval is accounted for one way or the other.
19
19
 
20
20
  ## [Unreleased]
21
21
 
22
+ ## [0.44.3] - 2026-10-21
23
+
24
+ <!-- stamped -->
25
+
26
+ ### Fixed
27
+
28
+ - **Cluster:** The children of a profile read on a slave (child jobs, AJAX sub-requests) are no longer cut at the slave's first 50: the master reads every page until the slave reports no more, and returns them oldest first like the local storages do.
29
+ - **Cluster:** The master no longer takes any answer of a slave for data. A `401` or `403` (a wrong `config.cluster_secret`) raises an error that names the secret instead of showing an empty slave, a `404` is no profile for `load` and an error elsewhere, and any other status outside 2xx raises a `Profiler::Error` carrying the slave's message. The `set_env_var`, `delete_env_var`, `reset_env_var`, `reset_all_env_vars` and `clear_profiles` MCP tools on a slave report that error instead of announcing a success, and the dashboard's slave proxy answers a slave's `404` with a `404`.
30
+ - **Cluster:** `DELETE /_profiler/api/profiles/clear` now honours its `type` parameter (`http`, `job`, `test` or `console`, anything else is a 422; `http` when it is absent, as before). The `clear_profiles` MCP tool on a slave used to delete the slave's HTTP profiles whatever the type asked, and answered that it had cleared the jobs; with no type it now clears every type of the slave.
31
+
22
32
  ## [0.44.2] - 2026-10-21
23
33
 
24
34
  <!-- stamped -->
@@ -44,8 +44,18 @@ module Profiler
44
44
  head :no_content
45
45
  end
46
46
 
47
+ CLEARABLE_TYPES = %w[http job test console].freeze
48
+
49
+ # Without a type the dashboard's long-standing behaviour holds: http profiles only. The
50
+ # cluster proxy names the type it means.
47
51
  def clear
48
- Profiler.storage.clear(type: "http")
52
+ type = params[:type].presence || "http"
53
+ unless CLEARABLE_TYPES.include?(type.to_s)
54
+ return render json: { error: "type must be one of #{CLEARABLE_TYPES.join(", ")}" },
55
+ status: :unprocessable_entity
56
+ end
57
+
58
+ Profiler.storage.clear(type: type.to_s)
49
59
  head :no_content
50
60
  end
51
61
 
@@ -26,6 +26,8 @@ module Profiler
26
26
  end
27
27
 
28
28
  render json: result
29
+ rescue Cluster::SlaveProxy::NotFound => e
30
+ render json: { error: e.message }, status: :not_found
29
31
  # The profiler's own refusals (unknown or offline slave, refused URL, missing secret).
30
32
  rescue Profiler::Error => e
31
33
  render json: { error: e.message }, status: :bad_gateway
@@ -9,6 +9,9 @@ require_relative "../storage/token"
9
9
  module Profiler
10
10
  module Cluster
11
11
  class SlaveProxy
12
+ # The slave answered 404: it has no such resource.
13
+ class NotFound < Profiler::Error; end
14
+
12
15
  # A slow or hung slave must not block the master's request thread for long.
13
16
  OPEN_TIMEOUT = 5 # seconds
14
17
  READ_TIMEOUT = 10 # seconds
@@ -51,18 +54,40 @@ module Profiler
51
54
 
52
55
  raw = data["profile"] || data
53
56
  profile_from_api(raw)
57
+ rescue NotFound
58
+ nil
54
59
  end
55
60
 
61
+ CHILDREN_PAGE_SIZE = 100
62
+
63
+ # Every child, not the first page of them: the slave lists children newest first, in pages,
64
+ # and the local storages answer oldest first, which is the order given back.
56
65
  def find_by_parent(parent_token)
57
66
  return [] unless Storage::Token.valid?(parent_token)
58
67
 
59
- data = get_json("/_profiler/api/profiles", parent_token: parent_token, all_types: true)
60
- Array(data["profiles"]).map { |h| profile_from_api(h) }
68
+ children = []
69
+ offset = 0
70
+ loop do
71
+ data = get_json("/_profiler/api/profiles", parent_token: parent_token, all_types: true,
72
+ limit: CHILDREN_PAGE_SIZE, offset: offset)
73
+ page = Array(data["profiles"])
74
+ children.concat(page.map { |h| profile_from_api(h) })
75
+ break if data["has_more"] != true || page.empty?
76
+
77
+ offset += page.size
78
+ end
79
+ children.sort_by { |p| p.started_at || Time.at(0) }
61
80
  end
62
81
 
82
+ CLEARABLE_TYPES = %w[http job test console].freeze
83
+
84
+ # ProfilesController#clear honours one type per call (http when none is given), so
85
+ # clearing everything takes one call per type.
63
86
  def clear(type: nil)
64
- params = type ? "?type=#{URI.encode_www_form_component(type)}" : ""
65
- delete_json("/_profiler/api/profiles/clear#{params}")
87
+ (type ? [type.to_s] : CLEARABLE_TYPES).each do |t|
88
+ delete_json("/_profiler/api/profiles/clear?type=#{URI.encode_www_form_component(t)}")
89
+ end
90
+ {}
66
91
  end
67
92
 
68
93
  # Generic HTTP access for action tools
@@ -123,14 +148,31 @@ module Profiler
123
148
  http.request(req)
124
149
  end
125
150
  end
126
- return {} if resp.code == "204"
127
- if resp.code.to_s.start_with?("3")
128
- raise Profiler::Error, "Slave profiler answered #{resp.code} (redirect not followed)"
151
+ interpret(resp)
152
+ end
153
+
154
+ # What a slave's status means, as PeerProxy#interpret reads a peer's: a wrong secret or a
155
+ # refusal is never an empty answer, and neither is an error of the slave.
156
+ def interpret(resp)
157
+ code = resp.code.to_s
158
+ return {} if code == "204"
159
+ raise NotFound, "Slave profiler answered 404: #{failure_detail(resp, "not found")}" if code == "404"
160
+ raise Profiler::Error, "Slave profiler answered #{code} (redirect not followed)" if code.start_with?("3")
161
+ if %w[401 403].include?(code)
162
+ raise Profiler::Error, "Slave profiler refused the request (#{code}): check that master and slave " \
163
+ "share the same config.cluster_secret"
129
164
  end
165
+ raise Profiler::Error, "Slave profiler answered #{code}: #{failure_detail(resp, "no detail")}" unless code.start_with?("2")
130
166
 
131
167
  parse_response(resp)
132
168
  end
133
169
 
170
+ # The slave's own message when its body carries one; never the raw body, which may be anything.
171
+ def failure_detail(resp, fallback)
172
+ message = parse_response(resp)["error"] if resp.body.to_s.start_with?("{")
173
+ message.is_a?(String) && !message.empty? ? message.slice(0, 200) : fallback
174
+ end
175
+
134
176
  def parse_response(resp)
135
177
  return {} if resp.body.nil? || resp.body.empty?
136
178
 
@@ -467,7 +467,7 @@ module Profiler
467
467
  ::MCP::Tool.define(name: name, description: description, input_schema: input_schema) do |server_context: nil, **args|
468
468
  result = handler.call(args.transform_keys(&:to_s))
469
469
  result.is_a?(::MCP::Tool::Response) ? result : ::MCP::Tool::Response.new(result)
470
- rescue Profiler::Storage::Unavailable::Error => e
470
+ rescue Profiler::Storage::Unavailable::Error, Profiler::Error => e
471
471
  ::MCP::Tool::Response.new([{ type: "text", text: e.message }], error: true)
472
472
  end
473
473
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  require_relative "../slave_support"
4
4
 
5
- require "uri"
6
-
7
5
  module Profiler
8
6
  module MCP
9
7
  module Tools
@@ -16,9 +14,7 @@ module Profiler
16
14
  end
17
15
 
18
16
  if (proxy = MCP::SlaveSupport.with_slave_proxy(params))
19
- path = "/_profiler/api/profiles/clear"
20
- path += "?type=#{URI.encode_www_form_component(type)}" if type
21
- proxy.delete_json(path)
17
+ proxy.clear(type: type)
22
18
  else
23
19
  Profiler.storage.clear(type: type)
24
20
  end
@@ -22,7 +22,8 @@ module Profiler
22
22
  end
23
23
 
24
24
  if (proxy = MCP::SlaveSupport.with_slave_proxy(params))
25
- proxy.patch_json("/_profiler/api/env_vars", { key: key, value: "" })
25
+ data = proxy.patch_json("/_profiler/api/env_vars", { key: key, value: "" })
26
+ return ::MCP::Tool::Response.new([{ type: "text", text: "Error: #{data["error"]}" }], error: true) if data["error"]
26
27
  return [{ type: "text", text: "Deleted #{key} on slave '#{params["slave"]}'. Override persisted across restarts until reset." }]
27
28
  end
28
29
 
@@ -9,7 +9,8 @@ module Profiler
9
9
  class ResetAllEnvVars
10
10
  def self.call(params)
11
11
  if (proxy = MCP::SlaveSupport.with_slave_proxy(params))
12
- proxy.delete_json("/_profiler/api/env_vars/reset_all")
12
+ data = proxy.delete_json("/_profiler/api/env_vars/reset_all")
13
+ return ::MCP::Tool::Response.new([{ type: "text", text: "Error: #{data["error"]}" }], error: true) if data["error"]
13
14
  return [{ type: "text", text: "Reset all ENV overrides on slave '#{params["slave"]}'." }]
14
15
  end
15
16
 
@@ -15,7 +15,8 @@ module Profiler
15
15
  return [{ type: "text", text: "Error: key cannot be blank." }] if key.empty?
16
16
 
17
17
  if (proxy = MCP::SlaveSupport.with_slave_proxy(params))
18
- proxy.delete_json("/_profiler/api/env_vars/reset?key=#{URI.encode_www_form_component(key)}")
18
+ data = proxy.delete_json("/_profiler/api/env_vars/reset?key=#{URI.encode_www_form_component(key)}")
19
+ return ::MCP::Tool::Response.new([{ type: "text", text: "Error: #{data["error"]}" }], error: true) if data["error"]
19
20
  return [{ type: "text", text: "Reset #{key} on slave '#{params["slave"]}'." }]
20
21
  end
21
22
 
@@ -28,7 +28,8 @@ module Profiler
28
28
  end
29
29
 
30
30
  if (proxy = MCP::SlaveSupport.with_slave_proxy(params))
31
- proxy.patch_json("/_profiler/api/env_vars", { key: key, value: value })
31
+ data = proxy.patch_json("/_profiler/api/env_vars", { key: key, value: value })
32
+ return ::MCP::Tool::Response.new([{ type: "text", text: "Error: #{data["error"]}" }], error: true) if data["error"]
32
33
  return [{ type: "text", text: "Set #{key}=#{value} on slave '#{params["slave"]}'" }]
33
34
  end
34
35
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Profiler
4
- VERSION = "0.44.2"
4
+ VERSION = "0.44.3"
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.2
4
+ version: 0.44.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Duplessy