Module: Async::GRPC::XDS::Cluster

Extended by:
Cluster
Included in:
Cluster
Defined in:
lib/async/grpc/xds/cluster.rb

Overview

Builds Envoy cluster resources.

Constant Summary collapse

TYPE_URL =
"type.googleapis.com/envoy.config.cluster.v3.Cluster"

Instance Method Summary collapse

Instance Method Details

#build(name, service_name: name, load_balancing_policy: nil, health_checks: [], connect_timeout: 5, protocol: :http2) ⇒ Object

Build an EDS cluster resource.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/async/grpc/xds/cluster.rb', line 30

def build(name, service_name: name, load_balancing_policy: nil, health_checks: [], connect_timeout: 5, protocol: :http2)
	options = {
		name: name.to_s,
		type: Envoy::Config::Cluster::V3::Cluster::DiscoveryType::EDS,
		eds_cluster_config: Envoy::Config::Cluster::V3::Cluster::EdsClusterConfig.new(
			service_name: service_name.to_s,
			eds_config: Envoy::Config::Core::V3::ConfigSource.new(
				ads: Envoy::Config::Core::V3::AggregatedConfigSource.new
			)
		),
		connect_timeout: duration(connect_timeout),
		health_checks: health_checks,
	}
	
	options[:load_balancing_policy] = load_balancing_policy if load_balancing_policy
	
	case protocol
	when :http1
		# Envoy uses HTTP/1 by default.
	when :http2
		options[:http2_protocol_options] = Envoy::Config::Core::V3::Http2ProtocolOptions.new
	else
		raise ArgumentError, "Unsupported upstream protocol: #{protocol.inspect}"
	end
	
	Envoy::Config::Cluster::V3::Cluster.new(**options)
end