diff --git a/.changesets/statsd-port-config-option.md b/.changesets/statsd-port-config-option.md new file mode 100644 index 000000000..9694ecc08 --- /dev/null +++ b/.changesets/statsd-port-config-option.md @@ -0,0 +1,6 @@ +--- +bump: "patch" +type: "add" +--- + +Allow configuration of the agent's StatsD server port through the `statsd_port` option. diff --git a/lib/appsignal/config.rb b/lib/appsignal/config.rb index 8d91e93b8..c889b049d 100644 --- a/lib/appsignal/config.rb +++ b/lib/appsignal/config.rb @@ -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, @@ -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 @@ -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] diff --git a/lib/puma/plugin/appsignal.rb b/lib/puma/plugin/appsignal.rb index 275b057c3..8463faaff 100644 --- a/lib/puma/plugin/appsignal.rb +++ b/lib/puma/plugin/appsignal.rb @@ -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) diff --git a/spec/lib/appsignal/config_spec.rb b/spec/lib/appsignal/config_spec.rb index e8e56624b..e3f94fe08 100644 --- a/spec/lib/appsignal/config_spec.rb +++ b/spec/lib/appsignal/config_spec.rb @@ -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" @@ -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