Skip to content

Commit

Permalink
fix: tell type checkers that the config options are strings (#587)
Browse files Browse the repository at this point in the history
* Tell type checkers that the config options are strings.

* Revert accidental commit.

* Fix formatting.
  • Loading branch information
tonyandrewmeyer authored Apr 26, 2024
1 parent 84c6a40 commit f85eb70
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def __init__(self, *args):
def _on_collect_unit_status(self, event: CollectStatusEvent):
# "Pull" statuses
retention_time = self.model.config.get("metrics_retention_time", "")
if not self._is_valid_timespec(retention_time):
if not self._is_valid_timespec(cast(str, retention_time)):
event.add_status(BlockedStatus(f"Invalid time spec : {retention_time}"))

# "Push" statuses
Expand Down Expand Up @@ -300,7 +300,7 @@ def self_scraping_job(self):
def log_level(self):
"""The log level configured for the charm."""
allowed_log_levels = ["debug", "info", "warn", "error", "fatal"]
log_level = self.model.config["log_level"].lower()
log_level = cast(str, self.model.config["log_level"]).lower()

if log_level not in allowed_log_levels:
logging.warning(
Expand Down Expand Up @@ -732,11 +732,15 @@ def _generate_command(self) -> str:
if config.get("metrics_wal_compression"):
args.append("--storage.tsdb.wal-compression")

if self._is_valid_timespec(retention_time := config.get("metrics_retention_time", "")):
if self._is_valid_timespec(
retention_time := cast(str, config.get("metrics_retention_time", ""))
):
args.append(f"--storage.tsdb.retention.time={retention_time}")

try:
ratio = self._percent_string_to_ratio(config.get("maximum_retention_size", ""))
ratio = self._percent_string_to_ratio(
cast(str, config.get("maximum_retention_size", ""))
)

except ValueError as e:
logger.warning(e)
Expand Down Expand Up @@ -902,9 +906,9 @@ def _prometheus_global_config(self) -> dict:
}

if config.get("evaluation_interval") and self._is_valid_timespec(
config["evaluation_interval"]
cast(str, config["evaluation_interval"])
):
global_config["evaluation_interval"] = config["evaluation_interval"]
global_config["evaluation_interval"] = cast(str, config["evaluation_interval"])

return global_config

Expand Down

0 comments on commit f85eb70

Please sign in to comment.