mirror of https://github.com/milvus-io/milvus.git
[skip ci] Add export logs method to utils (#13067)
Signed-off-by: ThreadDao <yufen.zong@zilliz.com>pull/13080/head
parent
29f4a209c0
commit
3b24b891ef
|
@ -1,3 +1,4 @@
|
|||
import os.path
|
||||
import time
|
||||
from kubernetes import client, config
|
||||
from kubernetes.client.rest import ApiException
|
||||
|
@ -78,6 +79,35 @@ def get_pod_list(namespace, label_selector):
|
|||
raise Exception(str(e))
|
||||
|
||||
|
||||
def export_pods_log(namespace, label_selector):
|
||||
"""
|
||||
export pod logs with label selector to '/tmp/milvus'
|
||||
|
||||
:param namespace: the namespace where the release
|
||||
:type namespace: str
|
||||
|
||||
:param label_selector: labels to restrict which pods logs to export
|
||||
:type label_selector: str
|
||||
|
||||
:example:
|
||||
>>> export_logs("chaos-testing", "app.kubernetes.io/instance=mic-milvus")
|
||||
"""
|
||||
pod_log_path = '/tmp/milvus'
|
||||
if not os.path.isdir(pod_log_path):
|
||||
os.makedirs(pod_log_path)
|
||||
|
||||
# get pods and export logs
|
||||
items = get_pod_list("chaos-testing", label_selector=label)
|
||||
try:
|
||||
for item in items:
|
||||
pod_name = item.metadata.name
|
||||
os.system(f'kubectl logs {pod_name} > {pod_log_path}/{pod_name}.log 2>&1')
|
||||
except Exception as e:
|
||||
log.error(f"Exception when export pod {pod_name} logs: %s\n" % e)
|
||||
raise Exception(str(e))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
label = "app.kubernetes.io/instance=test-proxy-pod-failure, component=proxy"
|
||||
res = get_pod_list("chaos-testing", label_selector=label)
|
||||
export_pods_log(namespace='chaos-testing', label_selector=label)
|
||||
|
|
Loading…
Reference in New Issue