Module: Async::GRPC::XDS::ClientSideWeightedRoundRobin

Defined in:
lib/async/grpc/xds/client_side_weighted_round_robin.rb

Overview

Builds Envoy's client-side weighted-round-robin policy with out-of-band ORCA reporting.

Class Method Summary collapse

Class Method Details

.build(port, reporting_period: 1) ⇒ Object

Build the typed load-balancing policy.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/async/grpc/xds/client_side_weighted_round_robin.rb', line 22

def self.build(port, reporting_period: 1)
	seconds = reporting_period.to_i
	duration = Google::Protobuf::Duration.new(
		seconds: seconds,
		nanos: ((reporting_period.to_f - seconds) * 1_000_000_000).to_i
	)
	configuration = Envoy::Extensions::LoadBalancingPolicies::ClientSideWeightedRoundRobin::V3::ClientSideWeightedRoundRobin.new(
		enable_oob_load_report: Google::Protobuf::BoolValue.new(value: true),
		oob_reporting_period: duration,
		oob_reporting_config: Envoy::Extensions::LoadBalancingPolicies::Common::V3::OrcaOobReportingConfig.new(
			port_value: Integer(port)
		)
	)
	
	Envoy::Config::Cluster::V3::LoadBalancingPolicy.new(
		policies: [
			Envoy::Config::Cluster::V3::LoadBalancingPolicy::Policy.new(
				typed_extension_config: Envoy::Config::Core::V3::TypedExtensionConfig.new(
					name: "envoy.load_balancing_policies.client_side_weighted_round_robin",
					typed_config: Google::Protobuf::Any.new(
						type_url: "type.googleapis.com/#{configuration.class.descriptor.name}",
						value: configuration.to_proto
					)
				)
			)
		]
	)
end