-
Notifications
You must be signed in to change notification settings - Fork 166
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
【WIP】add pod diagnosis feature #1219
Open
xiaochaoren
wants to merge
1
commit into
intelligent-machine-learning:master
Choose a base branch
from
xiaochaoren:master
base: master
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.
Open
Changes from all commits
Commits
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 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 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 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
70 changes: 70 additions & 0 deletions
70
dlrover/python/master/diagnosis/operator/check_pod_pending_operator.py
This file contains 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,70 @@ | ||
# Copyright 2024 The DLRover Authors. All rights reserved. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import List | ||
|
||
import datetime | ||
|
||
from dlrover.python.common.log import default_logger as logger | ||
from dlrover.python.common.diagnosis import K8sPodData, DiagnosisDataType | ||
from dlrover.python.master.diagnosis.diagnosis_data import DataManager | ||
from dlrover.python.master.diagnosis.inferencechain.common import ( | ||
Inference, | ||
InferenceAttribute, | ||
InferenceDescription, | ||
InferenceName, | ||
InferenceOperator, | ||
) | ||
|
||
|
||
class CheckPodPendingOperator(InferenceOperator): | ||
def __init__(self, data_manager: DataManager): | ||
self.data_manager = data_manager | ||
|
||
def is_compatible(self, inference: Inference) -> bool: | ||
if ( | ||
inference.name == InferenceName.POD | ||
and inference.attribution == InferenceAttribute.ISORNOT | ||
and inference.description == InferenceDescription.PENDING | ||
): | ||
return True | ||
else: | ||
return False | ||
|
||
def infer(self, inferences: List[Inference]) -> List[Inference]: | ||
# data = K8sPodData(0, pods) | ||
# DiagnosisManager.singleton_instance().collect_diagnosis_data(DiagnosisDataType.K8SPODDATA, data) | ||
pod_data = self.data_manager.get_data(DiagnosisDataType.K8SPODDATA) | ||
if pod_data is None or len(pod_data) == 0: | ||
logger.info('[PodPendingChecker] No pod data collected yet.') | ||
return [] | ||
k8s_pod_data = pod_data[-1] | ||
if not isinstance(k8s_pod_data, K8sPodData): | ||
logger.info('[PodPendingChecker] data is not instance of K8sPodData.') | ||
return [] | ||
|
||
pods = k8s_pod_data.pods | ||
logger.info(f'[PodPendingChecker] {len(pods)} pods collected at {pod_data[len(pod_data) - 1].timestamp}') | ||
# check pod pending time | ||
for pod in pods: | ||
if pod.status.phase == 'Pending': | ||
if pod.status.conditions is None or len(pod.status.conditions) == 0: | ||
logger.info(f'[PodPendingChecker] Pod {pod.metadata.name} has no conditions.') | ||
continue | ||
start_time = pod.status.conditions[-1].last_transition_time | ||
time_difference = (datetime.now() - start_time).total_seconds() / 60 | ||
logger.info(f'[PodPendingChecker] Pod {pod.metadata.name} is pending for {time_difference} minutes') | ||
if time_difference > 15: | ||
# TODO: add inference and do restart for pod | ||
logger.info(f'[PodPendingChecker] TODO: restart Pod {pod.metadata.name}') | ||
return [] | ||
This file contains 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 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,44 @@ | ||
import threading | ||
import time | ||
|
||
from dlrover.python.common.diagnosis import K8sPodData, DiagnosisDataType | ||
from dlrover.python.common.log import default_logger as logger | ||
from dlrover.python.master.diagnosis.diagnosis import DiagnosisManager | ||
from dlrover.python.master.watcher.k8s_watcher import K8sPodWatcher | ||
from dlrover.python.scheduler.job import JobArgs | ||
|
||
|
||
class PodMonitor(object): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This impl is duplicated with |
||
|
||
def __init__(self, job_args: JobArgs): | ||
self._stopped = False | ||
self._k8s_pod_watcher = K8sPodWatcher(job_args.job_name, job_args.namespace) | ||
|
||
def start(self): | ||
"""Start Detecting. The method should be called only once.""" | ||
threading.Thread( | ||
target=self._monitor_pod, | ||
name="pod-monitor", | ||
daemon=True | ||
).start() | ||
|
||
def stop(self): | ||
self._stopped = True | ||
|
||
def _monitor_pod(self): | ||
logger.info("Start monitoring pod events.") | ||
while True: | ||
logger.info("PodMonitor: monitoring pods") | ||
if self._stopped: | ||
logger.info("Stop monitoring pods.") | ||
break | ||
try: | ||
pods = self._k8s_pod_watcher.list() | ||
logger.info(f"PodMonitor: get pods {len(pods)}") | ||
data = K8sPodData(0, pods) | ||
DiagnosisManager.singleton_instance().collect_diagnosis_data(DiagnosisDataType.K8SPODDATA, data) | ||
except Exception as e: | ||
logger.warning(e) | ||
time.sleep(30) | ||
time.sleep(5) | ||
|
This file contains 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 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 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.
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.
Better not involve 'V1Pod' in common package(or user should add 'kubernetes' deps in their env).