Skip to content

Commit

Permalink
Don't emit a bunch of warning logs during normal operation (#273)
Browse files Browse the repository at this point in the history
* Don't emit a bunch of warning logs during normal operation

* Don't unit test to ensure we keep scary logs either

* Unit test adjustment
  • Loading branch information
rbarry82 authored May 20, 2022
1 parent 95116e6 commit 155f990
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/charms/prometheus_k8s/v0/prometheus_remote_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def add_path(self, path: str, *, recursive: bool = False) -> None:
elif path.is_file():
self.alert_groups.extend(self._from_file(path.parent, path))
else:
logger.warning("path does not exist: %s", path)
logger.debug("Alert rules path does not exist: %s", path)

def as_dict(self) -> dict:
"""Return standard alert rules file in dict representation.
Expand Down Expand Up @@ -1052,7 +1052,7 @@ def alerts(self) -> dict:
continue

if "groups" not in alert_rules:
logger.warning("No alert groups were found in relation data")
logger.debug("No alert groups were found in relation data")
continue
# Construct an ID based on what's in the alert rules
for group in alert_rules["groups"]:
Expand Down
8 changes: 4 additions & 4 deletions lib/charms/prometheus_k8s/v0/prometheus_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ def add_path(self, path: str, *, recursive: bool = False) -> None:
elif path.is_file():
self.alert_groups.extend(self._from_file(path.parent, path))
else:
logger.warning("path does not exist: %s", path)
logger.debug("Alert rules path does not exist: %s", path)

def as_dict(self) -> dict:
"""Return standard alert rules file in dict representation.
Expand Down Expand Up @@ -1130,7 +1130,7 @@ def _get_identifier_by_alert_rules(self, rules: dict) -> Union[str, None]:
rules: a dict of alert rules
"""
if "groups" not in rules:
logger.warning("No alert groups were found in relation data")
logger.debug("No alert groups were found in relation data")
return None

# Construct an ID based on what's in the alert rules if they have labels
Expand Down Expand Up @@ -1543,7 +1543,7 @@ def __init__(
try:
alert_rules_path = _resolve_dir_against_charm_path(charm, alert_rules_path)
except InvalidAlertRulePathError as e:
logger.warning(
logger.debug(
"Invalid Prometheus alert rules folder at %s: %s",
e.alert_rules_absolute_path,
e.message,
Expand Down Expand Up @@ -1705,7 +1705,7 @@ def __init__(
try:
dir_path = _resolve_dir_against_charm_path(charm, dir_path)
except InvalidAlertRulePathError as e:
logger.warning(
logger.debug(
"Invalid Prometheus alert rules folder at %s: %s",
e.alert_rules_absolute_path,
e.message,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_endpoint_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ def test_consumer_logs_an_error_on_missing_alerting_data(self):
with self.assertLogs(level="WARNING") as logger:
_ = self.harness.charm.prometheus_consumer.alerts()
messages = logger.output
self.assertEqual(len(messages), 2)
self.assertEqual(len(messages), 1)
self.assertIn(
"Alert rules were found but no usable group or identifier was present", messages[1]
"Alert rules were found but no usable group or identifier was present", messages[0]
)

def test_consumer_accepts_rules_with_no_identifier(self):
Expand Down

0 comments on commit 155f990

Please sign in to comment.