Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-core
Commits
baf81135
Commit
baf81135
authored
5 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Make the CLI initialize sentry-sdk based on CLI options/envvars.
parent
7dae52dc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!114
Make the CLI initialize sentry-sdk based on CLI options/envvars.
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
swh/core/cli/__init__.py
+10
-1
10 additions, 1 deletion
swh/core/cli/__init__.py
swh/core/db/tests/test_cli.py
+1
-0
1 addition, 0 deletions
swh/core/db/tests/test_cli.py
swh/core/tests/test_cli.py
+66
-2
66 additions, 2 deletions
swh/core/tests/test_cli.py
with
78 additions
and
3 deletions
requirements.txt
+
1
−
0
View file @
baf81135
Click
Deprecated
PyYAML
sentry-sdk
This diff is collapsed.
Click to expand it.
swh/core/cli/__init__.py
+
10
−
1
View file @
baf81135
...
...
@@ -9,6 +9,7 @@ import signal
import
click
import
pkg_resources
import
sentry_sdk
import
yaml
LOG_LEVEL_NAMES
=
[
'
NOTSET
'
,
'
DEBUG
'
,
'
INFO
'
,
'
WARNING
'
,
'
ERROR
'
,
'
CRITICAL
'
]
...
...
@@ -65,13 +66,21 @@ documented at https://docs.python.org/3/library/logging.config.html.
@click.option
(
'
--log-config
'
,
default
=
None
,
type
=
click
.
File
(
'
r
'
),
help
=
"
Python yaml logging configuration file.
"
)
@click.option
(
'
--sentry-dsn
'
,
default
=
None
,
help
=
"
DSN of the Sentry instance to report to
"
)
@click.option
(
'
--sentry-debug/--no-sentry-debug
'
,
default
=
False
,
hidden
=
True
,
help
=
"
Enable debugging of sentry
"
)
@click.pass_context
def
swh
(
ctx
,
log_level
,
log_config
):
def
swh
(
ctx
,
log_level
,
log_config
,
sentry_dsn
,
sentry_debug
):
"""
Command line interface for Software Heritage.
"""
signal
.
signal
(
signal
.
SIGTERM
,
clean_exit_on_signal
)
signal
.
signal
(
signal
.
SIGINT
,
clean_exit_on_signal
)
if
sentry_dsn
:
sentry_sdk
.
init
(
dsn
=
sentry_dsn
,
debug
=
sentry_debug
)
if
log_level
is
None
and
log_config
is
None
:
log_level
=
'
INFO
'
...
...
This diff is collapsed.
Click to expand it.
swh/core/db/tests/test_cli.py
+
1
−
0
View file @
baf81135
...
...
@@ -13,6 +13,7 @@ Options:
-l, --log-level [NOTSET|DEBUG|INFO|WARNING|ERROR|CRITICAL]
Log level (defaults to INFO).
--log-config FILENAME Python yaml logging configuration file.
--sentry-dsn TEXT DSN of the Sentry instance to report to
-h, --help Show this message and exit.
Notes:
...
...
This diff is collapsed.
Click to expand it.
swh/core/tests/test_cli.py
+
66
−
2
View file @
baf81135
#
# Copyright (C) 2019 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
logging
import
textwrap
from
unittest.mock
import
patch
import
click
from
click.testing
import
CliRunner
...
...
@@ -16,6 +20,7 @@ Options:
-l, --log-level [NOTSET|DEBUG|INFO|WARNING|ERROR|CRITICAL]
Log level (defaults to INFO).
--log-config FILENAME Python yaml logging configuration file.
--sentry-dsn TEXT DSN of the Sentry instance to report to
-h, --help Show this message and exit.
Notes:
...
...
@@ -45,7 +50,9 @@ def test_command(swhmain):
click
.
echo
(
'
Hello SWH!
'
)
runner
=
CliRunner
()
result
=
runner
.
invoke
(
swhmain
,
[
'
test
'
])
with
patch
(
'
sentry_sdk.init
'
)
as
sentry_sdk_init
:
result
=
runner
.
invoke
(
swhmain
,
[
'
test
'
])
sentry_sdk_init
.
assert_not_called
()
assert
result
.
exit_code
==
0
assert
result
.
output
.
strip
()
==
'
Hello SWH!
'
...
...
@@ -90,6 +97,63 @@ def test_loglevel_debug(caplog, swhmain):
assert
result
.
output
.
strip
()
==
'''
Hello SWH!
'''
def
test_sentry
(
swhmain
):
@swhmain.command
(
name
=
'
test
'
)
@click.pass_context
def
swhtest
(
ctx
):
click
.
echo
(
'
Hello SWH!
'
)
runner
=
CliRunner
()
with
patch
(
'
sentry_sdk.init
'
)
as
sentry_sdk_init
:
result
=
runner
.
invoke
(
swhmain
,
[
'
--sentry-dsn
'
,
'
test_dsn
'
,
'
test
'
])
assert
result
.
exit_code
==
0
assert
result
.
output
.
strip
()
==
'''
Hello SWH!
'''
sentry_sdk_init
.
assert_called_once_with
(
dsn
=
'
test_dsn
'
,
debug
=
False
,
)
def
test_sentry_debug
(
swhmain
):
@swhmain.command
(
name
=
'
test
'
)
@click.pass_context
def
swhtest
(
ctx
):
click
.
echo
(
'
Hello SWH!
'
)
runner
=
CliRunner
()
with
patch
(
'
sentry_sdk.init
'
)
as
sentry_sdk_init
:
result
=
runner
.
invoke
(
swhmain
,
[
'
--sentry-dsn
'
,
'
test_dsn
'
,
'
--sentry-debug
'
,
'
test
'
])
assert
result
.
exit_code
==
0
assert
result
.
output
.
strip
()
==
'''
Hello SWH!
'''
sentry_sdk_init
.
assert_called_once_with
(
dsn
=
'
test_dsn
'
,
debug
=
True
,
)
def
test_sentry_env
(
swhmain
):
@swhmain.command
(
name
=
'
test
'
)
@click.pass_context
def
swhtest
(
ctx
):
click
.
echo
(
'
Hello SWH!
'
)
runner
=
CliRunner
()
with
patch
(
'
sentry_sdk.init
'
)
as
sentry_sdk_init
:
env
=
{
'
SWH_SENTRY_DSN
'
:
'
test_dsn
'
,
'
SWH_SENTRY_DEBUG
'
:
'
1
'
,
}
result
=
runner
.
invoke
(
swhmain
,
[
'
test
'
],
env
=
env
,
auto_envvar_prefix
=
'
SWH
'
)
assert
result
.
exit_code
==
0
assert
result
.
output
.
strip
()
==
'''
Hello SWH!
'''
sentry_sdk_init
.
assert_called_once_with
(
dsn
=
'
test_dsn
'
,
debug
=
True
,
)
@pytest.fixture
def
log_config_path
(
tmp_path
):
log_config
=
textwrap
.
dedent
(
'''
\
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment