rails-profiler 0.44.2 → 0.44.4
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 +4 -4
- data/CHANGELOG.md +18 -0
- data/app/controllers/profiler/api/profiles_controller.rb +11 -1
- data/app/controllers/profiler/api/slave_proxy_controller.rb +2 -0
- data/lib/profiler/cluster/master_client.rb +26 -13
- data/lib/profiler/cluster/slave_proxy.rb +49 -7
- data/lib/profiler/mcp/server.rb +1 -1
- data/lib/profiler/mcp/tools/clear_profiles.rb +1 -5
- data/lib/profiler/mcp/tools/delete_env_var.rb +2 -1
- data/lib/profiler/mcp/tools/reset_all_env_vars.rb +2 -1
- data/lib/profiler/mcp/tools/reset_env_var.rb +2 -1
- data/lib/profiler/mcp/tools/set_env_var.rb +2 -1
- data/lib/profiler/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 83d59af955c9b38a889d0d2e8e1de82c0e1b7cd6e281a74545fdc078eba838ef
|
|
4
|
+
data.tar.gz: ac543e209b57284122855d727d2b0dfd1ce36948462642fae681e040e432507e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f81c36af2b33e98e1dcf90c855f5929e41f149236265ce65aeb24794cd536a8f4b41218d768aed511aee3fac6ed5f56a28ef044597c8f3cd779bf25675964a51
|
|
7
|
+
data.tar.gz: e0a804252b573fd3b934fb77bb14c20367042fe61cde6e1e4340401726f4e09442c72b27ccd7029fa6bbd3e09b3d4bca9b9c4123c12d42a7d9d57e1dedd8db23
|
data/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,24 @@ every commit of every tag interval is accounted for one way or the other.
|
|
|
19
19
|
|
|
20
20
|
## [Unreleased]
|
|
21
21
|
|
|
22
|
+
## [0.44.4] - 2026-10-21
|
|
23
|
+
|
|
24
|
+
<!-- stamped -->
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- **Cluster:** a slave no longer delays the boot of the server, of `rails console` or of a rake task when its master is unreachable. The first registration now runs in the heartbeat thread instead of `after_initialize`, and calls to the master time out after 3 seconds to connect and 5 seconds to read, instead of 60 seconds each.
|
|
29
|
+
|
|
30
|
+
## [0.44.3] - 2026-10-21
|
|
31
|
+
|
|
32
|
+
<!-- stamped -->
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- **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.
|
|
37
|
+
- **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`.
|
|
38
|
+
- **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.
|
|
39
|
+
|
|
22
40
|
## [0.44.2] - 2026-10-21
|
|
23
41
|
|
|
24
42
|
<!-- 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
|
-
|
|
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
|
|
@@ -20,6 +20,10 @@ module Profiler
|
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
# A master that does not answer must cost the heartbeat thread a few seconds, not a minute.
|
|
24
|
+
OPEN_TIMEOUT = 3
|
|
25
|
+
READ_TIMEOUT = 5
|
|
26
|
+
|
|
23
27
|
class << self
|
|
24
28
|
# The client the railtie started in this process, for the fork hook to restart.
|
|
25
29
|
attr_accessor :current
|
|
@@ -42,12 +46,7 @@ module Profiler
|
|
|
42
46
|
self.class.current = self
|
|
43
47
|
self.class.install_fork_hook!
|
|
44
48
|
@registered = false
|
|
45
|
-
|
|
46
|
-
register!
|
|
47
|
-
@registered = true
|
|
48
|
-
rescue => e
|
|
49
|
-
log_warn("could not register with master at startup, will retry in the heartbeat loop", e)
|
|
50
|
-
end
|
|
49
|
+
@failed = false
|
|
51
50
|
@started = true
|
|
52
51
|
start_heartbeat_thread
|
|
53
52
|
end
|
|
@@ -59,6 +58,7 @@ module Profiler
|
|
|
59
58
|
return if @started.nil? || @thread&.alive?
|
|
60
59
|
|
|
61
60
|
@registered = false
|
|
61
|
+
@failed = false
|
|
62
62
|
start_heartbeat_thread
|
|
63
63
|
end
|
|
64
64
|
|
|
@@ -68,7 +68,7 @@ module Profiler
|
|
|
68
68
|
config = Profiler.configuration
|
|
69
69
|
uri = master_uri("register")
|
|
70
70
|
body = { name: config.resolved_name, url: config.self_url }.to_json
|
|
71
|
-
resp =
|
|
71
|
+
resp = post(uri, body)
|
|
72
72
|
unless resp.code.to_i.between?(200, 299)
|
|
73
73
|
raise "Master returned #{resp.code}: #{resp.body.to_s.slice(0, 200)}"
|
|
74
74
|
end
|
|
@@ -80,10 +80,19 @@ module Profiler
|
|
|
80
80
|
config = Profiler.configuration
|
|
81
81
|
uri = master_uri("heartbeat")
|
|
82
82
|
body = { name: config.resolved_name }.to_json
|
|
83
|
-
resp =
|
|
83
|
+
resp = post(uri, body)
|
|
84
84
|
raise "Heartbeat rejected #{resp.code}" unless resp.code.to_i.between?(200, 299)
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
+
def post(uri, body)
|
|
88
|
+
Profiler.untracked_http do
|
|
89
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https",
|
|
90
|
+
open_timeout: OPEN_TIMEOUT, read_timeout: READ_TIMEOUT) do |http|
|
|
91
|
+
http.post(uri.request_uri, body, request_headers)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
87
96
|
# Refused before any request when the secret would cross the network in clear, or when
|
|
88
97
|
# there is no secret for the master to accept.
|
|
89
98
|
def master_uri(action)
|
|
@@ -111,20 +120,24 @@ module Profiler
|
|
|
111
120
|
@thread = Profiler::Instrumentation::RequestContext.detached { Thread.new { heartbeat_loop } }
|
|
112
121
|
end
|
|
113
122
|
|
|
123
|
+
# The first registration is the first turn of the loop, so an unreachable master never
|
|
124
|
+
# delays the boot of the process that started the client.
|
|
114
125
|
def heartbeat_loop
|
|
115
126
|
interval = Profiler.configuration.cluster_heartbeat_interval
|
|
116
127
|
loop do
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
if @registered
|
|
129
|
+
heartbeat!
|
|
130
|
+
else
|
|
119
131
|
register!
|
|
120
132
|
@registered = true
|
|
121
|
-
log_info("Re-registered with master after previous failure")
|
|
122
|
-
else
|
|
123
|
-
heartbeat!
|
|
133
|
+
log_info("Re-registered with master after previous failure") if @failed
|
|
124
134
|
end
|
|
125
135
|
rescue => e
|
|
126
136
|
@registered = false
|
|
137
|
+
@failed = true
|
|
127
138
|
log_warn("communication with the master failed, will retry", e)
|
|
139
|
+
ensure
|
|
140
|
+
sleep interval
|
|
128
141
|
end
|
|
129
142
|
end
|
|
130
143
|
|
|
@@ -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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
data/lib/profiler/mcp/server.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
|
data/lib/profiler/version.rb
CHANGED