From 939dec124dc3216faf9ce56be730118edf40f031 Mon Sep 17 00:00:00 2001 From: Alexey Tochilkin Date: Sun, 19 Nov 2023 16:51:26 +0200 Subject: [PATCH 1/2] Revert "Allow passing additional options directly to GRPC clients (#139)" This reverts commit b946b42ca90cb01d6411675a87db0c30c2bd937a. --- lib/etcdv3/auth.rb | 2 +- lib/etcdv3/kv.rb | 2 +- lib/etcdv3/lease.rb | 2 +- lib/etcdv3/lock.rb | 2 +- lib/etcdv3/maintenance.rb | 2 +- lib/etcdv3/namespace/kv.rb | 2 +- lib/etcdv3/namespace/lock.rb | 2 +- lib/etcdv3/namespace/watch.rb | 2 +- lib/etcdv3/watch.rb | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/etcdv3/auth.rb b/lib/etcdv3/auth.rb index d8d85c7..0167870 100644 --- a/lib/etcdv3/auth.rb +++ b/lib/etcdv3/auth.rb @@ -10,7 +10,7 @@ class Auth } def initialize(hostname, credentials, timeout, metadata = {}) - @stub = Etcdserverpb::Auth::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + @stub = Etcdserverpb::Auth::Stub.new(hostname, credentials) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/kv.rb b/lib/etcdv3/kv.rb index 48f9d63..ba1ebdb 100644 --- a/lib/etcdv3/kv.rb +++ b/lib/etcdv3/kv.rb @@ -5,7 +5,7 @@ class KV include GRPC::Core::TimeConsts def initialize(hostname, credentials, timeout, metadata={}) - @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + @stub = Etcdserverpb::KV::Stub.new(hostname, credentials) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/lease.rb b/lib/etcdv3/lease.rb index 437976c..462c3f6 100644 --- a/lib/etcdv3/lease.rb +++ b/lib/etcdv3/lease.rb @@ -3,7 +3,7 @@ class Lease include GRPC::Core::TimeConsts def initialize(hostname, credentials, timeout, metadata={}) - @stub = Etcdserverpb::Lease::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + @stub = Etcdserverpb::Lease::Stub.new(hostname, credentials) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/lock.rb b/lib/etcdv3/lock.rb index cb6ee81..ce9b36c 100644 --- a/lib/etcdv3/lock.rb +++ b/lib/etcdv3/lock.rb @@ -3,7 +3,7 @@ class Lock include GRPC::Core::TimeConsts def initialize(hostname, credentials, timeout, metadata = {}) - @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + @stub = V3lockpb::Lock::Stub.new(hostname, credentials) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/maintenance.rb b/lib/etcdv3/maintenance.rb index d8cd890..341c452 100644 --- a/lib/etcdv3/maintenance.rb +++ b/lib/etcdv3/maintenance.rb @@ -13,7 +13,7 @@ class Maintenance } def initialize(hostname, credentials, _timeout, metadata = {}) - @stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + @stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials) @metadata = metadata end diff --git a/lib/etcdv3/namespace/kv.rb b/lib/etcdv3/namespace/kv.rb index f9195c2..a6b8fb2 100644 --- a/lib/etcdv3/namespace/kv.rb +++ b/lib/etcdv3/namespace/kv.rb @@ -5,7 +5,7 @@ class KV include GRPC::Core::TimeConsts def initialize(hostname, credentials, timeout, namespace, metadata={}) - @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + @stub = Etcdserverpb::KV::Stub.new(hostname, credentials) @timeout = timeout @namespace = namespace @metadata = metadata diff --git a/lib/etcdv3/namespace/lock.rb b/lib/etcdv3/namespace/lock.rb index 6822f1a..76b60f6 100644 --- a/lib/etcdv3/namespace/lock.rb +++ b/lib/etcdv3/namespace/lock.rb @@ -4,7 +4,7 @@ class Lock include Etcdv3::Namespace::Utilities def initialize(hostname, credentials, timeout, namespace, metadata = {}) - @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + @stub = V3lockpb::Lock::Stub.new(hostname, credentials) @timeout = timeout @namespace = namespace @metadata = metadata diff --git a/lib/etcdv3/namespace/watch.rb b/lib/etcdv3/namespace/watch.rb index 6030d0e..199a348 100644 --- a/lib/etcdv3/namespace/watch.rb +++ b/lib/etcdv3/namespace/watch.rb @@ -4,7 +4,7 @@ class Watch include Etcdv3::Namespace::Utilities def initialize(hostname, credentials, timeout, namespace, metadata = {}) - @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials) @timeout = timeout @namespace = namespace @metadata = metadata diff --git a/lib/etcdv3/watch.rb b/lib/etcdv3/watch.rb index 84fbfa9..a08691b 100644 --- a/lib/etcdv3/watch.rb +++ b/lib/etcdv3/watch.rb @@ -3,7 +3,7 @@ class Watch include GRPC::Core::TimeConsts def initialize(hostname, credentials, timeout, metadata = {}) - @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **metadata.delete(:client_options) || {}) + @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials) @timeout = timeout @metadata = metadata end From 5b12d270e69850efa2ca3fdf6ec495dada027fd0 Mon Sep 17 00:00:00 2001 From: Alexey Tochilkin Date: Sun, 19 Nov 2023 17:12:09 +0200 Subject: [PATCH 2/2] ability to set grpc_options on all levels --- lib/etcdv3.rb | 1 + lib/etcdv3/auth.rb | 4 ++-- lib/etcdv3/connection.rb | 7 ++++--- lib/etcdv3/connection_wrapper.rb | 4 ++-- lib/etcdv3/kv.rb | 4 ++-- lib/etcdv3/lease.rb | 4 ++-- lib/etcdv3/lock.rb | 4 ++-- lib/etcdv3/maintenance.rb | 4 ++-- lib/etcdv3/namespace/kv.rb | 4 ++-- lib/etcdv3/namespace/lock.rb | 4 ++-- lib/etcdv3/namespace/watch.rb | 4 ++-- lib/etcdv3/watch.rb | 4 ++-- 12 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/etcdv3.rb b/lib/etcdv3.rb index 742c610..81faed3 100644 --- a/lib/etcdv3.rb +++ b/lib/etcdv3.rb @@ -38,6 +38,7 @@ def initialize(**options) *sanitized_endpoints, @namespace, @options.fetch(:allow_reconnect, true), + grpc_options: @options.fetch(:grpc_options, {}), ) warn "WARNING: `url` is deprecated. Please use `endpoints` instead." if @options.key?(:url) authenticate(@options[:user], @options[:password]) if @options.key?(:user) diff --git a/lib/etcdv3/auth.rb b/lib/etcdv3/auth.rb index 0167870..95eee28 100644 --- a/lib/etcdv3/auth.rb +++ b/lib/etcdv3/auth.rb @@ -9,8 +9,8 @@ class Auth :readwrite => Authpb::Permission::Type::READWRITE } - def initialize(hostname, credentials, timeout, metadata = {}) - @stub = Etcdserverpb::Auth::Stub.new(hostname, credentials) + def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {}) + @stub = Etcdserverpb::Auth::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/connection.rb b/lib/etcdv3/connection.rb index 4d4b5d0..532a8e0 100644 --- a/lib/etcdv3/connection.rb +++ b/lib/etcdv3/connection.rb @@ -18,12 +18,13 @@ class Connection attr_reader :endpoint, :hostname, :handlers, :credentials, :namespace - def initialize(url, timeout, namespace, metadata={}) + def initialize(url, timeout, namespace, metadata={}, grpc_options={}) @endpoint = URI(url) @hostname = "#{@endpoint.hostname}:#{@endpoint.port}" @namespace = namespace @credentials = resolve_credentials @timeout = timeout + @grpc_options = grpc_options @handlers = handler_map(metadata) end @@ -46,13 +47,13 @@ def refresh_metadata(metadata) def handler_map(metadata={}) handlers = Hash[ HANDLERS.map do |key, klass| - [key, klass.new(@hostname, @credentials, @timeout, metadata)] + [key, klass.new(@hostname, @credentials, @timeout, metadata, @grpc_options)] end ] # Override any handlers that are namespace compatable. if @namespace NAMESPACE_HANDLERS.each do |key, klass| - handlers[key] = klass.new(@hostname, @credentials, @timeout, @namespace, metadata) + handlers[key] = klass.new(@hostname, @credentials, @timeout, @namespace, metadata, @grpc_options) end end diff --git a/lib/etcdv3/connection_wrapper.rb b/lib/etcdv3/connection_wrapper.rb index 271b2a0..b6a2ab9 100644 --- a/lib/etcdv3/connection_wrapper.rb +++ b/lib/etcdv3/connection_wrapper.rb @@ -3,11 +3,11 @@ class ConnectionWrapper attr_accessor :connection, :endpoints, :user, :password, :token, :timeout - def initialize(timeout, *endpoints, namespace, allow_reconnect) + def initialize(timeout, *endpoints, namespace, allow_reconnect, **kwargs) @user, @password, @token = nil, nil, nil @timeout = timeout @namespace = namespace - @endpoints = endpoints.map{|endpoint| Etcdv3::Connection.new(endpoint, @timeout, @namespace) } + @endpoints = endpoints.map{|endpoint| Etcdv3::Connection.new(endpoint, @timeout, @namespace, {}, kwargs.fetch(:grpc_options, {})) } @allow_reconnect = allow_reconnect @connection = @endpoints.first end diff --git a/lib/etcdv3/kv.rb b/lib/etcdv3/kv.rb index ba1ebdb..aa9c314 100644 --- a/lib/etcdv3/kv.rb +++ b/lib/etcdv3/kv.rb @@ -4,8 +4,8 @@ class KV include Etcdv3::KV::Requests include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, metadata={}) - @stub = Etcdserverpb::KV::Stub.new(hostname, credentials) + def initialize(hostname, credentials, timeout, metadata={}, grpc_options={}) + @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/lease.rb b/lib/etcdv3/lease.rb index 462c3f6..7e09d60 100644 --- a/lib/etcdv3/lease.rb +++ b/lib/etcdv3/lease.rb @@ -2,8 +2,8 @@ class Etcdv3 class Lease include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, metadata={}) - @stub = Etcdserverpb::Lease::Stub.new(hostname, credentials) + def initialize(hostname, credentials, timeout, metadata={}, grpc_options={}) + @stub = Etcdserverpb::Lease::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/lock.rb b/lib/etcdv3/lock.rb index ce9b36c..280769d 100644 --- a/lib/etcdv3/lock.rb +++ b/lib/etcdv3/lock.rb @@ -2,8 +2,8 @@ class Etcdv3 class Lock include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, metadata = {}) - @stub = V3lockpb::Lock::Stub.new(hostname, credentials) + def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {}) + @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end diff --git a/lib/etcdv3/maintenance.rb b/lib/etcdv3/maintenance.rb index 341c452..24e1fab 100644 --- a/lib/etcdv3/maintenance.rb +++ b/lib/etcdv3/maintenance.rb @@ -12,8 +12,8 @@ class Maintenance deactivate: 2 } - def initialize(hostname, credentials, _timeout, metadata = {}) - @stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials) + def initialize(hostname, credentials, _timeout, metadata = {}, grpc_options = {}) + @stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials, **grpc_options) @metadata = metadata end diff --git a/lib/etcdv3/namespace/kv.rb b/lib/etcdv3/namespace/kv.rb index a6b8fb2..d9dfa90 100644 --- a/lib/etcdv3/namespace/kv.rb +++ b/lib/etcdv3/namespace/kv.rb @@ -4,8 +4,8 @@ class KV include Etcdv3::Namespace::Utilities include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, namespace, metadata={}) - @stub = Etcdserverpb::KV::Stub.new(hostname, credentials) + def initialize(hostname, credentials, timeout, namespace, metadata={}, grpc_options={}) + @stub = Etcdserverpb::KV::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @namespace = namespace @metadata = metadata diff --git a/lib/etcdv3/namespace/lock.rb b/lib/etcdv3/namespace/lock.rb index 76b60f6..f929f66 100644 --- a/lib/etcdv3/namespace/lock.rb +++ b/lib/etcdv3/namespace/lock.rb @@ -3,8 +3,8 @@ class Lock include GRPC::Core::TimeConsts include Etcdv3::Namespace::Utilities - def initialize(hostname, credentials, timeout, namespace, metadata = {}) - @stub = V3lockpb::Lock::Stub.new(hostname, credentials) + def initialize(hostname, credentials, timeout, namespace, metadata = {}, grpc_options = {}) + @stub = V3lockpb::Lock::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @namespace = namespace @metadata = metadata diff --git a/lib/etcdv3/namespace/watch.rb b/lib/etcdv3/namespace/watch.rb index 199a348..3d74ec7 100644 --- a/lib/etcdv3/namespace/watch.rb +++ b/lib/etcdv3/namespace/watch.rb @@ -3,8 +3,8 @@ class Watch include GRPC::Core::TimeConsts include Etcdv3::Namespace::Utilities - def initialize(hostname, credentials, timeout, namespace, metadata = {}) - @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials) + def initialize(hostname, credentials, timeout, namespace, metadata = {}, grpc_options = {}) + @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @namespace = namespace @metadata = metadata diff --git a/lib/etcdv3/watch.rb b/lib/etcdv3/watch.rb index a08691b..b215f05 100644 --- a/lib/etcdv3/watch.rb +++ b/lib/etcdv3/watch.rb @@ -2,8 +2,8 @@ class Etcdv3 class Watch include GRPC::Core::TimeConsts - def initialize(hostname, credentials, timeout, metadata = {}) - @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials) + def initialize(hostname, credentials, timeout, metadata = {}, grpc_options = {}) + @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials, **grpc_options) @timeout = timeout @metadata = metadata end