Add a script to export milvus log (#16895)

Signed-off-by: Bennu-Li <yunmei.li@zilliz.com>
pull/16896/head
Bennu 2022-05-11 11:41:53 +08:00 committed by GitHub
parent 9e6d9fb7d8
commit 84ce9fa324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,32 @@
# README
## Overview
For better tracking and debugging Milvus, the script `export-milvus-log.sh` is provided for exporting all Milvus logs at once. For those pods that have been restarted, this script can export the logs of the running pods and the logs of the previously pods.
## Parameter Description
| Parameters | Description | Default |
| ---------- | ------------------------------------------------- | ------------ |
| i | Specify the milvus instance name | None |
| n | Specify the namespace that milvus is installed in | default |
| p | Specify the log storage path | ./milvus-log |
## Usage
1. Milvus instance name is required to be specified
```shell
./export-milvus-log.sh -i my-release
```
> This command will generate a directory named milvus-log in the current directory.
> For a pod that have not been restarted, the command will generate a log named ${podname}.log for the pod and store it in `milvus-log`.
> For a pod that has been restarted, this command will generate a log named ${podname}.log and a log ${podname}-pre.log for the pod.
2. If your milvus is not installed in the k8s default namespace, please specify namespace with `-n`. You can also customize the log storage path with `-p`.
```shell
./export-milvus-log.sh -i my-release -n milvus -p ./logs
```

View File

@ -0,0 +1,63 @@
#!/bin/bash
namespace='default'
log_path='./milvus-log'
#-n namespace: The namespace that Milvus is installed in.
#-i milvus_instance: The name of milvus instance.
#-p log_path: Log storage path.
while getopts "n:i:p:" opt_name
do
case $opt_name in
n) namespace=$OPTARG
;;
i) instance_name=$OPTARG
;;
p) log_path=$OPTARG
;;
*) echo "Unkonwen parameters"
;;
esac
done
if [ ! $instance_name ];
then
echo "Missing argument instance_name, please add it. For example:'./export-milvus-log.sh -i milvus-instance-name'"
exit 1
fi
pods=$(kubectl get pod -n $namespace -l app.kubernetes.io/instance=$instance_name,app.kubernetes.io/name=milvus --output=jsonpath={.items..metadata.name})
if [ ${#pods} == 0 ];
then
echo "There is no Milvus instance $instance_name in the namespace $namespace"
exit 1
fi
if [ ! -d $log_path ];
then
mkdir -p $log_path
fi
echo "The log files will be stored $(readlink -f $log_path)"
for pod in $pods;
do
# Check if the pod has been restarted
if [ $(kubectl get pod $pod -n $namespace --output=jsonpath={.status.containerStatuses[0].restartCount}) == 0 ];
then
echo "Export log of $pod"
kubectl logs $pod -n $namespace > $log_path/$pod.log
else
echo "Export log of $pod"
kubectl logs $pod -n $namespace -p > $log_path/$pod-pre.log
kubectl logs $pod -n $namespace > $log_path/$pod.log
fi
done
tar zcf $log_path.tar.gz $log_path
echo "The compressed logs are stored in $(readlink -f $log_path.tar.gz)"