Async::Service::Supervisor::EnvoySourceAsyncServiceSupervisorEnvoyEndpoint

class Endpoint

Represents an endpoint published to Envoy EDS.

Definitions

def self.wrap(value)

Wrap an endpoint-like value.

Signature

parameter value Endpoint | Hash | Object | Nil

The endpoint value to wrap.

returns Endpoint | Nil

The wrapped endpoint, or nil if no endpoint was supplied.

raises ArgumentError

If the value cannot be converted to an endpoint.

Implementation

def self.wrap(value)
	case value
	when nil
		nil
	when self
		value
	when Hash
		new(**symbolize_keys(value))
	else
		raise ArgumentError, "Invalid Envoy endpoint: #{value.inspect}"
	end
end

def self.symbolize_keys(hash)

Convert hash keys to symbols.

Signature

parameter hash Hash

The hash to convert.

returns Hash

A copy of the hash with symbol keys.

Implementation

def self.symbolize_keys(hash)
	hash.each_with_object({}) do |(key, value), result|
		result[key.to_sym] = value
	end
end

def initialize(address:, port:, name: nil, hostname: nil, protocol: nil, healthy: true)

Initialize the endpoint.

Signature

parameter name String | Nil

The optional endpoint name.

parameter address String

The endpoint IP address or hostname.

parameter port Integer

The endpoint port.

parameter hostname String | Nil

The optional endpoint hostname.

parameter protocol String | Symbol | Nil

The optional endpoint protocol.

parameter healthy Boolean

Whether the endpoint should be published as healthy.

Implementation

def initialize(address:, port:, name: nil, hostname: nil, protocol: nil, healthy: true)
	@name = name
	@address = address
	@port = port.to_i
	@hostname = hostname
	@protocol = protocol
	@healthy = healthy
end

attr :name

Signature

attribute String | Nil

The optional endpoint name.

attr :address

Signature

attribute String

The endpoint IP address or hostname.

attr :port

Signature

attribute Integer

The endpoint port.

attr :hostname

Signature

attribute String | Nil

The optional endpoint hostname.

attr :protocol

Signature

attribute String | Symbol | Nil

The optional endpoint protocol.

def healthy?

Whether the endpoint is healthy.

Signature

returns Boolean

Returns true when the endpoint should be published as healthy.

Implementation

def healthy?
	@healthy
end

def to_h

Convert the endpoint to a hash suitable for the xDS control plane.

Signature

returns Hash

The endpoint attributes.

Implementation

def to_h
	{
		name: @name,
		address: @address,
		port: @port,
		hostname: @hostname,
		protocol: @protocol,
		healthy: @healthy
	}.compact
end