Skip to content

Commit

Permalink
Ensure the STATSD_IMPLEMENTATION env is a string:
Browse files Browse the repository at this point in the history
- Calling `empty?` when ENV['STATSD_IMPLEMENTATION'] isn't set makes kubernetes-deploy to crash
  • Loading branch information
Edouard-chin committed Aug 7, 2018
1 parent 7e19140 commit ef23a5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kubernetes-deploy/statsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.build
if ENV['STATSD_DEV'].present?
::StatsD.backend = ::StatsD::Instrument::Backends::LoggerBackend.new(Logger.new($stderr))
elsif ENV['STATSD_ADDR'].present?
statsd_impl = ENV['STATSD_IMPLEMENTATION'].empty? ? "datadog" : ENV['STATSD_IMPLEMENTATION']
statsd_impl = ENV['STATSD_IMPLEMENTATION'].present? ? ENV['STATSD_IMPLEMENTATION'] : "datadog"
::StatsD.backend = ::StatsD::Instrument::Backends::UDPBackend.new(ENV['STATSD_ADDR'], statsd_impl)
else
::StatsD.backend = ::StatsD::Instrument::Backends::NullBackend.new
Expand Down
22 changes: 22 additions & 0 deletions test/unit/kubernetes-deploy/statsd_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'test_helper'

class StatsDTest < KubernetesDeploy::TestCase
def test_build_when_statsd_addr_env_present_but_statsd_implementation_is_not
original_addr, = ENV['STATSD_ADDR']
ENV['STATSD_ADDR'] = '127.0.0.1'
original_impl = ENV['STATSD_IMPLEMENTATION']
ENV['STATSD_IMPLEMENTATION'] = nil
original_dev = ENV['STATSD_DEV']
ENV['STATSD_DEV'] = nil

KubernetesDeploy::StatsD.build

assert_equal :datadog, StatsD.backend.implementation
ensure
ENV['STATSD_ADDR'] = original_addr
ENV['STATSD_IMPLEMENTATION'] = original_impl
ENV['STATSD_DEV'] = original_dev
end
end

0 comments on commit ef23a5d

Please sign in to comment.