From 18d4a91903f3eaa246e74c6b8e0ed5c835cebf01 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 13 Oct 2024 00:30:11 +1300 Subject: [PATCH] Add support for instrumentation tags. --- async-http.gemspec | 7 ++++--- lib/async/http/client.rb | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/async-http.gemspec b/async-http.gemspec index e19643e..84f6147 100644 --- a/async-http.gemspec +++ b/async-http.gemspec @@ -25,11 +25,12 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 3.1" spec.add_dependency "async", ">= 2.10.2" - spec.add_dependency "async-pool", "~> 0.7" - spec.add_dependency "io-endpoint", "~> 0.11" + spec.add_dependency "async-pool", "~> 0.9" + spec.add_dependency "io-endpoint", "~> 0.14" spec.add_dependency "io-stream", "~> 0.4" spec.add_dependency "protocol-http", "~> 0.37" spec.add_dependency "protocol-http1", "~> 0.27" spec.add_dependency "protocol-http2", "~> 0.19" - spec.add_dependency "traces", ">= 0.10" + spec.add_dependency "traces", "~> 0.10" + spec.add_dependency "metrics", "~> 0.12" end diff --git a/lib/async/http/client.rb b/lib/async/http/client.rb index d4fdfc5..c755e87 100755 --- a/lib/async/http/client.rb +++ b/lib/async/http/client.rb @@ -18,7 +18,6 @@ module Async module HTTP DEFAULT_RETRIES = 3 - DEFAULT_CONNECTION_LIMIT = nil class Client < ::Protocol::HTTP::Methods # Provides a robust interface to a server. @@ -30,12 +29,12 @@ class Client < ::Protocol::HTTP::Methods # @param protocol [Protocol::HTTP1 | Protocol::HTTP2 | Protocol::HTTPS] the protocol to use. # @param scheme [String] The default scheme to set to requests. # @param authority [String] The default authority to set to requests. - def initialize(endpoint, protocol: endpoint.protocol, scheme: endpoint.scheme, authority: endpoint.authority, retries: DEFAULT_RETRIES, connection_limit: DEFAULT_CONNECTION_LIMIT) + def initialize(endpoint, protocol: endpoint.protocol, scheme: endpoint.scheme, authority: endpoint.authority, retries: DEFAULT_RETRIES, **options) @endpoint = endpoint @protocol = protocol @retries = retries - @pool = make_pool(connection_limit) + @pool = make_pool(**options) @scheme = scheme @authority = authority @@ -191,8 +190,20 @@ def make_response(request, connection) return response end - def make_pool(connection_limit) - Async::Pool::Controller.wrap(limit: connection_limit) do + def assign_default_tags(tags) + tags[:endpoint] = @endpoint.to_s + tags[:protocol] = @protocol.to_s + end + + def make_pool(**options) + if connection_limit = options.delete(:connection_limit) + warn "The connection_limit: option is deprecated, please use limit: instead.", uplevel: 2 + options[:limit] = connection_limit + end + + self.assign_default_tags(options[:tags] ||= {}) + + Async::Pool::Controller.wrap(**options) do Console.logger.debug(self) {"Making connection to #{@endpoint.inspect}"} @protocol.client(@endpoint.connect)