From 49853e92a45935fd8c213f66529a42afc067e2ef Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 30 Nov 2020 11:01:10 +0100 Subject: [PATCH] Fix sentry spam (#2313) --- supervisor/bootstrap.py | 1 - supervisor/misc/filter.py | 4 ++++ tests/misc/test_filter_data.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/supervisor/bootstrap.py b/supervisor/bootstrap.py index 56676c7b2..9fbf492c2 100644 --- a/supervisor/bootstrap.py +++ b/supervisor/bootstrap.py @@ -303,7 +303,6 @@ def setup_diagnostics(coresys: CoreSys) -> None: sentry_sdk.init( dsn="https://9c6ea70f49234442b4746e447b24747e@o427061.ingest.sentry.io/5370612", before_send=lambda event, hint: filter_data(coresys, event, hint), - auto_enabling_integrations=False, integrations=[AioHttpIntegration(), sentry_logging], release=SUPERVISOR_VERSION, max_breadcrumbs=30, diff --git a/supervisor/misc/filter.py b/supervisor/misc/filter.py index 05127bcd1..10622a171 100644 --- a/supervisor/misc/filter.py +++ b/supervisor/misc/filter.py @@ -76,6 +76,10 @@ def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict: }, "resolution": { "issues": [attr.asdict(issue) for issue in coresys.resolution.issues], + "suggestions": [ + attr.asdict(suggestion) + for suggestion in coresys.resolution.suggestions + ], "unhealthy": coresys.resolution.unhealthy, }, } diff --git a/tests/misc/test_filter_data.py b/tests/misc/test_filter_data.py index 804533314..94eed42da 100644 --- a/tests/misc/test_filter_data.py +++ b/tests/misc/test_filter_data.py @@ -10,6 +10,7 @@ from supervisor.misc.filter import filter_data from supervisor.resolution.const import ( ContextType, IssueType, + SuggestionType, UnhealthyReason, UnsupportedReason, ) @@ -124,6 +125,34 @@ def test_issues_on_report(coresys): assert event["contexts"]["resolution"]["issues"][0]["context"] == ContextType.SYSTEM +def test_suggestions_on_report(coresys): + """Attach suggestion to report.""" + + coresys.resolution.create_issue( + IssueType.FATAL_ERROR, + ContextType.SYSTEM, + suggestions=[SuggestionType.EXECUTE_RELOAD], + ) + + coresys.config.diagnostics = True + coresys.core.state = CoreState.RUNNING + + with patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0 ** 3))): + event = filter_data(coresys, SAMPLE_EVENT, {}) + + assert "issues" in event["contexts"]["resolution"] + assert event["contexts"]["resolution"]["issues"][0]["type"] == IssueType.FATAL_ERROR + assert event["contexts"]["resolution"]["issues"][0]["context"] == ContextType.SYSTEM + assert ( + event["contexts"]["resolution"]["suggestions"][0]["type"] + == SuggestionType.EXECUTE_RELOAD + ) + assert ( + event["contexts"]["resolution"]["suggestions"][0]["context"] + == ContextType.SYSTEM + ) + + def test_unhealthy_on_report(coresys): """Attach unhealthy to report."""