Skip to content

Commit

Permalink
Add statsd_port config option
Browse files Browse the repository at this point in the history
Allow configuration of the agent's statsd server port through the
statsd_port option.

Configure the Puma plugin using env vars. It cannot access the normal
AppSignal config, because the gem isn't loaded in the main process.

Requires an agent update from
appsignal/appsignal-agent#995
  • Loading branch information
tombruijn committed May 30, 2023
1 parent 05dc9fe commit 8e54a89
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changesets/statsd-port-config-option.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

Allow configuration of the agent's StatsD server port through the `statsd_port` option.
3 changes: 3 additions & 0 deletions lib/appsignal/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Config
"APPSIGNAL_SEND_PARAMS" => :send_params,
"APPSIGNAL_SEND_SESSION_DATA" => :send_session_data,
"APPSIGNAL_SKIP_SESSION_DATA" => :skip_session_data,
"APPSIGNAL_STATSD_PORT" => :statsd_port,
"APPSIGNAL_TRANSACTION_DEBUG_MODE" => :transaction_debug_mode,
"APPSIGNAL_WORKING_DIRECTORY_PATH" => :working_directory_path,
"APPSIGNAL_WORKING_DIR_PATH" => :working_dir_path,
Expand All @@ -117,6 +118,7 @@ class Config
APPSIGNAL_LOGGING_ENDPOINT
APPSIGNAL_PUSH_API_ENDPOINT
APPSIGNAL_PUSH_API_KEY
APPSIGNAL_STATSD_PORT
APPSIGNAL_WORKING_DIRECTORY_PATH
APPSIGNAL_WORKING_DIR_PATH
APP_REVISION
Expand Down Expand Up @@ -343,6 +345,7 @@ def write_to_environment # rubocop:disable Metrics/AbcSize
ENV["_APPSIGNAL_PUSH_API_KEY"] = config_hash[:push_api_key]
ENV["_APPSIGNAL_RUNNING_IN_CONTAINER"] = config_hash[:running_in_container].to_s
ENV["_APPSIGNAL_SEND_ENVIRONMENT_METADATA"] = config_hash[:send_environment_metadata].to_s
ENV["_APPSIGNAL_STATSD_PORT"] = config_hash[:statsd_port].to_s
ENV["_APPSIGNAL_TRANSACTION_DEBUG_MODE"] = config_hash[:transaction_debug_mode].to_s
if config_hash[:working_directory_path]
ENV["_APPSIGNAL_WORKING_DIRECTORY_PATH"] = config_hash[:working_directory_path]
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/plugin/appsignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Statsd
def initialize
# StatsD server location as configured in AppSignal agent StatsD server.
@host = "127.0.0.1"
@port = 8125
@port = ENV.fetch("APPSIGNAL_STATSD_PORT", 8125)
end

def gauge(metric_name, value, tags)
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/appsignal/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
expect(ENV.fetch("_APPSIGNAL_FILES_WORLD_ACCESSIBLE", nil)).to eq "true"
expect(ENV.fetch("_APPSIGNAL_TRANSACTION_DEBUG_MODE", nil)).to eq "true"
expect(ENV.fetch("_APPSIGNAL_SEND_ENVIRONMENT_METADATA", nil)).to eq "false"
expect(ENV.fetch("_APPSIGNAL_STATSD_PORT", nil)).to eq ""
expect(ENV.fetch("_APPSIGNAL_FILTER_PARAMETERS", nil)).to eq "password,confirm_password"
expect(ENV.fetch("_APPSIGNAL_FILTER_SESSION_DATA", nil)).to eq "key1,key2"
expect(ENV.fetch("_APP_REVISION", nil)).to eq "v2.5.1"
Expand Down Expand Up @@ -682,6 +683,17 @@
expect(ENV.fetch("_APPSIGNAL_WORKING_DIRECTORY_PATH", nil)).to eq "/tmp/appsignal2"
end
end

context "with :statsd_port" do
before do
config[:statsd_port] = "1000"
config.write_to_environment
end

it "sets the statsd_port env var" do
expect(ENV.fetch("_APPSIGNAL_STATSD_PORT", nil)).to eq "1000"
end
end
end

describe "#log_file_path" do
Expand Down

0 comments on commit 8e54a89

Please sign in to comment.