Async::GRPC::XDSSourceAsyncGRPCXDSResourcesEndpoint

class Endpoint

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

Definitions

def initialize(load_balancer_endpoint)

Initialize an endpoint from a protobuf message or hash.

Signature

parameter load_balancer_endpoint Envoy::Config::Endpoint::V3::LbEndpoint | Hash

The load-balancer endpoint representation.

Implementation

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.metadata || {}
	end
end

def healthy?

Determine whether this endpoint is eligible to receive traffic.

Signature

returns Boolean

true if the endpoint is healthy or has unknown health.

Implementation

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

def uri

Build the HTTP URI for this endpoint.

Signature

returns String

The endpoint URI.

Implementation

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