flipp-oss / deimos

Framework to work with Kafka, Avro and ActiveRecord
Other
59 stars 22 forks source link

Fix metrics and tracing defaults #141

Closed iMacTia closed 2 years ago

iMacTia commented 2 years ago

Description

This PR fixes an issue where the initialization of the 2 mock providers would cause unwanted logs to be sent to STDOUT. This is because the default values for metrics and tracer currently call the #initialize method in both Metrics::Mock and Tracing::Mock while the Deimos class is loaded.

There's currently no way to avoid that, including specifying a custom value for these settings.

This PR also includes a new bin/console script which allows developers to load up an IRB console with the local deimos gem loaded. This is a pretty common script (it's autogenerated in new gems nowadays), useful for testing uncommitted changes. It's been added in this PR because it makes it really easy to see the problem.

Type of change

How Has This Been Tested?

Since this issue happens when the Deimos is first loaded, it wasn't possible to write an RSpec test for this change. Instead, the new bin/console makes demonstrating this issue very easy.

If you checkout this PR, revert lib/deimos/configuration.rb to it's previous state, and then run bin/console, you'll see the following:

❯ bin/console              
I, [2022-03-14T14:53:32.827703 #39523]  INFO -- : MockMetricsProvider initialized
I, [2022-03-14T14:53:32.827748 #39523]  INFO -- : MockTracingProvider initialized
2.6.8 :001 > 

As you can see, the two mock providers log to STDOUT as a result of require 'deimos'. This happens even if you call Deimos.configure and pass a custom value for metrics and tracer.

If you now apply the changes to lib/deimos/configuration.rb included in this PR and run bin/console again, that won't happen anymore:

❯ bin/console
2.6.8 :001 >

Checklist:

dorner commented 2 years ago

LOL I've seen this for years and just never cared enough to fix it. Thanks for all your help improving Deimos!

iMacTia commented 2 years ago

Thank you @dorner as usual for the super-quick turnaround πŸ™! I'm currently working on a project with Deimos at my place and really happy to contribute back anytime I find something that might be improved πŸ‘.

I see you're prepping a 1.12.6 release, that would be really great πŸ™Œ !

iMacTia commented 2 years ago

And it's already out! Thank you a lot πŸ™‡ !