Skip to content

Commit

Permalink
Add host_role config option (#990)
Browse files Browse the repository at this point in the history
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 appsignal/appsignal-agent#1020
  • Loading branch information
tombruijn authored Aug 25, 2023
1 parent 4722292 commit d782f9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changesets/add-role-config-option.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions lib/appsignal/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(",")
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 @@ -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")
Expand All @@ -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"
Expand Down

0 comments on commit d782f9a

Please sign in to comment.