2022-05-11 03:41:53 +00:00
#!/bin/bash
namespace = 'default'
log_path = './milvus-log'
2022-06-29 07:06:18 +00:00
etcd = "false"
minio = "false"
pulsar = "false"
kafka = "false"
2022-09-14 08:04:30 +00:00
since_args = ""
2022-12-08 01:47:32 +00:00
operator = "false"
2022-05-11 03:41:53 +00:00
#-n namespace: The namespace that Milvus is installed in.
#-i milvus_instance: The name of milvus instance.
2022-12-08 01:47:32 +00:00
#-d log_path: Log storage path.
2022-06-29 07:06:18 +00:00
#-e export etcd logs
#-m export minio logs
2022-12-08 01:47:32 +00:00
#-p export pulsar logs
2022-06-29 07:06:18 +00:00
#-k export kafka logs
2022-09-14 08:04:30 +00:00
#-s 24h: export logs since 24h
2022-12-08 01:47:32 +00:00
while getopts "n:i:d:s:empko" opt_name
2022-05-11 03:41:53 +00:00
do
case $opt_name in
2022-06-29 07:06:18 +00:00
n) namespace = $OPTARG ; ;
i) instance_name = $OPTARG ; ;
2022-12-08 01:47:32 +00:00
d) log_path = $OPTARG ; ;
2022-06-29 07:06:18 +00:00
e) etcd = "true" ; ;
m) minio = "true" ; ;
2022-12-08 01:47:32 +00:00
p) pulsar = "true" ; ;
2022-06-29 07:06:18 +00:00
k) kafka = "true" ; ;
2023-01-12 11:27:40 +00:00
o) operator = "true" ; ;
s) since = $OPTARG ; ;
2022-06-29 07:06:18 +00:00
*) echo "Unkonwen parameters" ; ;
2022-05-11 03:41:53 +00:00
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
2023-01-12 11:27:40 +00:00
if [ ! -d $log_path /pod_log ] || [ ! -d $log_dir /pod_log_previous ] || [ ! -d $log_dir /pod_describe ] ;
2022-06-29 07:06:18 +00:00
then
2023-01-12 11:27:40 +00:00
mkdir -p $log_path /pod_log
mkdir -p $log_path /pod_log_previous
mkdir -p $log_path /pod_describe
2022-06-29 07:06:18 +00:00
fi
2022-09-14 08:04:30 +00:00
if [ $since ] ;
then
since_args = " --since= $since "
fi
2022-12-08 01:47:32 +00:00
echo " The log files will be stored in $( readlink -f $log_path ) "
2022-06-29 07:06:18 +00:00
2022-05-11 03:41:53 +00:00
2022-06-29 07:06:18 +00:00
function export_log( ) {
# export pod logs
for pod in $1 ;
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 "
2023-01-12 11:27:40 +00:00
kubectl logs $pod -n $namespace ${ since_args } > $log_path /pod_log/$pod .log
2022-06-29 07:06:18 +00:00
else
echo " Export log of $pod "
2023-01-12 11:27:40 +00:00
kubectl logs $pod -n $namespace -p ${ since_args } > $log_path /pod_log_previous/$pod .log
kubectl logs $pod -n $namespace ${ since_args } > $log_path /pod_log/$pod .log
2022-06-29 07:06:18 +00:00
fi
2023-01-12 11:27:40 +00:00
echo " Export describe of $pod "
kubectl describe pod $pod -n $namespace > $log_path /pod_describe/$pod .log
2022-06-29 07:06:18 +00:00
done
}
# export milvus component log
pods = $( kubectl get pod -n $namespace -l app.kubernetes.io/instance= $instance_name ,app.kubernetes.io/name= milvus --output= jsonpath = { .items..metadata.name} )
2022-05-11 03:41:53 +00:00
if [ ${# pods } = = 0 ] ;
then
echo " There is no Milvus instance $instance_name in the namespace $namespace "
2022-06-29 07:06:18 +00:00
else
export_log " ${ pods [*] } "
2022-05-11 03:41:53 +00:00
fi
2022-06-29 07:06:18 +00:00
# export etcd component log
if $etcd ;
2022-05-11 03:41:53 +00:00
then
2022-12-08 01:47:32 +00:00
if $operator
then
etcd_pods = $( kubectl get pod -n $namespace -l app.kubernetes.io/instance= $instance_name -etcd,app.kubernetes.io/name= etcd --output= jsonpath = { .items..metadata.name} )
else
etcd_pods = $( kubectl get pod -n $namespace -l app.kubernetes.io/instance= $instance_name ,app.kubernetes.io/name= etcd --output= jsonpath = { .items..metadata.name} )
fi
2022-06-29 07:06:18 +00:00
if [ ${# etcd_pods } = = 0 ] ;
then
echo " There is no etcd component for Milvus instance $instance_name in the namespace $namespace "
else
export_log " ${ etcd_pods [*] } "
fi
2022-05-11 03:41:53 +00:00
fi
2022-06-29 07:06:18 +00:00
# export minio component log
if $minio ;
then
2022-12-08 01:47:32 +00:00
if $operator
then
minio_pods = $( kubectl get pod -n $namespace -l release = ${ instance_name } -minio,app= minio --output= jsonpath = { .items..metadata.name} )
else
minio_pods = $( kubectl get pod -n $namespace -l release = $instance_name ,app= minio --output= jsonpath = { .items..metadata.name} )
fi
2022-06-29 07:06:18 +00:00
if [ ${# minio_pods } = = 0 ] ;
then
echo " There is no minio component for Milvus instance $instance_name in the namespace $namespace "
else
export_log " ${ minio_pods [*] } "
fi
fi
2022-05-11 03:41:53 +00:00
2022-06-29 07:06:18 +00:00
# export pulsar component log
if $pulsar ;
then
2022-12-08 01:47:32 +00:00
if $operator
then
pulsar_pods = $( kubectl get pod -n $namespace -l cluster = ${ instance_name } -pulsar,app= pulsar --output= jsonpath = { .items..metadata.name} )
else
if [ [ $instance_name = ~ "pulsar" ] ]
then
pulsar_pods = $( kubectl get pod -n $namespace -l cluster = $instance_name ,app= pulsar --output= jsonpath = { .items..metadata.name} )
else
pulsar_pods = $( kubectl get pod -n $namespace -l cluster = ${ instance_name } -pulsar,app= pulsar --output= jsonpath = { .items..metadata.name} )
fi
fi
2022-06-29 07:06:18 +00:00
if [ ${# pulsar_pods } = = 0 ] ;
2022-05-11 03:41:53 +00:00
then
2022-06-29 07:06:18 +00:00
echo " There is no pulsar component for Milvus instance $instance_name in the namespace $namespace "
2022-05-11 03:41:53 +00:00
else
2022-06-29 07:06:18 +00:00
export_log " ${ pulsar_pods [*] } "
2022-05-11 03:41:53 +00:00
fi
2022-06-29 07:06:18 +00:00
fi
# export kafka component log
if $kafka ;
then
2022-12-08 01:47:32 +00:00
if $operator
then
kafka_pods = $( kubectl get pod -n $namespace -l app.kubernetes.io/instance= ${ instance_name } -kafka,app.kubernetes.io/component= kafka --output= jsonpath = { .items..metadata.name} )
else
kafka_pods = $( kubectl get pod -n $namespace -l app.kubernetes.io/instance= ${ instance_name } ,app.kubernetes.io/component= kafka --output= jsonpath = { .items..metadata.name} )
fi
2022-06-29 07:06:18 +00:00
if [ ${# kafka_pods } = = 0 ] ;
then
echo " There is no kafka component for Milvus instance $instance_name in the namespace $namespace "
else
export_log " ${ kafka_pods [*] } "
fi
fi
2022-05-11 03:41:53 +00:00
tar zcf $log_path .tar.gz $log_path
echo " The compressed logs are stored in $( readlink -f $log_path .tar.gz) "