mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-22 00:26:29 +00:00
Filter AddonConfigurationError from sentry (#1912)
This commit is contained in:
parent
c9585033cb
commit
84755836c9
@ -43,6 +43,7 @@ from ..coresys import CoreSys
|
|||||||
from ..docker.addon import DockerAddon
|
from ..docker.addon import DockerAddon
|
||||||
from ..docker.stats import DockerStats
|
from ..docker.stats import DockerStats
|
||||||
from ..exceptions import (
|
from ..exceptions import (
|
||||||
|
AddonConfigurationError,
|
||||||
AddonsError,
|
AddonsError,
|
||||||
AddonsNotSupportedError,
|
AddonsNotSupportedError,
|
||||||
DockerAPIError,
|
DockerAPIError,
|
||||||
@ -375,7 +376,7 @@ class Addon(AddonModel):
|
|||||||
_LOGGER.debug("Add-on %s write options: %s", self.slug, options)
|
_LOGGER.debug("Add-on %s write options: %s", self.slug, options)
|
||||||
return
|
return
|
||||||
|
|
||||||
raise AddonsError()
|
raise AddonConfigurationError()
|
||||||
|
|
||||||
async def remove_data(self) -> None:
|
async def remove_data(self) -> None:
|
||||||
"""Remove add-on data."""
|
"""Remove add-on data."""
|
||||||
|
@ -282,8 +282,8 @@ def supervisor_debugger(coresys: CoreSys) -> None:
|
|||||||
def setup_diagnostics(coresys: CoreSys) -> None:
|
def setup_diagnostics(coresys: CoreSys) -> None:
|
||||||
"""Sentry diagnostic backend."""
|
"""Sentry diagnostic backend."""
|
||||||
|
|
||||||
def filter_event(event, _hint):
|
def filter_event(event, hint):
|
||||||
return filter_data(coresys, event)
|
return filter_data(coresys, event, hint)
|
||||||
|
|
||||||
# Set log level
|
# Set log level
|
||||||
sentry_logging = LoggingIntegration(
|
sentry_logging = LoggingIntegration(
|
||||||
|
@ -105,6 +105,10 @@ class AddonsError(HassioError):
|
|||||||
"""Addons exception."""
|
"""Addons exception."""
|
||||||
|
|
||||||
|
|
||||||
|
class AddonConfigurationError(AddonsError):
|
||||||
|
"""Error with add-on configuration."""
|
||||||
|
|
||||||
|
|
||||||
class AddonsNotSupportedError(HassioNotSupportedError):
|
class AddonsNotSupportedError(HassioNotSupportedError):
|
||||||
"""Addons don't support a function."""
|
"""Addons don't support a function."""
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from aiohttp import hdrs
|
|||||||
|
|
||||||
from ..const import ENV_SUPERVISOR_DEV, HEADER_TOKEN_OLD, CoreStates
|
from ..const import ENV_SUPERVISOR_DEV, HEADER_TOKEN_OLD, CoreStates
|
||||||
from ..coresys import CoreSys
|
from ..coresys import CoreSys
|
||||||
|
from ..exceptions import AddonConfigurationError
|
||||||
|
|
||||||
RE_URL: re.Pattern = re.compile(r"(\w+:\/\/)(.*\.\w+)(.*)")
|
RE_URL: re.Pattern = re.compile(r"(\w+:\/\/)(.*\.\w+)(.*)")
|
||||||
|
|
||||||
@ -19,10 +20,16 @@ def sanitize_url(url: str) -> str:
|
|||||||
return re.sub(RE_URL, r"\1example.com\3", url)
|
return re.sub(RE_URL, r"\1example.com\3", url)
|
||||||
|
|
||||||
|
|
||||||
def filter_data(coresys: CoreSys, event: dict) -> dict:
|
def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict:
|
||||||
"""Filter event data before sending to sentry."""
|
"""Filter event data before sending to sentry."""
|
||||||
dev_env: bool = bool(os.environ.get(ENV_SUPERVISOR_DEV, 0))
|
dev_env: bool = bool(os.environ.get(ENV_SUPERVISOR_DEV, 0))
|
||||||
|
|
||||||
|
# Ignore some exceptions
|
||||||
|
if "exc_info" in hint:
|
||||||
|
_, exc_value, _ = hint["exc_info"]
|
||||||
|
if isinstance(exc_value, (AddonConfigurationError)):
|
||||||
|
return None
|
||||||
|
|
||||||
# Ignore issue if system is not supported or diagnostics is disabled
|
# Ignore issue if system is not supported or diagnostics is disabled
|
||||||
if not coresys.config.diagnostics or not coresys.supported or dev_env:
|
if not coresys.config.diagnostics or not coresys.supported or dev_env:
|
||||||
return None
|
return None
|
||||||
@ -48,6 +55,7 @@ def filter_data(coresys: CoreSys, event: dict) -> dict:
|
|||||||
"dns": coresys.plugins.dns.version,
|
"dns": coresys.plugins.dns.version,
|
||||||
"multicast": coresys.plugins.multicast.version,
|
"multicast": coresys.plugins.multicast.version,
|
||||||
"cli": coresys.plugins.cli.version,
|
"cli": coresys.plugins.cli.version,
|
||||||
|
"disk_free_space": coresys.host.info.free_space,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -78,5 +86,4 @@ def filter_data(coresys: CoreSys, event: dict) -> dict:
|
|||||||
|
|
||||||
if key in [hdrs.HOST, hdrs.X_FORWARDED_HOST]:
|
if key in [hdrs.HOST, hdrs.X_FORWARDED_HOST]:
|
||||||
event["request"]["headers"][i] = [key, "example.com"]
|
event["request"]["headers"][i] = [key, "example.com"]
|
||||||
print(event)
|
|
||||||
return event
|
return event
|
||||||
|
@ -2,23 +2,30 @@
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from supervisor.const import CoreStates
|
from supervisor.const import CoreStates
|
||||||
|
from supervisor.exceptions import AddonConfigurationError
|
||||||
from supervisor.misc.filter import filter_data
|
from supervisor.misc.filter import filter_data
|
||||||
|
|
||||||
SAMPLE_EVENT = {"sample": "event"}
|
SAMPLE_EVENT = {"sample": "event"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_ignored_exception(coresys):
|
||||||
|
"""Test ignored exceptions."""
|
||||||
|
hint = {"exc_info": (None, AddonConfigurationError(), None)}
|
||||||
|
assert filter_data(coresys, SAMPLE_EVENT, hint) is None
|
||||||
|
|
||||||
|
|
||||||
def test_diagnostics_disabled(coresys):
|
def test_diagnostics_disabled(coresys):
|
||||||
"""Test if diagnostics is disabled."""
|
"""Test if diagnostics is disabled."""
|
||||||
coresys.config.diagnostics = False
|
coresys.config.diagnostics = False
|
||||||
coresys.supported = True
|
coresys.supported = True
|
||||||
assert filter_data(coresys, SAMPLE_EVENT) is None
|
assert filter_data(coresys, SAMPLE_EVENT, {}) is None
|
||||||
|
|
||||||
|
|
||||||
def test_not_supported(coresys):
|
def test_not_supported(coresys):
|
||||||
"""Test if not supported."""
|
"""Test if not supported."""
|
||||||
coresys.config.diagnostics = True
|
coresys.config.diagnostics = True
|
||||||
coresys.supported = False
|
coresys.supported = False
|
||||||
assert filter_data(coresys, SAMPLE_EVENT) is None
|
assert filter_data(coresys, SAMPLE_EVENT, {}) is None
|
||||||
|
|
||||||
|
|
||||||
def test_is_dev(coresys):
|
def test_is_dev(coresys):
|
||||||
@ -26,7 +33,7 @@ def test_is_dev(coresys):
|
|||||||
coresys.config.diagnostics = True
|
coresys.config.diagnostics = True
|
||||||
coresys.supported = True
|
coresys.supported = True
|
||||||
with patch("os.environ", return_value=[("ENV_SUPERVISOR_DEV", "1")]):
|
with patch("os.environ", return_value=[("ENV_SUPERVISOR_DEV", "1")]):
|
||||||
assert filter_data(coresys, SAMPLE_EVENT) is None
|
assert filter_data(coresys, SAMPLE_EVENT, {}) is None
|
||||||
|
|
||||||
|
|
||||||
def test_not_started(coresys):
|
def test_not_started(coresys):
|
||||||
@ -35,10 +42,10 @@ def test_not_started(coresys):
|
|||||||
coresys.supported = True
|
coresys.supported = True
|
||||||
|
|
||||||
coresys.core.state = CoreStates.INITIALIZE
|
coresys.core.state = CoreStates.INITIALIZE
|
||||||
assert filter_data(coresys, SAMPLE_EVENT) == SAMPLE_EVENT
|
assert filter_data(coresys, SAMPLE_EVENT, {}) == SAMPLE_EVENT
|
||||||
|
|
||||||
coresys.core.state = CoreStates.SETUP
|
coresys.core.state = CoreStates.SETUP
|
||||||
assert filter_data(coresys, SAMPLE_EVENT) == SAMPLE_EVENT
|
assert filter_data(coresys, SAMPLE_EVENT, {}) == SAMPLE_EVENT
|
||||||
|
|
||||||
|
|
||||||
def test_defaults(coresys):
|
def test_defaults(coresys):
|
||||||
@ -47,7 +54,8 @@ def test_defaults(coresys):
|
|||||||
coresys.supported = True
|
coresys.supported = True
|
||||||
|
|
||||||
coresys.core.state = CoreStates.RUNNING
|
coresys.core.state = CoreStates.RUNNING
|
||||||
filtered = filter_data(coresys, SAMPLE_EVENT)
|
with patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0 ** 3))):
|
||||||
|
filtered = filter_data(coresys, SAMPLE_EVENT, {})
|
||||||
|
|
||||||
assert ["installation_type", "supervised"] in filtered["tags"]
|
assert ["installation_type", "supervised"] in filtered["tags"]
|
||||||
assert filtered["extra"]["supervisor"]["arch"] == "amd64"
|
assert filtered["extra"]["supervisor"]["arch"] == "amd64"
|
||||||
@ -71,7 +79,8 @@ def test_sanitize(coresys):
|
|||||||
coresys.supported = True
|
coresys.supported = True
|
||||||
|
|
||||||
coresys.core.state = CoreStates.RUNNING
|
coresys.core.state = CoreStates.RUNNING
|
||||||
filtered = filter_data(coresys, event)
|
with patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0 ** 3))):
|
||||||
|
filtered = filter_data(coresys, event, {})
|
||||||
|
|
||||||
assert ["url", "https://example.com"] in filtered["tags"]
|
assert ["url", "https://example.com"] in filtered["tags"]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user