Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for presence of the `STATSD_IMPLEMENTATION' env: #324

Merged
merged 1 commit into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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