From 31b5794fbee74fdacab2603fd87afbb749a7ba65 Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Mon, 21 Aug 2023 14:38:41 +0200 Subject: [PATCH] Add host_role config option Allow users to configure a role for a host. It's not used a lot in the product yet, but we generate a metric for it and we can do some more stuff with it in the future. Part of https://github.com/appsignal/appsignal-agent/issues/1020 --- .changesets/add-role-config-option.md | 6 ++++++ lib/appsignal/config.rb | 3 +++ spec/lib/appsignal/config_spec.rb | 12 ++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 .changesets/add-role-config-option.md diff --git a/.changesets/add-role-config-option.md b/.changesets/add-role-config-option.md new file mode 100644 index 000000000..dbb6b1137 --- /dev/null +++ b/.changesets/add-role-config-option.md @@ -0,0 +1,6 @@ +--- +bump: "patch" +type: "add" +--- + +Add the `host_role` config option. This config option can be set per host to generate some metrics automatically per host and possibly do things like grouping in the future. diff --git a/lib/appsignal/config.rb b/lib/appsignal/config.rb index 213871f28..615502c5c 100644 --- a/lib/appsignal/config.rb +++ b/lib/appsignal/config.rb @@ -83,6 +83,7 @@ class Config "APPSIGNAL_FILTER_PARAMETERS" => :filter_parameters, "APPSIGNAL_FILTER_SESSION_DATA" => :filter_session_data, "APPSIGNAL_HOSTNAME" => :hostname, + "APPSIGNAL_HOST_ROLE" => :host_role, "APPSIGNAL_HTTP_PROXY" => :http_proxy, "APPSIGNAL_IGNORE_ACTIONS" => :ignore_actions, "APPSIGNAL_IGNORE_ERRORS" => :ignore_errors, @@ -115,6 +116,7 @@ class Config APPSIGNAL_BIND_ADDRESS APPSIGNAL_CA_FILE_PATH APPSIGNAL_HOSTNAME + APPSIGNAL_HOST_ROLE APPSIGNAL_HTTP_PROXY APPSIGNAL_LOG APPSIGNAL_LOG_LEVEL @@ -337,6 +339,7 @@ def write_to_environment # rubocop:disable Metrics/AbcSize ENV["_APPSIGNAL_FILTER_PARAMETERS"] = config_hash[:filter_parameters].join(",") ENV["_APPSIGNAL_FILTER_SESSION_DATA"] = config_hash[:filter_session_data].join(",") ENV["_APPSIGNAL_HOSTNAME"] = config_hash[:hostname].to_s + ENV["_APPSIGNAL_HOST_ROLE"] = config_hash[:host_role].to_s ENV["_APPSIGNAL_HTTP_PROXY"] = config_hash[:http_proxy] ENV["_APPSIGNAL_IGNORE_ACTIONS"] = config_hash[:ignore_actions].join(",") ENV["_APPSIGNAL_IGNORE_ERRORS"] = config_hash[:ignore_errors].join(",") diff --git a/spec/lib/appsignal/config_spec.rb b/spec/lib/appsignal/config_spec.rb index 9b0c6d73f..82e070915 100644 --- a/spec/lib/appsignal/config_spec.rb +++ b/spec/lib/appsignal/config_spec.rb @@ -641,6 +641,7 @@ expect(ENV.fetch("_APPSIGNAL_RUNNING_IN_CONTAINER", nil)).to eq "false" expect(ENV.fetch("_APPSIGNAL_ENABLE_HOST_METRICS", nil)).to eq "true" expect(ENV.fetch("_APPSIGNAL_HOSTNAME", nil)).to eq "" + expect(ENV.fetch("_APPSIGNAL_HOST_ROLE", nil)).to eq "" expect(ENV.fetch("_APPSIGNAL_PROCESS_NAME", nil)).to include "rspec" expect(ENV.fetch("_APPSIGNAL_CA_FILE_PATH", nil)) .to eq File.join(resources_dir, "cacert.pem") @@ -667,6 +668,17 @@ end end + context "with :host_role" do + before do + config[:host_role] = "host role" + config.write_to_environment + end + + it "sets the modified :host_role" do + expect(ENV.fetch("_APPSIGNAL_HOST_ROLE", nil)).to eq "host role" + end + end + context "with :working_dir_path" do before do config[:working_dir_path] = "/tmp/appsignal2"