diff --git a/docs/latest/modules/en/attachments/suse-observability_logs_collector.sh b/docs/latest/modules/en/attachments/suse-observability_logs_collector.sh index 8bfe30c2..c52af5b3 100644 --- a/docs/latest/modules/en/attachments/suse-observability_logs_collector.sh +++ b/docs/latest/modules/en/attachments/suse-observability_logs_collector.sh @@ -1,6 +1,6 @@ #!/bin/bash -ELASTICSEARCH_LOGS=0 +ELASTICSEARCH_LOGS=false ELASTICSEARCH_RANGE="7d" while getopts "her:" option; do case $option in @@ -23,7 +23,7 @@ options: EOF exit 0;; e) # Collect elasticsearch logs - ELASTICSEARCH_LOGS=1;; + ELASTICSEARCH_LOGS=true;; r) # Time range for elasticsearch logs ELASTICSEARCH_RANGE=$OPTARG;; \?) # Invalid option @@ -49,12 +49,12 @@ for cmd in ${COMMANDS[@]}; do done # skip helm release analysis when not all its dependencies are present -HELM_RELEASES=1 +HELM_RELEASES=true for cmd in base64 gzip jq do if ! command -v $cmd &>/dev/null; then echo "$cmd is not installed. Skipping analysis of helm releases." - HELM_RELEASES=0 + HELM_RELEASES=false fi done @@ -130,11 +130,25 @@ collect_pod_disk_usage() { collect_helm_releases() { techo "Collecting helm releases..." mkdir -p "$OUTPUT_DIR/releases" + + # Restrict keys extracted from Helm values to only this include-list to avoid including any + included_keys='["resources", "affinity", "nodeSelector", "tolerations"]' + + # 1. --argjson keys "$included_keys": Passes the shell variable as a JSON array $keys. + # 2. . as $input: Saves the entire original JSON into a variable $input. + # 3. [ paths | ... ]: Gathers all paths from the JSON. + # 4. select(.[-1] as $last | $keys | index($last)): Selects only paths where + # the last element (.[-1]) is found inside the $keys array. + # 5. reduce .[] as $p (null; ...): Starts with an empty (null) document + # and iterates over every path ($p) that was selected. + # 6. setpath($p; $input | getpath($p)): For each path, it sets that path + # in the *new* document, pulling the *value* from the original $input. + RELEASES=$(kubectl -n "$NAMESPACE" get secrets -l owner=helm -o jsonpath="{.items[*].metadata.name}") for release in $RELEASES; do kubectl -n "$NAMESPACE" get secret "$release" -o jsonpath='{.data.release}' | \ base64 --decode | base64 --decode | gzip -d | \ - jq '{ info: .info, metadata: .chart.metadata, config: .config }' > "$OUTPUT_DIR/releases/$release" + jq --argjson keys "$included_keys" '{ info: .info, metadata: .chart.metadata, config: ( .config as $input | [ .config | paths | select(.[-1] as $last | $keys | index($last)) ] | reduce .[] as $p (null; setpath($p; $input | getpath($p)))) }' > "$OUTPUT_DIR/releases/$release" done } @@ -247,6 +261,35 @@ EOF kill $CHILD } +collect_hdfs_report() { + POD=$(kubectl -n "$NAMESPACE" get pod -l app.kubernetes.io/component=hdfs-nn -o jsonpath='{.items[0].metadata.name}' 2>/dev/null) || true + if [ -n "$POD" ]; then + techo "Collecting HDFS report..." + mkdir -p "$OUTPUT_DIR/reports" + kubectl exec -n "$NAMESPACE" "$POD" -c namenode -- bash -c "unset HADOOP_OPTS; hdfs dfsadmin -report" > "$OUTPUT_DIR/reports/hdfs.log" + fi +} + +collect_hbase_report() { + POD=$(kubectl -n "$NAMESPACE" get pod -l app.kubernetes.io/component=hbase-master -o jsonpath='{.items[0].metadata.name}' 2>/dev/null) || true + if [ -n "$POD" ]; then + # Running in HA Mode + techo "Collecting HBase report..." + mkdir -p "$OUTPUT_DIR/reports" + kubectl exec -n "$NAMESPACE" "$POD" -c master -- bash -c 'hbase hbck -details 2>&1' > "$OUTPUT_DIR/reports/hbase.log" + else + POD=$(kubectl -n "$NAMESPACE" get pod -l app.kubernetes.io/component=stackgraph -o jsonpath='{.items[0].metadata.name}' 2>/dev/null) || true + if [ -n "$POD" ]; then + # Running in non-HA mode + techo "Collecting HBase report..." + mkdir -p "$OUTPUT_DIR/reports" + kubectl exec -n "$NAMESPACE" "$POD" -c stackgraph -- bash -c 'hbase hbck -details 2>&1' > "$OUTPUT_DIR/reports/hbase.log" + else + techo "Could not find HBase or StackGraph pod to generate HBase report." + fi + fi +} + archive_and_cleanup() { echo "Creating archive $ARCHIVE_FILE..." tar -czf "$ARCHIVE_FILE" "$OUTPUT_DIR" @@ -303,11 +346,13 @@ kubectl -n "$NAMESPACE" get events --sort-by='.metadata.creationTimestamp' > "$O # Run the pod logs collection function collect_pod_logs collect_pod_disk_usage +collect_hdfs_report +collect_hbase_report collect_yaml_configs -if [ $HELM_RELEASES ]; then +if $HELM_RELEASES; then collect_helm_releases fi -if [ $ELASTICSEARCH_LOGS ]; then +if $ELASTICSEARCH_LOGS; then collect_pod_logs_from_elasticsearch fi