diff --git a/cloudinit/performance.py b/cloudinit/performance.py index 5ad386320250..060afed6fac9 100644 --- a/cloudinit/performance.py +++ b/cloudinit/performance.py @@ -58,12 +58,19 @@ def __exit__(self, exc_type, exc_val, exc_tb): suffix = f"took {self.delta:.3f} seconds" if "always" == self.log_mode: LOG.debug("%s %s", self.msg, suffix) - elif "threshold" == self.log_mode and self.delta > self.threshold: - LOG.debug("%s %s", self.msg, suffix) - self.output = f"{self.msg} {suffix}" - - -def timed(msg: str, /, *, threshold: float = 0.01, log_mode: str = ""): + elif "skip" == self.log_mode: + return + elif "threshold" == self.log_mode: + if self.delta > self.threshold: + LOG.debug("%s %s", self.msg, suffix) + self.output = f"{self.msg} {suffix}" + else: + raise ValueError( + f"Invalid Timed log_mode value: '{self.log_mode}'." + ) + + +def timed(msg: str, /, *, threshold: float = 0.01, log_mode: str = "threshold"): """ A decorator which measures and optionally logs context run time. diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index e323a59e2da4..d2b4f619bd45 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -483,7 +483,7 @@ def clear_cached_attrs(self, attr_defaults=()): if not attr_defaults: self._dirty_cache = False - @performance.timed("Getting metadata") + @performance.timed("Getting metadata", log_mode="always") def get_data(self) -> bool: """Datasources implement _get_data to setup metadata and userdata_raw.