Skip to content
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#datetime_formatter #17223

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented Mar 28, 2018

The code for Ruby's Logger#datetime_formatter is as follows:

def datetime_format
  @default_formatter.datetime_format
end

In the MulticastLogger, neither @default_formatter is set or super called to set this in the default manner, so this value is always nil when this method is called on MulticastLogger and thus returns an error.

This fixes that by setting @default_formatter to VMDBLogger::Formatter.new even though it will never be used to log anything, simply because this was what is used by default in the other loggers.

Set @formatter to nil as well as that is also what is done in ruby's source in Logger#initialize to avoid potential warnings.

Links

Steps for Testing/QA

  1. Open up a Rails console
  2. Run $azure_log.datetime_format

On master, it should blow up. With this patch, it should return nil.

The code for Ruby's `Logger#datetime_formatter` is as follows:

    def datetime_format
      @default_formatter.datetime_format
    end

In the MulticastLogger, neither `@default_formatter` is set or `super`
called to set this in the default manner, so this value is always `nil`
when this method is called on `MulticastLogger` and thus returns an
error.

This fixes that by setting `@default_formatter` to
`VMDBLogger::Formatter.new` even though it will never be used to log
anything, simply because this was what is used by default in the other
loggers.

Set `@formatter` to `nil` as well as that is also what is done in ruby's
source in `Logger#initialize` (to avoid potential warnings).
@djberg96
Copy link
Contributor

👍

@level = DEBUG
@loggers = Set.new(loggers)
@level = DEBUG
@default_formatter = VMDBLogger::Formatter.new
Copy link
Member Author

@NickLaMuro NickLaMuro Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative for this is we could call super, but incase that would break other things, we decided it would be better to start with this change for now, since it will modify less things in doing so (since less things would be called in that super call). Up for debate though.

@NickLaMuro
Copy link
Member Author

@miq-bot add_label bug

cc @bdunne @Fryguy

@miq-bot miq-bot added the bug label Mar 28, 2018
Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the less intrusive change. Where did you notice this? Is there anything we can add tests for?

@Fryguy
Copy link
Member

Fryguy commented Mar 28, 2018

I'm going to 👎 this. I feel like adding more complexity is worse, and this is the second issue like this. Instead of playing whack-a-mole with missing methods, can we get rid of MulticastLogger < Logger and just delegate all calls instead?

@NickLaMuro
Copy link
Member Author

Where did you notice this?

@djberg96 made note of it in the provider's channel, specifically here:

https://gitter.im/ManageIQ/manageiq/providers?at=5abab883f3f6d24c68c194fa

Is there anything we can add tests for?

Yes, sounds good... though, @Fryguy chimed in as I was typing here... so a difference of opinions has clearly surfaced...

@NickLaMuro
Copy link
Member Author

NickLaMuro commented Mar 28, 2018

Instead of playing whack-a-mole with missing methods, can we get rid of MulticastLogger < Logger and just delegate all calls instead?

So we (@Fryguy and myself) had a longer conversation about this in the gitter channel (shortly after the links in the description), but I think the general theme is that we probably want to move away from the MulticastLogger in it's current form.

My 2 cents: I think we should do that eventually, but I think that possibly merging and backporting this to G as a surgical fix, and making this change in prep for H makes the most sense to me (I think making a larger fix and trying to backport that is much riskier). That said, I think this plan making sense hinges on the use case that @djberg96 was having issues with that caused this PR to be open in the first place.

</2cents>

@NickLaMuro
Copy link
Member Author

@bdunne Added some specs, a lot actually.

Based the other conversations, tried to make them "integration-y", where they are testing the global constants themselves, instead of a newly created instance to make sure what is used in the app are responding as expected.

This means they might be a little more brittle, and I had to do a decent amount of jerry-rigging to make them idempotent (cross your fingers I succeeded in that...), with the goal that it will hopefully allow us to swap out the underlying implementation of the MulticastLogger in the future if we decide to go that route, but still keep these tests as a safety net.

Let me know if you think I should test anything else while I am at it, as I don't think these tests are exhaustive by any means.

cc/ @Fryguy @djberg96

@NickLaMuro NickLaMuro force-pushed the fix_datetime_format_method_for_multicast_logger branch 2 times, most recently from 26d625a to 9bee9bd Compare March 29, 2018 01:11
@NickLaMuro
Copy link
Member Author

NickLaMuro commented Mar 29, 2018

Update: Added #17227 as a POC for using ActiveSupport::Logger.broadcast instead of MulticastLogger. On the fence about it, and not sure it is a good idea, but just throwing that out there as a option for the #future™.

@bdunne
Copy link
Member

bdunne commented Mar 29, 2018

Honestly, I'm less interested in refactoring and redesigning this. I think in master we can go the path that @jrafanie prefers and just delete this code. It was originally added to bridge the gap where we need to write both to a log file (for appliances) and STDOUT (for containers). Is there any reason we still need to log to files on master?

@djberg96
Copy link
Contributor

@bdunne Does that mean you favor #17227? If not, what do you suggest?

@NickLaMuro NickLaMuro force-pushed the fix_datetime_format_method_for_multicast_logger branch from 9bee9bd to 2a30a53 Compare March 29, 2018 21:07
Adds specs for each of the global loggers around the multicast logger
based loggers.

Written in a way where we should be able to swap out what we are using
under the hood for Multicast logger, and the tests should be a litmus
test if we are doing everything correct.  Borrowed a decent number of
tests from lib/vmdb/loggers/multicast_logger_spec.rb since that has the
potential to go away, but we want to test the functionality from that
spec file on all of the existing loggers.

Hopefully most of the specs here are idempotent, but we will see.
@miq-bot
Copy link
Member

miq-bot commented Mar 29, 2018

Checked commits NickLaMuro/manageiq@26ed45e~...2a30a53 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🏆

@Fryguy
Copy link
Member

Fryguy commented Apr 2, 2018

Is there any reason we still need to log to files on master?

Because we're not going fully podified?

@Fryguy
Copy link
Member

Fryguy commented Apr 2, 2018

I favor #17227 personally.

@NickLaMuro
Copy link
Member Author

NickLaMuro commented Apr 2, 2018

I favor #17227 personally.

For master, I agree. Again, my #2cents™ above was more suggesting that this should be a backport PR (but get it into master) to then be overwritten by #17227 . For what it is worth, #17227 uses the commits in this PR as well, along with a LOT of the tests.

That said, #17228 by @djberg96 might address his concerns just fine, which his issues were the main reason I opened this up, and this might only be tangentially related (not sure myself since I am not looking at it from a usage perspective like Dan is).

@bdunne bdunne merged commit 2a30a53 into ManageIQ:master Jul 25, 2018
@agrare agrare added this to the Sprint 91 Ending Jul 30, 2018 milestone Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants