Class: Async::Service::Supervisor::Envoy::Monitor

Inherits:
Monitor
  • Object
show all
Defined in:
lib/async/service/supervisor/envoy/monitor.rb

Overview

Represents a supervisor monitor that publishes worker endpoints to Envoy using xDS.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bind: nil, delegate: Delegate.new, control_plane: Async::GRPC::XDS::ControlPlane.new, **options) ⇒ Monitor

Initialize the monitor.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 25

def initialize(
	bind: nil,
	delegate: Delegate.new,
	control_plane: Async::GRPC::XDS::ControlPlane.new,
	**options
)
	super(**options)
	
	@bind = bind
	@delegate = delegate
	@control_plane = control_plane
	@controllers = {}
	@published_clusters = {}
	@server_task = nil
	@mutex = Mutex.new
end

Instance Attribute Details

#control_planeObject (readonly)

Returns the value of attribute control_plane.



43
44
45
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 43

def control_plane
  @control_plane
end

#delegateObject (readonly)

Returns the value of attribute delegate.



46
47
48
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 46

def delegate
  @delegate
end

#The xDS control plane receiving cluster and endpoint updates.(xDScontrolplanereceivingcluster) ⇒ Object (readonly)



43
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 43

attr :control_plane

Instance Method Details

#as_jsonObject

Convert the currently published endpoints to JSON-compatible data.



86
87
88
89
90
91
92
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 86

def as_json
	@mutex.synchronize do
		{
			clusters: build_clusters
		}
	end
end

#register(supervisor_controller) ⇒ Object

Register a supervisor worker with Envoy.



51
52
53
54
55
56
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 51

def register(supervisor_controller)
	@mutex.synchronize do
		@controllers[supervisor_controller.id] = supervisor_controller
		reconcile
	end
end

#remove(supervisor_controller) ⇒ Object

Remove a supervisor worker from Envoy.



61
62
63
64
65
66
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 61

def remove(supervisor_controller)
	@mutex.synchronize do
		@controllers.delete(supervisor_controller.id)
		reconcile
	end
end

#run(parent: Async::Task.current) ⇒ Object

Run the monitor and optional xDS server task.



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 71

def run(parent: Async::Task.current)
	task = super(parent: parent)
	
	if @bind
		@server_task = parent.async do
			endpoint = Async::HTTP::Endpoint.parse(@bind, protocol: Async::HTTP::Protocol::HTTP2)
			Async::GRPC::XDS::Server.new(@control_plane).run(endpoint)
		end
	end
	
	task
end

#run_onceObject

Refresh endpoint health and publish updated EDS state.



96
97
98
99
100
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 96

def run_once
	@mutex.synchronize do
		reconcile
	end
end

#The delegate used to map supervisor state into Envoy endpoints.=(delegateusedtomapsupervisorstateintoEnvoyendpoints. = (value)) ⇒ Object



46
# File 'lib/async/service/supervisor/envoy/monitor.rb', line 46

attr :delegate