google / slo-generator

SLO Generator computes SLIs, SLOs, Error Budgets and Burn Rates from supported backends, then exports an SLO report to supported targets.
Apache License 2.0
489 stars 78 forks source link

refactor(tests): add logging output to console and deal with DEBUG mode #358

Open sdenef-adeo opened 1 year ago

sdenef-adeo commented 1 year ago

When testing, I would like my IDE to output logs to the console. And I would like to set DEBUG mode like we do for running code.

I'm not this is the best way to do. And how to avoid duplicated code, already existing in utils.setup_logging() function. Feel free to improve my code.

lvaylet commented 1 year ago

Hi @sdenef-adeo, which IDE do you use? Using DEBUG mode should be as simple as setting the DEBUG env variable to 1. This can be done in multiple ways. For example with a .env file that is automatically picked up by the IDE or the test engine. Or by setting the env variable explicitly during tests.

sdenef-adeo commented 1 year ago

Hi @lvaylet ,

Did you try?

I use Intellij IDEA. Here are the ouputs for the same launch configuration (DEBUG=1)

Against master branch:

slo-generator_test_against_master

Against my PR branch:

slo-generator_test_against_pr-branch

AFAIU the DEBUG is never read when running tests as it does not reach utils.setup_logging() nor constants.DEBUG

lvaylet commented 1 year ago

Got it. I assumed "testing" meant "running slo-generator compute ... manually in my terminal". Not "unit testing". So yes, this does make sense.

Let me take a look and see how we can leverage the existing utils.setup_logging().

lvaylet commented 1 year ago

Is there a specific reason why you decided not to call utils.setup_logging()?

We could rewrite it so it remains compatible with the current usage (for example by adding options with default values) and let you use debug mode in unit tests at the same time.

sdenef-adeo commented 1 year ago

Is there a specific reason why you decided not to call utils.setup_logging()?

Hello,

No reason except I'm not familiar with Python logging. ;)