async-grpc-xds 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/grpc/xds/ads_stream.rb +4 -0
- data/lib/async/grpc/xds/client_side_weighted_round_robin.rb +53 -0
- data/lib/async/grpc/xds/cluster.rb +71 -0
- data/lib/async/grpc/xds/control_plane.rb +47 -6
- data/lib/async/grpc/xds/discovery_client.rb +12 -2
- data/lib/async/grpc/xds/endpoint.rb +102 -0
- data/lib/async/grpc/xds/resource_cache.rb +1 -0
- data/lib/async/grpc/xds/resources.rb +9 -0
- data/lib/async/grpc/xds/server.rb +7 -0
- data/lib/async/grpc/xds/service.rb +24 -0
- data/lib/async/grpc/xds/version.rb +4 -1
- data/lib/async/grpc/xds.rb +3 -1
- data/lib/envoy/config/common/mutation_rules/v3/mutation_rules_pb.rb +33 -0
- data/lib/envoy/config/route/v3/route_components_pb.rb +108 -0
- data/lib/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin_pb.rb +30 -0
- data/lib/envoy/extensions/load_balancing_policies/common/v3/common_pb.rb +41 -0
- data/lib/envoy/type/tracing/v3/custom_tag_pb.rb +31 -0
- data/lib/xds/data/orca/v3/orca_load_report_pb.rb +24 -0
- data/lib/xds/service/orca/v3/open_rca_service.rb +23 -0
- data/lib/xds/service/orca/v3/orca_pb.rb +25 -0
- data/proto/envoy/config/common/mutation_rules/v3/mutation_rules.proto +113 -0
- data/proto/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.proto +96 -0
- data/proto/envoy/extensions/load_balancing_policies/common/v3/common.proto +188 -0
- data/proto/envoy/type/tracing/v3/custom_tag.proto +109 -0
- data/proto/readme.md +3 -0
- data/proto/xds/data/orca/v3/orca_load_report.proto +58 -0
- data/proto/xds/service/orca/v3/orca.proto +36 -0
- data/readme.md +16 -2
- data/releases.md +12 -0
- data/xds/readme.md +2 -29
- data/xds/test/async/grpc/xds/control_plane.rb +5 -6
- data.tar.gz.sig +0 -0
- metadata +18 -2
- metadata.gz.sig +0 -0
- data/lib/async/grpc/xds/resource_builder.rb +0 -138
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2026, by Samuel Williams.
|
|
5
|
-
|
|
6
|
-
require "google/protobuf/any_pb"
|
|
7
|
-
require "google/protobuf/duration_pb"
|
|
8
|
-
|
|
9
|
-
require "envoy/config/cluster/v3/cluster_pb"
|
|
10
|
-
require "envoy/config/core/v3/address_pb"
|
|
11
|
-
require "envoy/config/core/v3/config_source_pb"
|
|
12
|
-
require "envoy/config/core/v3/health_check_pb"
|
|
13
|
-
require "envoy/config/core/v3/protocol_pb"
|
|
14
|
-
require "envoy/config/endpoint/v3/endpoint_pb"
|
|
15
|
-
require "envoy/config/endpoint/v3/endpoint_components_pb"
|
|
16
|
-
|
|
17
|
-
module Async
|
|
18
|
-
module GRPC
|
|
19
|
-
module XDS
|
|
20
|
-
# Builds Envoy xDS resource protobufs.
|
|
21
|
-
module ResourceBuilder
|
|
22
|
-
TYPE_URL_PREFIX = "type.googleapis.com"
|
|
23
|
-
|
|
24
|
-
CLUSTER_TYPE = "#{TYPE_URL_PREFIX}/envoy.config.cluster.v3.Cluster"
|
|
25
|
-
ENDPOINT_TYPE = "#{TYPE_URL_PREFIX}/envoy.config.endpoint.v3.ClusterLoadAssignment"
|
|
26
|
-
|
|
27
|
-
def self.pack(resource)
|
|
28
|
-
Google::Protobuf::Any.new(
|
|
29
|
-
type_url: "#{TYPE_URL_PREFIX}/#{resource.class.descriptor.name}",
|
|
30
|
-
value: resource.to_proto
|
|
31
|
-
)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def self.cluster(name, service_name: name, load_balancer_policy: :round_robin, connect_timeout: 5)
|
|
35
|
-
Envoy::Config::Cluster::V3::Cluster.new(
|
|
36
|
-
name: name.to_s,
|
|
37
|
-
type: Envoy::Config::Cluster::V3::Cluster::DiscoveryType::EDS,
|
|
38
|
-
eds_cluster_config: Envoy::Config::Cluster::V3::Cluster::EdsClusterConfig.new(
|
|
39
|
-
service_name: service_name.to_s,
|
|
40
|
-
eds_config: Envoy::Config::Core::V3::ConfigSource.new(
|
|
41
|
-
ads: Envoy::Config::Core::V3::AggregatedConfigSource.new
|
|
42
|
-
)
|
|
43
|
-
),
|
|
44
|
-
connect_timeout: duration(connect_timeout),
|
|
45
|
-
lb_policy: load_balancer_policy_value(load_balancer_policy),
|
|
46
|
-
http2_protocol_options: Envoy::Config::Core::V3::Http2ProtocolOptions.new
|
|
47
|
-
)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def self.cluster_load_assignment(cluster_name, endpoints)
|
|
51
|
-
Envoy::Config::Endpoint::V3::ClusterLoadAssignment.new(
|
|
52
|
-
cluster_name: cluster_name.to_s,
|
|
53
|
-
endpoints: [
|
|
54
|
-
Envoy::Config::Endpoint::V3::LocalityLbEndpoints.new(
|
|
55
|
-
lb_endpoints: endpoints.map{|endpoint| load_balancer_endpoint(endpoint)}
|
|
56
|
-
)
|
|
57
|
-
]
|
|
58
|
-
)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def self.load_balancer_endpoint(endpoint)
|
|
62
|
-
endpoint = normalize_endpoint(endpoint)
|
|
63
|
-
|
|
64
|
-
Envoy::Config::Endpoint::V3::LbEndpoint.new(
|
|
65
|
-
endpoint: Envoy::Config::Endpoint::V3::Endpoint.new(
|
|
66
|
-
address: Envoy::Config::Core::V3::Address.new(
|
|
67
|
-
socket_address: Envoy::Config::Core::V3::SocketAddress.new(
|
|
68
|
-
protocol: Envoy::Config::Core::V3::SocketAddress::Protocol::TCP,
|
|
69
|
-
address: endpoint[:address],
|
|
70
|
-
port_value: endpoint[:port]
|
|
71
|
-
)
|
|
72
|
-
),
|
|
73
|
-
hostname: endpoint[:hostname].to_s
|
|
74
|
-
),
|
|
75
|
-
health_status: health_status_value(endpoint.fetch(:healthy, true))
|
|
76
|
-
)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def self.normalize_endpoint(endpoint)
|
|
80
|
-
case endpoint
|
|
81
|
-
when Hash
|
|
82
|
-
{
|
|
83
|
-
address: endpoint.fetch(:address){endpoint.fetch("address")},
|
|
84
|
-
port: endpoint.fetch(:port){endpoint.fetch("port")}.to_i,
|
|
85
|
-
hostname: endpoint[:hostname] || endpoint["hostname"],
|
|
86
|
-
healthy: endpoint.key?(:healthy) ? endpoint[:healthy] : endpoint.fetch("healthy", true)
|
|
87
|
-
}
|
|
88
|
-
else
|
|
89
|
-
if endpoint.respond_to?(:address) && endpoint.respond_to?(:port)
|
|
90
|
-
{
|
|
91
|
-
address: endpoint.address,
|
|
92
|
-
port: endpoint.port.to_i,
|
|
93
|
-
hostname: endpoint.respond_to?(:hostname) ? endpoint.hostname : nil,
|
|
94
|
-
healthy: endpoint.respond_to?(:healthy?) ? endpoint.healthy? : true
|
|
95
|
-
}
|
|
96
|
-
else
|
|
97
|
-
raise ArgumentError, "Invalid endpoint: #{endpoint.inspect}"
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def self.duration(seconds)
|
|
103
|
-
whole_seconds = seconds.to_i
|
|
104
|
-
nanos = ((seconds.to_f - whole_seconds) * 1_000_000_000).to_i
|
|
105
|
-
|
|
106
|
-
Google::Protobuf::Duration.new(seconds: whole_seconds, nanos: nanos)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def self.load_balancer_policy_value(load_balancer_policy)
|
|
110
|
-
case load_balancer_policy
|
|
111
|
-
when :round_robin, :ROUND_ROBIN, "round_robin", "ROUND_ROBIN"
|
|
112
|
-
Envoy::Config::Cluster::V3::Cluster::LbPolicy::ROUND_ROBIN
|
|
113
|
-
when :least_request, :LEAST_REQUEST, "least_request", "LEAST_REQUEST"
|
|
114
|
-
Envoy::Config::Cluster::V3::Cluster::LbPolicy::LEAST_REQUEST
|
|
115
|
-
when :random, :RANDOM, "random", "RANDOM"
|
|
116
|
-
Envoy::Config::Cluster::V3::Cluster::LbPolicy::RANDOM
|
|
117
|
-
else
|
|
118
|
-
load_balancer_policy
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def self.health_status_value(healthy)
|
|
123
|
-
case healthy
|
|
124
|
-
when :healthy, :HEALTHY, "healthy", "HEALTHY", true
|
|
125
|
-
Envoy::Config::Core::V3::HealthStatus::HEALTHY
|
|
126
|
-
when :unhealthy, :UNHEALTHY, "unhealthy", "UNHEALTHY", false
|
|
127
|
-
Envoy::Config::Core::V3::HealthStatus::UNHEALTHY
|
|
128
|
-
when :degraded, :DEGRADED, "degraded", "DEGRADED"
|
|
129
|
-
Envoy::Config::Core::V3::HealthStatus::DEGRADED
|
|
130
|
-
else
|
|
131
|
-
Envoy::Config::Core::V3::HealthStatus::UNKNOWN
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
|