Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix grcp hangs and upgrade grpcio to 1.62.2 #909

Open
wants to merge 28 commits into
base: feature/pdeathsigger
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions gprofiler/containers_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@

logger = get_logger_adapter(__name__)

_containers_client: Optional[ContainersClient] = None


class ContainerNamesClient:
def __init__(self) -> None:
global _containers_client
try:
self._containers_client: Optional[ContainersClient] = ContainersClient()
logger.info(f"Discovered container runtimes: {self._containers_client.get_runtimes()}")
if _containers_client is None:
_containers_client = ContainersClient()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract this to a method get_containers_client which will be locked (to avoid any concurrency issues) and maintain the cache.

Then, ContainerNamesClient runs self._containers_client = get_containers_client().

logger.info(f"Discovered container runtimes: {_containers_client.get_runtimes()}")
except NoContainerRuntimesError:
logger.warning(
"Could not find a Docker daemon or CRI-compatible daemon, profiling data will not"
" include the container names. If you do have a containers runtime and it's not supported,"
" please open a new issue here:"
" https://github.com/Granulate/gprofiler/issues/new"
)
self._containers_client = None

self._pid_to_container_name_cache: Dict[int, str] = {}
self._current_container_names: Set[str] = set()
Expand All @@ -53,7 +56,7 @@ def container_names(self) -> List[str]:
return list(self._current_container_names)

def get_container_name(self, pid: int) -> str:
if self._containers_client is None:
if _containers_client is None:
return ""

if not valid_perf_pid(pid):
Expand All @@ -73,7 +76,8 @@ def get_container_name(self, pid: int) -> str:
def _safely_get_process_container_name(self, pid: int) -> Optional[str]:
try:
try:
container_id = get_process_container_id(Process(pid))
process = Process(pid)
container_id = get_process_container_id(process)
if container_id is None:
return None
except NoSuchProcess:
Expand Down Expand Up @@ -103,5 +107,5 @@ def _get_container_name(self, container_id: str) -> Optional[str]:
def _refresh_container_names_cache(self) -> None:
# We re-fetch all of the currently running containers, so in order to keep the cache small we clear it
self._container_id_to_name_cache.clear()
for container in self._containers_client.list_containers() if self._containers_client is not None else []:
for container in _containers_client.list_containers() if _containers_client is not None else []:
self._container_id_to_name_cache[container.id] = container.name
Loading