-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathfleet_logs
More file actions
executable file
·92 lines (74 loc) · 1.91 KB
/
Copy pathfleet_logs
File metadata and controls
executable file
·92 lines (74 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
set -eo pipefail
usage() {
echo "Example usage: ./fleet_logs --tier <tier> --fleet-id <fleet-id> --task-id <task-id> --subcomponent-type [fleet_task|fleet_worker] --since 6h0m0s"
exit 1
}
ICL_ENDPOINT="${LOGS_URL}"
REGION="${REGION:=eu-de}"
NAME_PREFIX="${NAME_PREFIX:=ce-fleet-sandbox}"
RESOURCE_GROUP="${RESOURCE_GROUP:=$NAME_PREFIX--rg}"
ICL_NAME="${NAME_PREFIX}--icl"
FLEET_ID=
TASK_ID=
SUBCOMPONENT_TYPE=
TIER="frequent_search"
OUTPUT="logs-raw"
SINCE="6h0m0s"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
while [[ $# -gt 0 ]]; do
case "$1" in
--fleet-id)
shift
FLEET_ID="$1"
;;
--task-id)
shift
TASK_ID="$1"
;;
--subcomponent-type)
shift
SUBCOMPONENT_TYPE="$1"
;;
--tier)
shift
TIER="$1"
;;
--output)
shift
OUTPUT="$1"
;;
--since)
shift
SINCE="$1"
;;
--help)
usage
;;
*)
usage
;;
esac
shift
done
source ${SCRIPT_DIR}/common.sh
target_region $REGION > /dev/null
target_resource_group $RESOURCE_GROUP > /dev/null
ibmcloud plugin show logs > /dev/null
if [[ $? -ne 0 ]]; then
ibmcloud plugin install logs
fi
if [[ -z "${ICL_ENDPOINT}" ]]; then
ICL_ENDPOINT=https://"$(ibmcloud resource service-instance ${ICL_NAME} -o json | jq -r '.[].extensions.external_api')"
fi
LOGS_FILTER="source logs"
if [ -n "$FLEET_ID" ]; then
LOGS_FILTER="${LOGS_FILTER} | filter \$d.codeengine.fleetId ~ '${FLEET_ID}'"
fi
if [ -n "$TASK_ID" ]; then
LOGS_FILTER="${LOGS_FILTER} | filter \$d.codeengine.taskId ~ '${TASK_ID}'"
fi
if [ -n "$SUBCOMPONENT_TYPE" ]; then
LOGS_FILTER="${LOGS_FILTER} | filter \$d.codeengine.subcomponentType ~ '${SUBCOMPONENT_TYPE}'"
fi
ibmcloud logs query --since ${SINCE} --tier ${TIER} --query "${LOGS_FILTER} | sort by \$m.timestamp" --service-url "${ICL_ENDPOINT}" --output ${OUTPUT}