Class: Vivarium::Registry

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

Overview

Wraps the daemon’s live BPF target maps so the API can (un)register PIDs.

Constant Summary collapse

OTEL_CTX_PACK_FMT =

struct otel_ctx_t { trace_idhi; u64 lo; u64 span_id; u64 parent_span_id; }

"Q<Q<Q<Q<"

Instance Method Summary collapse

Constructor Details

#initialize(config_root_targets, config_spawned_targets, otel_ctx = nil) ⇒ Registry

Returns a new instance of Registry.



51
52
53
54
55
# File 'lib/vivarium/api_server.rb', line 51

def initialize(config_root_targets, config_spawned_targets, otel_ctx = nil)
  @config_root_targets = config_root_targets
  @config_spawned_targets = config_spawned_targets
  @otel_ctx = otel_ctx
end

Instance Method Details

#register(pid) ⇒ Object

Registering a root target marks the start of a trace: issue a fresh 128-bit trace_id and a root span_id (no parent) into the otel_ctx map, keyed by the root pid (== the main thread’s tid).



60
61
62
63
64
65
66
67
68
# File 'lib/vivarium/api_server.rb', line 60

def register(pid)
  @config_root_targets[pid] = 1
  return unless @otel_ctx

  hi = SecureRandom.random_number(1 << 64)
  lo = SecureRandom.random_number(1 << 64)
  span = SecureRandom.random_number(1 << 64)
  write_otel_ctx(pid, hi, lo, span, 0)
end

#unregister(pid) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/vivarium/api_server.rb', line 70

def unregister(pid)
  @config_root_targets.delete(pid)
  @config_spawned_targets.clear
  @otel_ctx&.clear
rescue KeyError
  nil
end