Class: Vivarium::DaemonClient

Inherits:
Object
  • Object
show all
Defined in:
lib/vivarium/daemon_client.rb

Overview

HTTP-over-Unix-domain-socket client for talking to vivariumd. The client side never touches BPF maps or the ring buffer directly; everything goes through here.

Instance Method Summary collapse

Constructor Details

#initialize(socket_path: Vivarium.socket_path) ⇒ DaemonClient

Returns a new instance of DaemonClient.



9
10
11
# File 'lib/vivarium/daemon_client.rb', line 9

def initialize(socket_path: Vivarium.socket_path)
  @socket_path = socket_path
end

Instance Method Details

#healthy?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/vivarium/daemon_client.rb', line 13

def healthy?
  status, = simple_request("GET", "/healthz")
  status == 200
rescue Error
  false
end

#open_event_stream(since: nil) ⇒ Object

Opens a dedicated streaming connection to GET /events, consumes the response headers, and returns the still-open socket positioned at the start of the chunked body. The caller is responsible for reading chunks and closing it.



31
32
33
34
35
36
37
38
39
40
# File 'lib/vivarium/daemon_client.rb', line 31

def open_event_stream(since: nil)
  sock = connect
  path = since ? "/events?since=#{since}" : "/events"
  sock.write("GET #{path} HTTP/1.1\r\n")
  sock.write("Host: vivarium\r\n")
  sock.write("Accept: application/octet-stream\r\n")
  sock.write("\r\n")
  read_response_headers(sock)
  sock
end

#register(pid) ⇒ Object



20
21
22
# File 'lib/vivarium/daemon_client.rb', line 20

def register(pid)
  simple_request("PUT", "/targets/#{pid}")
end

#unregister(pid) ⇒ Object



24
25
26
# File 'lib/vivarium/daemon_client.rb', line 24

def unregister(pid)
  simple_request("DELETE", "/targets/#{pid}")
end