Skip to content

Commit

Permalink
Remove mutating calls and ignore collection of unknown logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nithu0115 authored and mogren committed Mar 7, 2020
1 parent 1b3642c commit 7a53fbb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 148 deletions.
7 changes: 1 addition & 6 deletions log-collector-script/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ The project can be used in normal or enable_debug(**Caution: enable_debug will p

```
# sudo bash eks-log-collector.sh --help
USAGE: eks-log-collector --help [ --mode=collect|enable_debug --ignore_introspection=true|false --ignore_metrics=true|false ]
USAGE: eks-log-collector --help [ --ignore_introspection=true|false --ignore_metrics=true|false ]
OPTIONS:
--mode Has two parameters 1) collect or 2) enable_debug,:
collect Gathers basic operating system, Docker daemon, and
Amazon EKS related config files and logs. This is the default mode.
enable_debug Enables debug mode for the Docker daemon(Not for production use)
--ignore_introspection To ignore introspection of IPAMD; Pass this flag if DISABLE_INTROSPECTION is enabled on CNI
--ignore_metrics To ignore prometheus metrics collection; Pass this flag if DISABLE_METRICS enabled on CNI
Expand Down
96 changes: 22 additions & 74 deletions log-collector-script/linux/eks-log-collector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export LANG="C"
export LC_ALL="C"

# Global options
readonly PROGRAM_VERSION="0.5.2"
readonly PROGRAM_VERSION="0.6.0"
readonly PROGRAM_SOURCE="https://github.com/awslabs/amazon-eks-ami/blob/master/log-collector-script/"
readonly PROGRAM_NAME="$(basename "$0" .sh)"
readonly PROGRAM_DIR="/opt/log-collector"
Expand All @@ -32,7 +32,6 @@ INIT_TYPE=""
PACKAGE_TYPE=""

# Script run defaults
mode='collect'
ignore_introspection='false'
ignore_metrics='false'

Expand Down Expand Up @@ -85,13 +84,9 @@ IPAMD_DATA=(

help() {
echo ""
echo "USAGE: ${PROGRAM_NAME} --help [ --mode=collect|enable_debug --ignore_introspection=true|false --ignore_metrics=true|false ]"
echo "USAGE: ${PROGRAM_NAME} --help [ --ignore_introspection=true|false --ignore_metrics=true|false ]"
echo ""
echo "OPTIONS:"
echo " --mode Has two parameters 1) collect or 2) enable_debug,:"
echo " collect Gathers basic operating system, Docker daemon, and"
echo " Amazon EKS related config files and logs. This is the default mode."
echo " enable_debug Enables debug mode for the Docker daemon(Not for production use)"
echo ""
echo " --ignore_introspection To ignore introspection of IPAMD; Pass this flag if DISABLE_INTROSPECTION is enabled on CNI"
echo ""
Expand All @@ -110,9 +105,6 @@ parse_options() {
val="$(echo "${arg}" | awk -F '=' '{print $2}')"

case "${param}" in
mode)
eval "${param}"="${val}"
;;
ignore_introspection)
eval "${param}"="${val}"
;;
Expand Down Expand Up @@ -169,7 +161,6 @@ version_output() {
}

log_parameters() {
echo mode: "${mode}" >> "${COLLECT_DIR}"/system/script-params.txt
echo ignore_introspection: "${ignore_introspection}" >> "${COLLECT_DIR}"/system/script-params.txt
echo ignore_metrics: "${ignore_metrics}" >> "${COLLECT_DIR}"/system/script-params.txt
}
Expand Down Expand Up @@ -250,11 +241,6 @@ collect() {
get_docker_logs
}

enable_debug() {
init
enable_docker_debug
}

pack() {
try "archive gathered information"

Expand All @@ -264,10 +250,8 @@ pack() {
}

finished() {
if [[ "${mode}" == "collect" ]]; then
cleanup
echo -e "\n\tDone... your bundled logs are located in ${PROGRAM_DIR}/eks_${INSTANCE_ID}_$(date --utc +%Y-%m-%d_%H%M-%Z)_${PROGRAM_VERSION}.tar.gz\n"
fi
cleanup
echo -e "\n\tDone... your bundled logs are located in ${PROGRAM_DIR}/eks_${INSTANCE_ID}_$(date --utc +%Y-%m-%d_%H%M-%Z)_${PROGRAM_VERSION}.tar.gz\n"
}

get_mounts_info() {
Expand Down Expand Up @@ -316,6 +300,18 @@ get_common_logs() {
tail -c 10M /var/log/messages > "${COLLECT_DIR}"/var_log/messages
continue
fi
if [[ "${entry}" == "containers" ]]; then
cp --force --recursive /var/log/containers/aws-node* "${COLLECT_DIR}"/var_log/
cp --force --recursive /var/log/containers/coredns-* "${COLLECT_DIR}"/var_log/
cp --force --recursive /var/log/containers/kube-proxy* "${COLLECT_DIR}"/var_log/
continue
fi
if [[ "${entry}" == "pods" ]]; then
cp --force --recursive /var/log/pods/kube-system_aws-node* "${COLLECT_DIR}"/var_log/
cp --force --recursive /var/log/pods//kube-system_coredns* "${COLLECT_DIR}"/var_log/
cp --force --recursive /var/log/pods/kube-system_kube-proxy* "${COLLECT_DIR}"/var_log/
continue
fi
cp --force --recursive --dereference /var/log/"${entry}" "${COLLECT_DIR}"/var_log/
fi
done
Expand Down Expand Up @@ -525,59 +521,11 @@ get_docker_info() {
ok
}

enable_docker_debug() {
try "enable debug mode for the Docker daemon"

case "${PACKAGE_TYPE}" in
rpm)

if [[ -e /etc/sysconfig/docker ]] && grep -q "^\s*OPTIONS=\"-D" /etc/sysconfig/docker
then
echo "Debug mode is already enabled."
ok
else
if [[ -e /etc/sysconfig/docker ]]; then
echo "OPTIONS=\"-D \$OPTIONS\"" >> /etc/sysconfig/docker

try "restart Docker daemon to enable debug mode"
service docker restart
ok
fi
fi
;;
*)
warning "The current operating system is not supported."

ok
;;
esac
}

confirm_enable_docker_debug() {
read -r -p "${1:-Enabled Docker Debug will restart the Docker Daemon and restart all running container. Are you sure? [y/N]} " USER_INPUT
case "$USER_INPUT" in
[yY][eE][sS]|[yY])
enable_docker_debug
;;
*)
die "\"No\" was selected."
;;
esac
}

# -----------------------------------------------------------------------------
# Entrypoint
parse_options "$@"

case "${mode}" in
collect)
collect
pack
finished
;;
enable_debug)
confirm_enable_docker_debug
finished
;;
*)
help && exit 1
;;
esac
collect
pack
finished

13 changes: 1 addition & 12 deletions log-collector-script/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,7 @@ Invoke-WebRequest -OutFile eks-log-collector.ps1 https://raw.githubusercontent.c
The project can be used in normal or Enable/Disable Debug(**Caution: Enable/Disable Debug will restart Docker daemon which would kill running containers**).

```
# eks-log-collector.ps1
USAGE: eks-log-collector [ -RunMode =Collect|EnableDebug|DisableDebug ]
OPTIONS:
-RunMode Has three parameters 1) Collect, 2) EnableDebug 3) DisableDebug:
Collect Gathers basic operating system, Docker daemon, and
Amazon EKS related config files and logs. This is the default mode.
EnableDebug Enables debug mode for Docker daemon (Not for production use)
DisableDebug Disable debug mode for Docker daemon
Enables debug mode for the Docker daemon:
eks-log-collector.ps1 -RunMode EnableDebug
USAGE: .\eks-log-collector.ps1
```
#### Example output in normal mode
The following output shows this project running in normal mode.
Expand Down
62 changes: 6 additions & 56 deletions log-collector-script/windows/eks-log-collector.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
.EXAMPLE
eks-log-collector.ps1
Gather basic operating system, Docker daemon, and kubelet logs.
.EXAMPLE
eks-log-collector.ps1 -RunMode EnableDebug
Enables debug mode for the Docker daemon.
#>

Expand Down Expand Up @@ -279,41 +276,6 @@ Function get_network_info{
Break
}
}
Function enable_docker_debug{
try {
Write-Host "Enabling debug mode for the Docker Service"
if (sc.exe qc docker | where-object {$_ -like '*-D*'}){
Write-Host "Debug mode already enabled" -foregroundcolor "yellow"
}
else {
sc.exe config docker binPath= "C:\Program Files\Docker\dockerd.exe --run-service -D"
Restart-service Docker
Write-Host "OK" -foregroundcolor "green"
}
}
catch {
Write-Error "Failed to enable debug mode"
Break
}
}

Function disable_docker_debug{
try {
Write-Host "Disabling debug mode for the Docker Service"
if (sc.exe qc docker | where-object {$_ -like '*-D*'}){
sc.exe config docker binPath= "C:\Program Files\Docker\dockerd.exe --run-service"
Restart-service Docker
Write-Host "OK" -foregroundcolor "green"
}
else {
Write-Host "Debug mode already disabled" -foregroundcolor "yellow"
}
}
catch {
Write-Error "Failed to disable debug mode"
Break
}
}

Function cleanup{
Write-Host "Cleaning up directory"
Expand Down Expand Up @@ -357,26 +319,14 @@ Function collect{

}

Function enable_debug{
enable_docker_debug
}

Function disable_debug{
disable_docker_debug
}

if ($RunMode -eq "Collect"){
#--------------------------
#Main-function
Function main {
Write-Host "Running Default(Collect) Mode" -foregroundcolor "blue"
cleanup
collect
pack
} elseif ($RunMode -eq "EnableDebug"){
Write-Host "Enabling Debug for Docker" -foregroundcolor "blue"
enable_debug
} elseif ($RunMode -eq "DisableDebug"){
Write-Host "Disabling Debug for Docker" -foregroundcolor "blue"
disable_debug
} else {
Write-Host "You need to specify either Collect, EnableDebug or DisableDebug RunMode" -ForegroundColor "red"
Break
}

#Entry point
main

0 comments on commit 7a53fbb

Please sign in to comment.