Skip to content

Commit

Permalink
Minor style updates, adds Serverless in meta header
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Jul 12, 2024
1 parent 353dc70 commit 18ad5d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/elastic/transport/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Client
#
# @option arguments [Integer] :sniffer_timeout Timeout for reloading connections in seconds (1 by default)
#
# @option arguments [Boolean,Number] :retry_on_failure Retry X times when request fails before raising and
# @option arguments [Boolean,Number] :retry_on_failure Retry X times when request fails before raising an
# exception (false by default)
# @option arguments [Number] :delay_on_retry Delay in milliseconds between each retry (0 by default)
#
Expand Down Expand Up @@ -173,7 +173,7 @@ def initialize(arguments = {}, &block)
# Performs a request through delegation to {#transport}.
#
def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {})
method = @send_get_body_as if 'GET' == method && body
method = @send_get_body_as if method == 'GET' && body
validate_ca_fingerprints if @ca_fingerprint
if @otel
# If no endpoint is specified in the opts, use the HTTP method name
Expand Down
9 changes: 8 additions & 1 deletion lib/elastic/transport/meta_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def set_meta_header
def meta_header_service_version
if enterprise_search?
Elastic::ENTERPRISE_SERVICE_VERSION
elsif serverless?
Elastic::ES_SERVERLESS_SERVICE_VERSION
elsif elasticsearch?
Elastic::ELASTICSEARCH_SERVICE_VERSION
elsif defined?(Elasticsearch::VERSION)
Expand All @@ -60,6 +62,11 @@ def elasticsearch?
called_from?('elasticsearch')
end

def serverless?
defined?(ElasticsearchServerless::CLIENT_VERSION) &&
called_from?('elasticsearch-serverless')
end

def called_from?(service)
!caller.select { |c| c.match?(service) }.empty?
end
Expand All @@ -70,7 +77,7 @@ def called_from?(service)
def client_meta_version(version)
regexp = /^([0-9]+\.[0-9]+\.[0-9]+)(\.?[a-z0-9.-]+)?$/
match = version.match(regexp)
return "#{match[1]}p" if (match[2])
return "#{match[1]}p" if match[2]

version
end
Expand Down
6 changes: 3 additions & 3 deletions lib/elastic/transport/transport/serializer/multi_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Serializer
module Base
# @param transport [Object] The instance of transport which uses this serializer
#
def initialize(transport=nil)
def initialize(transport = nil)
@transport = transport
end
end
Expand All @@ -36,13 +36,13 @@ class MultiJson

# De-serialize a Hash from JSON string
#
def load(string, options={})
def load(string, options = {})
::MultiJson.load(string, options)
end

# Serialize a Hash to JSON string
#
def dump(object, options={})
def dump(object, options = {})
::MultiJson.dump(object, options)
end
end
Expand Down

0 comments on commit 18ad5d9

Please sign in to comment.