Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Fix E2BIG, use tempfile instead of env var for loaded config file list #14

Merged
merged 4 commits into from
Jun 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/sensu/settings/loader.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "sensu/settings/validator"
require "multi_json"
require "tempfile"

module Sensu
module Settings
Expand Down Expand Up @@ -135,11 +136,26 @@ def load_directory(directory)
end
end

# Create a temporary file containing the colon delimited list of
# loaded configuration files.
#
# @return [String] tempfile path.
def create_loaded_tempfile!
file = Tempfile.new("sensu_loaded_files")
file.write(@loaded_files.join(":"))
file.close
file.path
end

# Set Sensu settings related environment variables. This method
# currently sets SENSU_CONFIG_FILES, a colon delimited list of
# loaded config files.
# sets `SENSU_LOADED_TEMPFILE` to a new temporary file path,
# a file containing the colon delimited list of loaded
# configuration files (using `create_loaded_tempfile!()`. The
# environment variable `SENSU_CONFIG_FILES` has been removed,
# due to the exec ARG_MAX (E2BIG) error when spawning processes
# after loading many configuration files (e.g. > 2000).
def set_env!
ENV["SENSU_CONFIG_FILES"] = @loaded_files.join(":")
ENV["SENSU_LOADED_TEMPFILE"] = create_loaded_tempfile!
end

# Validate the loaded settings.
Expand Down
4 changes: 3 additions & 1 deletion spec/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@
@loader.load_directory(@config_dir)
expect(@loader.loaded_files.size).to eq(3)
@loader.set_env!
expect(ENV["SENSU_CONFIG_FILES"].split(":")).to eq(@loader.loaded_files)
expect(ENV["SENSU_LOADED_TEMPFILE"]).to match(/sensu_loaded_files/)
loaded_files = IO.read(ENV["SENSU_LOADED_TEMPFILE"])
expect(loaded_files.split(":")).to eq(@loader.loaded_files)
end

it "can load settings and determine if certain definitions exist" do
Expand Down
4 changes: 3 additions & 1 deletion spec/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
expect(settings[:checks][:merger][:command]).to eq("echo -n merger")
expect(settings[:checks][:merger][:subscribers]).to eq(["foo", "bar"])
expect(settings[:checks][:nested][:command]).to eq("true")
expect(ENV["SENSU_CONFIG_FILES"].split(":")).to eq(settings.loaded_files)
expect(ENV["SENSU_LOADED_TEMPFILE"]).to match(/sensu_loaded_files/)
loaded_files = IO.read(ENV["SENSU_LOADED_TEMPFILE"])
expect(loaded_files.split(":")).to eq(settings.loaded_files)
ENV["RABBITMQ_URL"] = nil
end

Expand Down