Class: Profiler::Cluster::SlaveProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/profiler/cluster/slave_proxy.rb

Constant Summary collapse

OPEN_TIMEOUT =

A slow or hung slave must not block the master's request thread for long.

5
READ_TIMEOUT =

seconds

10

Instance Method Summary collapse

Constructor Details

#initialize(slave_name) ⇒ SlaveProxy

seconds

Raises:



14
15
16
17
18
19
# File 'lib/profiler/cluster/slave_proxy.rb', line 14

def initialize(slave_name)
  entry = Profiler.slave_registry.find!(slave_name)
  raise Profiler::Error, "Slave profiler '#{slave_name}' is offline" if entry.status == "offline"

  @base_url = entry.url.to_s.chomp("/")
end

Instance Method Details

#clear(type: nil) ⇒ Object



38
39
40
41
# File 'lib/profiler/cluster/slave_proxy.rb', line 38

def clear(type: nil)
  params = type ? "?type=#{URI.encode_www_form_component(type)}" : ""
  delete_json("/_profiler/api/profiles/clear#{params}")
end

#delete_json(path) ⇒ Object



58
59
60
61
# File 'lib/profiler/cluster/slave_proxy.rb', line 58

def delete_json(path)
  uri = build_uri(path)
  request(uri, Net::HTTP::Delete.new(uri))
end

#get_json(path, params = {}) ⇒ Object

Generic HTTP access for action tools



45
46
47
48
# File 'lib/profiler/cluster/slave_proxy.rb', line 45

def get_json(path, params = {})
  uri = build_uri(path, params)
  request(uri, Net::HTTP::Get.new(uri))
end

#list(limit: 50, offset: 0) ⇒ Object

Storage-compatible interface for MCP query tools



23
24
25
26
27
28
# File 'lib/profiler/cluster/slave_proxy.rb', line 23

def list(limit: 50, offset: 0, **)
  # all_types mirrors Profiler.storage.list, which returns every profile type;
  # without it the proxy would only ever see http profiles (see ProfilesController#index).
  data = get_json("/_profiler/api/profiles", limit: limit, offset: offset, all_types: true)
  Array(data["profiles"]).map { |h| profile_from_api(h) }
end

#load(token) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/profiler/cluster/slave_proxy.rb', line 30

def load(token)
  data = get_json("/_profiler/api/profiles/#{token}")
  return nil unless data["token"] || data["profile"]

  raw = data["profile"] || data
  profile_from_api(raw)
end

#patch_json(path, body = {}) ⇒ Object



54
55
56
# File 'lib/profiler/cluster/slave_proxy.rb', line 54

def patch_json(path, body = {})
  request(*json_request(Net::HTTP::Patch, path, body))
end

#post_json(path, body = {}) ⇒ Object



50
51
52
# File 'lib/profiler/cluster/slave_proxy.rb', line 50

def post_json(path, body = {})
  request(*json_request(Net::HTTP::Post, path, body))
end