Skip to content

Commit

Permalink
Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
fbogsany committed Sep 8, 2020
1 parent 702357f commit a06c496
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class Exporter # rubocop:disable Metrics/ClassLength
RETRY_COUNT = 5
private_constant(:KEEP_ALIVE_TIMEOUT, :OPEN_TIMEOUT, :READ_TIMEOUT, :RETRY_COUNT)

def initialize(endpoint: config_opt('OTEL_EXPORTER_OTLP_SPAN_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'localhost:55681/v1/trace'), # rubocop:disable Metrics/AbcSize
def initialize(endpoint: config_opt('OTEL_EXPORTER_OTLP_SPAN_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'localhost:55681/v1/trace'), # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
insecure: config_opt('OTEL_EXPORTER_OTLP_SPAN_INSECURE', 'OTEL_EXPORTER_OTLP_INSECURE', default: false),
certificate_file: config_opt('OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'),
headers: config_opt('OTEL_EXPORTER_OTLP_SPAN_HEADERS', 'OTEL_EXPORTER_OTLP_HEADERS'), # TODO: what format is expected here?
compression: config_opt('OTEL_EXPORTER_OTLP_SPAN_COMPRESSION', 'OTEL_EXPORTER_OTLP_COMPRESSION'),
timeout: config_opt('OTEL_EXPORTER_OTLP_SPAN_TIMEOUT', 'OTEL_EXPORTER_OTLP_TIMEOUT', default: 10))
raise ArgumentError, "invalid url for OTLP::Exporter #{endpoint}" if invalid_url?("http://#{endpoint}")
raise ArgumentError, "unsupported compression key #{compression}" unless compression.nil?
raise ArgumentError, "headers must be comma-separated k:v pairs or a Hash" unless valid_headers?(headers)
raise ArgumentError, 'headers must be comma-separated k:v pairs or a Hash' unless valid_headers?(headers)

uri = URI "http://#{endpoint}"
@http = Net::HTTP.new(uri.host, uri.port)
Expand All @@ -49,9 +49,8 @@ def initialize(endpoint: config_opt('OTEL_EXPORTER_OTLP_SPAN_ENDPOINT', 'OTEL_EX

@path = uri.path
@headers = case headers
when String then CSV.parse(headers, :col_sep => ':', :row_sep => ',').to_h
when String then CSV.parse(headers, col_sep: ':', row_sep: ',').to_h
when Hash then headers
else nil
end
@timeout = timeout.to_f # TODO: use this as a default timeout when we implement timeouts in https://github.com/open-telemetry/opentelemetry-ruby/pull/341
@tracer = OpenTelemetry.tracer_provider.tracer
Expand Down Expand Up @@ -93,9 +92,9 @@ def valid_headers?(headers)
return true if headers.nil? || headers.is_a?(Hash)
return false unless headers.is_a?(String)

CSV.parse(headers, :col_sep => ':', :row_sep => ',').to_h
CSV.parse(headers, col_sep: ':', row_sep: ',').to_h
true
rescue
rescue ArgumentError
false
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
_(http.ca_file).must_be_nil
_(http.use_ssl?).must_equal true
_(http.address).must_equal 'localhost'
_(http.port).must_equal 55681
_(http.port).must_equal 55_681
end

it 'refuses invalid headers' do
Expand Down Expand Up @@ -49,7 +49,7 @@
'OTEL_EXPORTER_OTLP_TIMEOUT' => '11') do
OpenTelemetry::Exporter::OTLP::Exporter.new
end
_(exp.instance_variable_get(:@headers)).must_equal({ 'a' => 'b', 'c' => 'd' })
_(exp.instance_variable_get(:@headers)).must_equal('a' => 'b', 'c' => 'd')
_(exp.instance_variable_get(:@timeout)).must_equal 11.0
_(exp.instance_variable_get(:@path)).must_equal '/v2/trace'
http = exp.instance_variable_get(:@http)
Expand All @@ -71,7 +71,7 @@
headers: { 'x' => 'y' },
timeout: 12)
end
_(exp.instance_variable_get(:@headers)).must_equal({ 'x' => 'y' })
_(exp.instance_variable_get(:@headers)).must_equal('x' => 'y')
_(exp.instance_variable_get(:@timeout)).must_equal 12.0
_(exp.instance_variable_get(:@path)).must_equal '/v3/trace'
http = exp.instance_variable_get(:@http)
Expand Down

0 comments on commit a06c496

Please sign in to comment.