From b83c2868a477b95352edd6dc0fad59bfb3f7259c Mon Sep 17 00:00:00 2001 From: Sean Porter Date: Thu, 11 Jun 2015 11:50:22 -0700 Subject: [PATCH 1/4] [E2BIG] use a tempfile for the loaded config file list instead of an environment variable --- lib/sensu/settings/loader.rb | 22 ++++++++++++++++++++-- spec/loader_spec.rb | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/sensu/settings/loader.rb b/lib/sensu/settings/loader.rb index 1460e55..97cc3fb 100644 --- a/lib/sensu/settings/loader.rb +++ b/lib/sensu/settings/loader.rb @@ -1,5 +1,6 @@ require "sensu/settings/validator" require "multi_json" +require "tempfile" module Sensu module Settings @@ -135,10 +136,27 @@ def load_directory(directory) end end + # Create a temporary file containing a 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, + # containing a colon delimited list of loaded configuration + # files (using `create_loaded_tempfile!()`. The environment + # variable `SENSU_CONFIG_FILES` is also set to a colon delimited + # list of loaded files, however, this variable is DEPRECATED due + # to ARG_MAX (E2BIG). def set_env! + ENV["SENSU_LOADED_TEMPFILE"] = create_loaded_tempfile! + # SENSU_CONFIG_FILES is DEPRECATED! ENV["SENSU_CONFIG_FILES"] = @loaded_files.join(":") end diff --git a/spec/loader_spec.rb b/spec/loader_spec.rb index e75b907..c25fb23 100644 --- a/spec/loader_spec.rb +++ b/spec/loader_spec.rb @@ -130,6 +130,9 @@ @loader.load_directory(@config_dir) expect(@loader.loaded_files.size).to eq(3) @loader.set_env! + 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) expect(ENV["SENSU_CONFIG_FILES"].split(":")).to eq(@loader.loaded_files) end From 71af7df8171180db2213cc2ebe3f591378bbe75f Mon Sep 17 00:00:00 2001 From: Sean Porter Date: Thu, 11 Jun 2015 22:11:37 -0700 Subject: [PATCH 2/4] [E2BIG] removed SENSU_CONFIG_FILES, Sensu package includes sensu-plugin --- lib/sensu/settings/loader.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/sensu/settings/loader.rb b/lib/sensu/settings/loader.rb index 97cc3fb..c097cd9 100644 --- a/lib/sensu/settings/loader.rb +++ b/lib/sensu/settings/loader.rb @@ -136,7 +136,7 @@ def load_directory(directory) end end - # Create a temporary file containing a colon delimited list of + # Create a temporary file containing the colon delimited list of # loaded configuration files. # # @return [String] tempfile path. @@ -148,16 +148,14 @@ def create_loaded_tempfile! end # Set Sensu settings related environment variables. This method - # sets `SENSU_LOADED_TEMPFILE` to a new temporary file, - # containing a colon delimited list of loaded configuration - # files (using `create_loaded_tempfile!()`. The environment - # variable `SENSU_CONFIG_FILES` is also set to a colon delimited - # list of loaded files, however, this variable is DEPRECATED due - # to ARG_MAX (E2BIG). + # 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 ARG_MAX (E2BIG) error when many configuration + # files. def set_env! ENV["SENSU_LOADED_TEMPFILE"] = create_loaded_tempfile! - # SENSU_CONFIG_FILES is DEPRECATED! - ENV["SENSU_CONFIG_FILES"] = @loaded_files.join(":") end # Validate the loaded settings. From c973050cab5e9232eb2147b2da6fd1f94947ba8c Mon Sep 17 00:00:00 2001 From: Sean Porter Date: Thu, 11 Jun 2015 22:23:20 -0700 Subject: [PATCH 3/4] [E2BIG] improved yardoc --- lib/sensu/settings/loader.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sensu/settings/loader.rb b/lib/sensu/settings/loader.rb index c097cd9..753b689 100644 --- a/lib/sensu/settings/loader.rb +++ b/lib/sensu/settings/loader.rb @@ -152,8 +152,8 @@ def create_loaded_tempfile! # 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 ARG_MAX (E2BIG) error when many configuration - # files. + # due to the exec ARG_MAX (E2BIG) error when spawning processes + # after loading many configuration files (e.g. > 2000). def set_env! ENV["SENSU_LOADED_TEMPFILE"] = create_loaded_tempfile! end From 5473f45f0277c854dbe50c014c63bb3961be44bc Mon Sep 17 00:00:00 2001 From: Sean Porter Date: Thu, 11 Jun 2015 22:31:20 -0700 Subject: [PATCH 4/4] [E2BIG] removed SENSU_CONFIG_FILES from specs --- spec/loader_spec.rb | 1 - spec/settings_spec.rb | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/loader_spec.rb b/spec/loader_spec.rb index c25fb23..967859d 100644 --- a/spec/loader_spec.rb +++ b/spec/loader_spec.rb @@ -133,7 +133,6 @@ 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) - expect(ENV["SENSU_CONFIG_FILES"].split(":")).to eq(@loader.loaded_files) end it "can load settings and determine if certain definitions exist" do diff --git a/spec/settings_spec.rb b/spec/settings_spec.rb index 45aae66..7072f09 100644 --- a/spec/settings_spec.rb +++ b/spec/settings_spec.rb @@ -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