Class: Async::GRPC::XDS::Resources::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/async/grpc/xds/resources.rb

Overview

Represents a single endpoint Based on envoy.config.endpoint.v3.LbEndpoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(load_balancer_endpoint) ⇒ Endpoint

Initialize an endpoint from a protobuf message or hash.



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/async/grpc/xds/resources.rb', line 224

def initialize(load_balancer_endpoint)
	if load_balancer_endpoint.is_a?(Hash)
		endpoint_data = load_balancer_endpoint[:endpoint] || {}
		address_data = endpoint_data[:address] || {}
		socket_address = address_data[:socket_address] || {}
		
		@address = socket_address[:address] || "localhost"
		@port = socket_address[:port_value] || 50051
		@health_status = parse_health_status(load_balancer_endpoint[:health_status])
		@metadata = load_balancer_endpoint[:metadata] || {}
	else
		socket_address = load_balancer_endpoint.endpoint.address.socket_address
		@address = socket_address.address
		@port = socket_address.port_value
		@health_status = parse_health_status(load_balancer_endpoint.health_status)
		@metadata = load_balancer_endpoint. || {}
	end
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



220
221
222
# File 'lib/async/grpc/xds/resources.rb', line 220

def address
  @address
end

#health_statusObject (readonly)

Returns the value of attribute health_status.



220
221
222
# File 'lib/async/grpc/xds/resources.rb', line 220

def health_status
  @health_status
end

#metadataObject (readonly)

Returns the value of attribute metadata.



220
221
222
# File 'lib/async/grpc/xds/resources.rb', line 220

def 
  @metadata
end

#portObject (readonly)

Returns the value of attribute port.



220
221
222
# File 'lib/async/grpc/xds/resources.rb', line 220

def port
  @port
end

Instance Method Details

#healthy?Boolean

Determine whether this endpoint is eligible to receive traffic.

Returns:

  • (Boolean)


245
246
247
# File 'lib/async/grpc/xds/resources.rb', line 245

def healthy?
	@health_status == :HEALTHY || @health_status == :UNKNOWN
end

#uriObject

Build the HTTP URI for this endpoint.



251
252
253
254
255
# File 'lib/async/grpc/xds/resources.rb', line 251

def uri
	# Use http for insecure/docker environments (gRPC h2c)
	scheme = ENV["XDS_ENDPOINT_SCHEME"] || "http"
	"#{scheme}://#{@address}:#{@port}"
end