-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update sentry and logging configuration
Why these changes are being introduced: Our terraform template requires that each env variable be present in all envs, even if we don't need it in a particular env (e.g. SENTRY_DSN is not needed in dev). Env variables are now given a string value of "None" in env(s) where they are not needed. In addition, while working on this a logging bug was addressed in which logging was configured on the cli module logger instead of the root logger and thus was not propagating to all modules. In resolving both issues it made sense to refactor these configuration steps into their own functions in a separate config module. How this addresses that need: * Creates a new config module with functions to configure logging and sentry, and moves that logic from the cli module to these functions. * Updates sentry configuration to check for a string value of "None" in addition to a None object value for the SENTRY_DSN env variable. * Adds unit tests for new config module and update cli tests to match new expected outputs. Additional changes: * Minor update to conftest.py configuration for all tests. * Two minor logging additions: * One to add a timer to the transform command and log the total transform time at the end of the process, useful as a benchmark for large/long transform jobs. * One to log a status update after every 1000 records transformed, useful to monitor progress during large/long transform jobs. * Update Makefile to match standard section formatting across repos. * Update Github Actions to use our shared CI workflow. * Update coverage reporting to use coverage library instead of pytest-cov to match our shared CI workflow. * Code/documentation cleanup across a few files. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/RDI-160 * https://mitlibraries.atlassian.net/browse/RDI-148
- Loading branch information
Showing
15 changed files
with
328 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: CI | ||
on: push | ||
jobs: | ||
test: | ||
uses: mitlibraries/.github/.github/workflows/python-shared-test.yml@main | ||
lint: | ||
uses: mitlibraries/.github/.github/workflows/python-shared-lint.yml@main |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
|
||
from transmogrifier.config import configure_logger, configure_sentry | ||
|
||
|
||
def test_configure_logger_not_verbose(): | ||
logger = logging.getLogger(__name__) | ||
result = configure_logger(logger, verbose=False) | ||
assert logger.getEffectiveLevel() == 20 | ||
assert result == "Logger 'test_config' configured with level=INFO" | ||
|
||
|
||
def test_configure_logger_verbose(caplog): | ||
logger = logging.getLogger(__name__) | ||
result = configure_logger(logger, verbose=True) | ||
assert logger.getEffectiveLevel() == 10 | ||
assert result == "Logger 'test_config' configured with level=DEBUG" | ||
|
||
|
||
def test_configure_sentry_no_env_variable(monkeypatch): | ||
monkeypatch.delenv("SENTRY_DSN", raising=False) | ||
result = configure_sentry() | ||
assert result == "No Sentry DSN found, exceptions will not be sent to Sentry" | ||
|
||
|
||
def test_configure_sentry_env_variable_is_none(monkeypatch): | ||
monkeypatch.setenv("SENTRY_DSN", "None") | ||
result = configure_sentry() | ||
assert result == "No Sentry DSN found, exceptions will not be sent to Sentry" | ||
|
||
|
||
def test_configure_sentry_env_variable_is_dsn(monkeypatch): | ||
monkeypatch.setenv("SENTRY_DSN", "https://1234567890@00000.ingest.sentry.io/123456") | ||
result = configure_sentry() | ||
assert result == "Sentry DSN found, exceptions will be sent to Sentry with env=test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +0,0 @@ | ||
import logging | ||
|
||
logging.basicConfig( | ||
format=( | ||
"%(asctime)s %(levelname)s %(name)s.%(funcName)s() line " | ||
"%(lineno)d: %(message)s" | ||
) | ||
) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.