Skip to content

Commit

Permalink
The plugin is always enabled now
Browse files Browse the repository at this point in the history
Since PR #20, this plugin is always enabled and we default to assuming
stats is listening on 127.0.0.1. That makes the else branch of this
method dead code.
  • Loading branch information
yob committed Jan 5, 2021
1 parent c10b41e commit a5aa9e2
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions lib/puma/plugin/statsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ def initialize
@port = ENV.fetch("STATSD_PORT", 8125)
end

def enabled?
!!host
end

def send(metric_name:, value:, type:, tags: nil)
data = "#{metric_name}:#{value}|#{STATSD_TYPES.fetch(type)}"
data = "#{data}|##{tags}" unless tags.nil?
Expand Down Expand Up @@ -88,19 +84,15 @@ def start(launcher)
@launcher = launcher

@statsd = ::StatsdConnector.new
if @statsd.enabled?
@launcher.events.debug "statsd: enabled (host: #{@statsd.host})"

# Fetch global metric prefix from env variable
@metric_prefix = ENV.fetch("STATSD_METRIC_PREFIX", nil)
if @metric_prefix && !@metric_prefix.end_with?(::StatsdConnector::METRIC_DELIMETER)
@metric_prefix += ::StatsdConnector::METRIC_DELIMETER
end
@launcher.events.debug "statsd: enabled (host: #{@statsd.host})"

register_hooks
else
@launcher.events.debug "statsd: not enabled (no #{StatsdConnector::ENV_NAME} env var found)"
# Fetch global metric prefix from env variable
@metric_prefix = ENV.fetch("STATSD_METRIC_PREFIX", nil)
if @metric_prefix && !@metric_prefix.end_with?(::StatsdConnector::METRIC_DELIMETER)
@metric_prefix += ::StatsdConnector::METRIC_DELIMETER
end

register_hooks
end

private
Expand Down

0 comments on commit a5aa9e2

Please sign in to comment.