-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix MulticastLogger DEBUG mode #16990
Fix MulticastLogger DEBUG mode #16990
Conversation
d8f2361
to
7505e3f
Compare
lib/vmdb/loggers.rb
Outdated
@@ -130,7 +130,10 @@ def self.create_loggers | |||
private_class_method :create_loggers | |||
|
|||
def self.create_multicast_logger(log_file_path, logger_class = VMDBLogger) | |||
MulticastLogger.new(logger_class.new(log_file_path)).tap do |l| | |||
logger_instance = logger_class.new(log_file_path).tap do |logger| | |||
logger.level = MulticastLogger::DEBUG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be Logger::DEBUG
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no reason why not. I can change in the morning.
spec/lib/vmdb/loggers_spec.rb
Outdated
|
||
def in_container_env(example) | ||
old_env = ENV.delete('CONTAINER') | ||
ENV['CONTAINER'] = '1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually this is set to "true"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code has it as effectively a nil
check, but I can change it if you would prefer. I have always kept the practice when calling other toggle-able ENV
vars has been TOGGLE_SOMETHING=1
, but that is just my preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, we're really just checking to see if the ENV variable is set or unset. But to avoid confusion in case the value becomes important in the future, I'd prefer "true".
https://github.com/ManageIQ/manageiq-pods/blob/master/images/miq-app/Dockerfile#L9
@NickLaMuro Looks good to me (though I agree with bdunne's comments). 👍 |
7505e3f
to
c68b94c
Compare
spec/lib/vmdb/loggers_spec.rb
Outdated
@@ -0,0 +1,52 @@ | |||
describe Vmdb::Loggers do | |||
let(:log_file) { Rails.root.join("log", "foo.log").to_s } | |||
describe "#create_multicast_logger" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor style...please add blank lines around describes to separate them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, minor, but since this is a private method, can you clarify that in the describe line? It makes it clearer why you have to do .send below. I usually do something like describe "#create_multicast_logger (private)" do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, all for this, just assumed rubocop would have yelled at me (feel like it has in the past).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I expected rubocop to yell about it too, so I was surprised
spec/lib/vmdb/loggers_spec.rb
Outdated
end | ||
end | ||
|
||
def in_container_env(example) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this definition be inside the describe block? toplevel clearly infects the global namespace, but I think inside of a describe it will be at least isolated. @bdunne Do you remember?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try, since it isn't too much effort to do so. Wanted to make sure it was not repeated code, but yeah, I can see if tossing it in a describe isolates things. Couldn't hurt.
spec/lib/vmdb/loggers_spec.rb
Outdated
ENV['CONTAINER'] = 'true' | ||
example.run | ||
ensure | ||
# ENV['x'] = nil deletes the key because ENV accepts only string values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this comment is needed...we should always set back to the original value anyway (i.e. this code won't ever say = nil
, so no need to explain it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code won't ever say =
nil
, so no need to explain it
Not directly, but in the lines above, where we get the old_env
, more often then not, it is probably nil
.
Also, I have shamelessly ripped this off from here: d098bc0
So this is not my comment to begin with.
That said, I am fine with removing it if it is a bother, though, seeing as it is now in our codebase about 5 other times, we probably should just make it a helper at this point (not in this PR though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh..ok, this is fine then 👍
spec/lib/vmdb/loggers_spec.rb
Outdated
end | ||
|
||
context "in a container environment" do | ||
around(:each) { |example| in_container_env(example) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The :each is redundant as it's the default, so please remove (same below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no prob. Again, though, ripped off from here: d098bc0
Where around(:each)
was used.
Most of my comments are super-minor. I am concerned that we default to DEBUG in this part of the code, but the MulticastLogger defaults to DEBUG in a different part of the code. If the intention is to keep them linked, then code-wise it feels disconnected. I'm ok with merging for now, as I'm not sure how to resolve that disconnect. |
When passing the config/settings data to the `.apply_config_value` method of Vmdb::Loggers, if the value was set to `DEBUG` the level wouldn't be changed in the lower level logger to reflect that. This is because the MulticastLogger is instantiated and defaulted at DEBUG, but the logger it casts to (normally an instance of VMDBLogger) would have it's level defaulted to `info`. When `.apply_config_value` is then called, it would compare the old value to the new one, and see it as the same, even though it was different under the covers. This means when a user attempts to do a `$log.debug "my message"`, the message would then not be applied. The fix here effectively makes sure we are defaulting the lower level logger to the same log level as the parent, or the MulticastLogger. When `.apply_config_value` is then eventually called, if the setting is set to `DEBUG`, nothing will change, but the level will be set properly for the lower level logger. Anything level set higher than DEBUG will function as it has. * * * There was also some additional tests added to the new test file, `spec/lib/vmdb/loggers_spec.rb`, that covered some of the quirks of log levels in a container config. Since `$container_log` is set to use the `lib/vmdb/loggers/container_logger.rb`, this means it's `#level=` method is set to override the default and always set itself to "DEBUG". This is a bit confusing at first glace if you are trying to grok what is happening in `lib/vmdb/loggers.rb`, as it can seem like the whole thing wouldn't work as expected, and the level for the $container_log would be overwritten with each log type.
c68b94c
to
a7ed2cb
Compare
@Fryguy changes applied, minus the "comment about the comment". Left an explanation and ref about that one. Can change if you feel strongly about it. |
Checked commit NickLaMuro@a7ed2cb with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
…bug-mode-in-settings Fix MulticastLogger DEBUG mode (cherry picked from commit c6eac38) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1545292
Gaprindashvili backport details:
|
When passing the config/settings data to the
.apply_config_value
method ofVmdb::Loggers
, if the value was set toDEBUG
the level wouldn't be changed in the lower level logger to reflect that.This is because the
MulticastLogger
is instantiated and defaulted atDEBUG
, but the logger it casts to (normally an instance ofVMDBLogger
) would have it's level defaulted toinfo
. When.apply_config_value
is then called, it would compare the old value to the new one, and see it as the same, even though it was different under the covers.This means when a user attempts to do a
$log.debug "my message"
, the message would then not be applied.The fix here effectively makes sure we are defaulting the lower level logger to the same log level as the parent, or the
MulticastLogger
. When.apply_config_value
is then eventually called, if the setting is set toDEBUG
, nothing will change, but the level will be set properly for the lower level logger. Anything level set higher thanDEBUG
will function as it has.Regarding extra tests...
There was also some additional tests added to the new test file,
spec/lib/vmdb/loggers_spec.rb
, that covered some of the quirks of log levels in a container config. Since$container_log
is set to use thelib/vmdb/loggers/container_logger.rb
, this means it's#level=
method is set to override the default and always set itself to "DEBUG". This is a bit confusing at first glace if you are trying to grok what is happening inlib/vmdb/loggers.rb
, as it can seem like the whole thing wouldn't work as expected, and the level for the$container_log
would be overwritten with each log type.Links