Compare commits

..

6 Commits

Author SHA1 Message Date
HoneyryderChuck
834873638d Merge branch 'iaddict-master-patch-44799' into 'master'
Fix and enhance grpc method definition

See merge request os85/httpx!277
2023-10-12 22:16:34 +00:00
HoneyryderChuck
4618845a97 fix datadog version used 2023-10-12 23:07:01 +01:00
HoneyryderChuck
5db6e28534 linting updates 2023-10-12 22:39:26 +01:00
HoneyryderChuck
fb86669872 fixing datadog integration, removing support for versions older than 1.13.0 2023-10-12 18:56:41 +01:00
Thomas Steinhausen
013f24ba80 Test camel case grpc procedure names
Show that a camel case procedure can be called with underscored name.
2023-10-11 10:54:27 +02:00
Thomas Steinhausen
96eae65da1 Fix and enhance rpc method definition
Snake case named procedures could not be called. Now two methods are defined, where one is underscore named and the second has the originla procedure name as called on the service.
2023-10-10 17:55:48 +00:00
4 changed files with 51 additions and 14 deletions

View File

@ -127,18 +127,21 @@ module Datadog::Tracing
option :split_by_domain, default: false
option :enabled do |o|
o.default { env_to_bool("DD_TRACE_HTTPX_ENABLED", true) }
o.lazy
o.type :bool
o.env "DD_TRACE_HTTPX_ENABLED"
o.default true
end
option :analytics_enabled do |o|
o.default { env_to_bool(%w[DD_TRACE_HTTPX_ANALYTICS_ENABLED DD_HTTPX_ANALYTICS_ENABLED], false) }
o.lazy
o.type :bool
o.env "DD_TRACE_HTTPX_ANALYTICS_ENABLED"
o.default false
end
option :analytics_sample_rate do |o|
o.default { env_to_float(%w[DD_TRACE_HTTPX_ANALYTICS_SAMPLE_RATE DD_HTTPX_ANALYTICS_SAMPLE_RATE], 1.0) }
o.lazy
o.type :float
o.env "DD_TRACE_HTTPX_ANALYTICS_SAMPLE_RATE"
o.default 1.0
end
if defined?(Datadog::Tracing::Contrib::SpanAttributeSchema)
@ -162,7 +165,17 @@ module Datadog::Tracing
option :distributed_tracing, default: true
option :error_handler, default: DEFAULT_ERROR_HANDLER
if DDTrace::VERSION::STRING >= "1.15.0"
option :error_handler do |o|
o.type :proc
o.default_proc(&DEFAULT_ERROR_HANDLER)
end
else
option :error_handler do |o|
o.type :proc
o.experimental_default_proc(&DEFAULT_ERROR_HANDLER)
end
end
end
end
@ -192,7 +205,7 @@ module Datadog::Tracing
class Integration
include Contrib::Integration
MINIMUM_VERSION = Gem::Version.new("0.10.2")
MINIMUM_VERSION = Gem::Version.new("1.0.1")
register_as :httpx

View File

@ -149,17 +149,29 @@ module HTTPX
deadline: @options.grpc_deadline,
}.merge(opts)
local_rpc_name = rpc_name.underscore
session_class = Class.new(self.class) do
# define rpc method with ruby style name
class_eval(<<-OUT, __FILE__, __LINE__ + 1)
def #{rpc_name}(input, **opts) # def grpc_action(input, **opts)
rpc_execute("#{rpc_name}", input, **opts) # rpc_execute("grpc_action", input, **opts)
end # end
def #{local_rpc_name}(input, **opts) # def grpc_action(input, **opts)
rpc_execute("#{local_rpc_name}", input, **opts) # rpc_execute("grpc_action", input, **opts)
end # end
OUT
# define rpc method with original name
unless local_rpc_name == rpc_name
class_eval(<<-OUT, __FILE__, __LINE__ + 1)
def #{rpc_name}(input, **opts) # def grpcAction(input, **opts)
rpc_execute("#{local_rpc_name}", input, **opts) # rpc_execute("grpc_action", input, **opts)
end # end
OUT
end
end
session_class.new(@options.merge(
grpc_rpcs: @options.grpc_rpcs.merge(
rpc_name.underscore => [rpc_name, input, output, rpc_opts]
local_rpc_name => [rpc_name, input, output, rpc_opts]
).freeze
))
end

View File

@ -102,7 +102,7 @@ class HTTPXAwsSigv4Test < Minitest::Test
private
def sigv4_session(**options)
HTTPX.plugin(:aws_sigv4).aws_sigv4_authentication(**{ service: "s3", region: "us-east-1", username: "akid",
password: "secret" }.merge(options))
HTTPX.plugin(:aws_sigv4).aws_sigv4_authentication(service: "s3", region: "us-east-1", username: "akid",
password: "secret", **options)
end
end

View File

@ -5,6 +5,18 @@ module Requests
module GRPC
include GRPCHelpers
def test_plugin_grpc_stub_rpc_defines_snake_case_methods
server_port = run_rpc(TestService)
grpc = grpc_plugin
# build service
stub = grpc.build_stub("localhost:#{server_port}")
sv = stub.rpc(:aCamelCaseRpc, EchoMsg, EchoMsg, marshal_method: :marshal, unmarshal_method: :unmarshal)
assert sv.respond_to? :a_camel_case_rpc
assert sv.respond_to? :aCamelCaseRpc
end
def test_plugin_grpc_unary_plain_bytestreams
no_marshal = proc { |x| x }