-
Notifications
You must be signed in to change notification settings - Fork 161
feat(BA-1213): Add detection and event notifications for kernel/container mismatches #4252
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
Open
fregataa
wants to merge
30
commits into
main
Choose a base branch
from
feat/produce-dangling-events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+550
−167
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6edc345
feat: Produce kernel/container dangling events
fregataa 0d698de
add news fragment
fregataa 29060ab
Merge branch 'main' into feat/produce-dangling-events
fregataa 885ac1a
Merge branch 'main' into feat/produce-dangling-events
fregataa 92b68af
Merge branch 'main' into feat/produce-dangling-events
fregataa f45266e
remove commented codes
fregataa 107a689
add probe
fregataa 3e03d30
left comments
fregataa 3781f50
Merge branch 'main' into feat/produce-dangling-events
fregataa ba28c43
apply probe to agent
fregataa 3e0417f
change log msg
fregataa 33dcc2e
inject kernel/container getter to probe
fregataa 83b2bee
relocate agent probe codes
fregataa 6365cde
fix kernel re-init after agent restart
fregataa 49dd14a
correct exception
fregataa e41f033
relocate compare_with_container to probe
fregataa fc7de24
Merge branch 'main' into feat/produce-dangling-events
fregataa 161e50e
Merge branch 'main' into feat/produce-dangling-events
fregataa bd6b21f
rename method
fregataa 964ebc0
Merge branch 'main' into feat/produce-dangling-events
fregataa a772980
remove not useful codes
fregataa 7726961
remove abc kernelprobe class
fregataa 1911063
Add prode runner with no resource
fregataa 304b6a6
better AgentProbe
fregataa 772422a
Merge branch 'main' into feat/produce-dangling-events
fregataa 893aff2
better name?
fregataa c09764b
small change
fregataa 294ad2d
remove probe_runner_with_no_resource_ctx
fregataa 526782f
use label name enum
fregataa 64157ef
Merge branch 'main' into feat/produce-dangling-events
fregataa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add detection and event notifications for dangling kernel/container mismatches |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Callable, Optional | ||
|
||
from aiodocker.docker import Docker | ||
from aiodocker.exceptions import DockerError | ||
|
||
from ai.backend.common.events import ( | ||
DanglingKernelDetected, | ||
EventProducer, | ||
) | ||
from ai.backend.common.types import ContainerId, KernelId | ||
|
||
from ..probe import DanglingKernel | ||
from ..types import ( | ||
Container, | ||
ContainerStatus, | ||
KernelLifecycleStatus, | ||
) | ||
from ..utils import closing_async | ||
from .utils import container_from_docker_container | ||
|
||
|
||
class DockerKernelProbe: | ||
def __init__( | ||
self, | ||
kernel_id: KernelId, | ||
kernel_state_getter: Callable[..., KernelLifecycleStatus], | ||
container_id_getter: Callable[..., Optional[ContainerId]], | ||
event_producer: EventProducer, | ||
) -> None: | ||
self._kernel_id = kernel_id | ||
self._container_id_getter = container_id_getter | ||
self._kernel_state_getter = kernel_state_getter | ||
self._event_producer = event_producer | ||
|
||
async def _get_container_info(self) -> Optional[Container]: | ||
cid = self._container_id_getter() | ||
if cid is None: | ||
return None | ||
async with closing_async(Docker()) as docker: | ||
try: | ||
container = await docker.containers.get(str(cid)) | ||
except DockerError as e: | ||
if e.status == 404: | ||
raise DanglingKernel | ||
return container_from_docker_container(container) | ||
|
||
def _compare_with_container(self, container: Optional[Container]) -> None: | ||
kernel_state = self._kernel_state_getter() | ||
match kernel_state: | ||
case KernelLifecycleStatus.PREPARING: | ||
if container is not None: | ||
# container exists but kernel is hanging in PREPARING state | ||
raise DanglingKernel | ||
case KernelLifecycleStatus.RUNNING: | ||
if container is None or container.status != ContainerStatus.RUNNING: | ||
raise DanglingKernel | ||
case KernelLifecycleStatus.TERMINATING: | ||
# There might be a delay in the container status change | ||
# after the kernel is being terminated. | ||
pass | ||
|
||
async def probe(self, resource_ctx: None) -> None: | ||
try: | ||
container = await self._get_container_info() | ||
self._compare_with_container(container) | ||
except DanglingKernel: | ||
await self._event_producer.produce_event(DanglingKernelDetected(self._kernel_id)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍