class Endpoint
Represents an upstream endpoint published to Envoy EDS.
Definitions
def self.build(name:, scheme:, protocols:, addresses:)
Build an immutable endpoint.
Signature
-
parameter
nameString The upstream cluster name.
-
parameter
schemeString | Symbol The upstream application scheme.
-
parameter
protocolsArray(String) The supported upstream HTTP protocol names.
-
parameter
addressesArray(Hash) The grouped concrete addresses.
-
returns
Endpoint The immutable endpoint.
Implementation
def self.build(name:, scheme:, protocols:, addresses:)
new(
name.to_s,
scheme.to_sym,
protocols.map(&:to_s).uniq,
addresses,
).tap(&:freeze)
end
def self.wrap(value)
Wrap serialized endpoint state.
Signature
-
parameter
valueEndpoint | Hash The value to wrap.
-
returns
Endpoint The endpoint value.
Implementation
def self.wrap(value)
case value
when self
value
when Hash
build(**value)
else
raise ArgumentError, "Invalid Envoy endpoint: #{value.inspect}"
end
end
def initialize(name, scheme, protocols, addresses)
Initialize an endpoint.
Signature
-
parameter
nameString The upstream cluster name.
-
parameter
schemeSymbol The upstream application scheme.
-
parameter
protocolsArray(String) The supported upstream HTTP protocol names.
-
parameter
addressesArray(Hash) The grouped concrete addresses.
Implementation
def initialize(name, scheme, protocols, addresses)
@name = name
@scheme = scheme
@protocols = protocols
raise ArgumentError, "An endpoint requires at least one protocol!" if @protocols.empty?
@addresses = addresses
raise ArgumentError, "An endpoint requires at least one address!" if @addresses.empty?
@hash = nil
end
attr :name
Signature
-
attribute
String The upstream cluster name.
attr :scheme
Signature
-
attribute
Symbol The upstream application scheme.
attr :protocols
Signature
-
attribute
Array(String) The supported upstream HTTP protocol names.
attr :addresses
Signature
-
attribute
Array(Hash) The grouped concrete addresses.
def freeze
Freeze this endpoint and cache its value hash.
Implementation
def freeze
return self if frozen?
@name.freeze
@protocols.each(&:freeze).freeze
@addresses.each do |address|
address.each_value(&:freeze)
address.freeze
end.freeze
@hash = self.hash
super
end
def eql?(other)
Compare this endpoint with another endpoint by value.
Signature
-
parameter
otherObject The object to compare.
-
returns
Boolean Whether both endpoints have identical values.
Implementation
def eql?(other)
other.instance_of?(self.class) &&
@name == other.name &&
@scheme == other.scheme &&
@protocols == other.protocols &&
@addresses == other.addresses
end
def hash
Compute the value hash used when grouping endpoints.
Signature
-
returns
Integer The endpoint value hash.
Implementation
def hash
@hash || [self.class, @name, @scheme, @protocols, @addresses].hash
end