diff options
| author | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-04-10 17:21:26 +0300 |
|---|---|---|
| committer | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-04-10 17:21:26 +0300 |
| commit | 43618112e45953528cde593275f755881f852d67 (patch) | |
| tree | d594f2a3264e5beafa6e5910e83a74f02e83af03 /robusta_krr/utils | |
| parent | 144aea2ef44271f3cfc773bd3ddfe872c617160e (diff) | |
Lower the required python version to 3.9, improve verbose logs
Diffstat (limited to 'robusta_krr/utils')
| -rw-r--r-- | robusta_krr/utils/configurable.py | 10 | ||||
| -rw-r--r-- | robusta_krr/utils/resource_units.py | 3 | ||||
| -rw-r--r-- | robusta_krr/utils/service_discovery.py | 5 |
3 files changed, 14 insertions, 4 deletions
diff --git a/robusta_krr/utils/configurable.py b/robusta_krr/utils/configurable.py index d2f1442..3957e6e 100644 --- a/robusta_krr/utils/configurable.py +++ b/robusta_krr/utils/configurable.py @@ -1,4 +1,5 @@ import abc +from inspect import getframeinfo, stack from typing import Literal from rich.console import Console @@ -51,7 +52,14 @@ class Configurable(abc.ABC): """ if self.debug_active: - self.console.print(self.__add_prefix(message, "[bold green][DEBUG][/bold green]", no_prefix=False)) + caller = getframeinfo(stack()[1][0]) + self.console.print( + self.__add_prefix( + message + f"\t\t({caller.filename}:{caller.lineno})", + "[bold green][DEBUG][/bold green]", + no_prefix=False, + ) + ) def debug_exception(self) -> None: """ diff --git a/robusta_krr/utils/resource_units.py b/robusta_krr/utils/resource_units.py index 37a3646..d80ac05 100644 --- a/robusta_krr/utils/resource_units.py +++ b/robusta_krr/utils/resource_units.py @@ -1,4 +1,5 @@ from decimal import Decimal +from typing import Optional UNITS = { "m": Decimal("1e-3"), @@ -25,7 +26,7 @@ def parse(x: str) -> Decimal: return Decimal(x) -def format(x: Decimal, prescision: int | None = None) -> str: +def format(x: Decimal, prescision: Optional[int] = None) -> str: """Converts an integer to a string with respect of units.""" if prescision is not None: diff --git a/robusta_krr/utils/service_discovery.py b/robusta_krr/utils/service_discovery.py index 8c498fe..f341225 100644 --- a/robusta_krr/utils/service_discovery.py +++ b/robusta_krr/utils/service_discovery.py @@ -1,4 +1,5 @@ import logging +from typing import Optional from cachetools import TTLCache from kubernetes import client @@ -13,7 +14,7 @@ class ServiceDiscovery(Configurable): SERVICE_CACHE_TTL_SEC = 900 cache: TTLCache = TTLCache(maxsize=1, ttl=SERVICE_CACHE_TTL_SEC) - def find_service_url(self, label_selector: str, *, api_client: ApiClient | None = None) -> str | None: + def find_service_url(self, label_selector: str, *, api_client: Optional[ApiClient] = None) -> Optional[str]: """ Get the url of an in-cluster service with a specific label """ @@ -36,7 +37,7 @@ class ServiceDiscovery(Configurable): return None - def find_url(self, selectors: list[str], *, api_client: ApiClient | None = None) -> str | None: + def find_url(self, selectors: list[str], *, api_client: Optional[ApiClient] = None) -> Optional[str]: """ Try to autodiscover the url of an in-cluster service """ |
