Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hive-lineage/hive-lineage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function install_jars() {
}

function restart_hive_server2_master() {
ROLE=$(curl -f -s -H Metadata-Flavor:Google http://metadata/computeMetadata/v1/instance/attributes/dataproc-role)
# Safely get metadata without failing the script if the key is missing
ROLE=$(/usr/share/google/get_metadata_value attributes/dataproc-role || echo "Unknown")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve encapsulation and prevent the ROLE variable from potentially leaking into the global scope, it's a good practice to declare it as a local variable within the function.

Suggested change
ROLE=$(/usr/share/google/get_metadata_value attributes/dataproc-role || echo "Unknown")
local ROLE=$(/usr/share/google/get_metadata_value attributes/dataproc-role || echo "Unknown")

if [[ "${ROLE}" == 'Master' ]]; then
echo "Restarting hive-server2"
sudo systemctl restart hive-server2.service
Expand Down