From 489d13fc1743ec2c3e9ac4dc3c66e0900af35c29 Mon Sep 17 00:00:00 2001 From: "Chandan Kumar (raukadah)" Date: Mon, 17 Mar 2025 12:46:53 +0530 Subject: [PATCH] Use get_extra_file for downloading node_exporter/prometheus tarballs DevStack provides get_extra_file[1] to download node_exporter/prometheus tarballs and cache them in ci for further use. Let's reuse the same instead of wget the binary. This CR also adds cleanup phase under unstack step. Links: [1]. https://github.com/openstack/devstack/blob/master/functions#L50-L79 Closes-Bug: #2102666 Change-Id: I858eea3584794fdc10e45c9f80bfacdabdd537e2 Signed-off-by: Chandan Kumar (raukadah) --- devstack/lib/node_exporter | 14 +++++++++++--- devstack/lib/prometheus | 16 ++++++++++++---- devstack/plugin.sh | 4 ++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/devstack/lib/node_exporter b/devstack/lib/node_exporter index bbb2a88..72697be 100644 --- a/devstack/lib/node_exporter +++ b/devstack/lib/node_exporter @@ -15,14 +15,19 @@ function pre_install_node_exporter { } function install_node_exporter { + + local ne_tarball=node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz + local ne_url=https://github.com/prometheus/node_exporter/releases/download/v${NODE_EXPORTER_VERSION}/${ne_tarball} + # Download node_exporter - wget https://github.com/prometheus/node_exporter/releases/download/v${NODE_EXPORTER_VERSION}/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz + local ne_dest + ne_dest=`get_extra_file ${ne_url}` # Extract the tarball - tar -xvf node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz + tar xzf ${ne_dest} -C $DEST # Move binaries to /usr/local/bin - sudo mv node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64/node_exporter /usr/local/bin/ + sudo mv $DEST/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64/node_exporter /usr/local/bin/ # Set ownership sudo chown $(whoami):$(whoami) ${NODE_EXPORTER_BINARY} @@ -69,6 +74,9 @@ function cleanup_node_exporter { # Remove Node Exporter binaries sudo rm -rf $NODE_EXPORTER_BINARY + + # Remove untar location + sudo rm -rf $DEST/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64 } function wait_for_data { diff --git a/devstack/lib/prometheus b/devstack/lib/prometheus index 10b325a..c74193a 100644 --- a/devstack/lib/prometheus +++ b/devstack/lib/prometheus @@ -15,15 +15,20 @@ function pre_install_prometheus { } function install_prometheus { + + local prom_tarball=prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz + local prom_url=https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/${prom_tarball} + # Download Prometheus - wget https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz + local prom_dest + prom_dest=`get_extra_file ${prom_url}` # Extract the tarball - tar -xvf prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz + tar xzf ${prom_dest} -C $DEST # Move binaries to /usr/local/bin - sudo mv prometheus-${PROMETHEUS_VERSION}.linux-amd64/prometheus /usr/local/bin/ - sudo mv prometheus-${PROMETHEUS_VERSION}.linux-amd64/promtool /usr/local/bin/ + sudo mv $DEST/prometheus-${PROMETHEUS_VERSION}.linux-amd64/prometheus /usr/local/bin/ + sudo mv $DEST/prometheus-${PROMETHEUS_VERSION}.linux-amd64/promtool /usr/local/bin/ # Set ownership sudo chown $(whoami):$(whoami) /usr/local/bin/prometheus @@ -87,6 +92,9 @@ function cleanup_prometheus { # Remove binaries sudo rm /usr/local/bin/prometheus sudo rm /usr/local/bin/promtool + + # Remove untar location + sudo rm -rf $DEST/prometheus-${PROMETHEUS_VERSION}.linux-amd64 } function wait_for_data { diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 5377c50..f8823e2 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -44,6 +44,8 @@ if is_service_enabled prometheus; then # no-op echo_summary "Stoping prometheus service" stop_prometheus + echo_summary "Cleaning prometheus service" + cleanup_prometheus fi if [[ "$1" == "clean" ]]; then @@ -88,6 +90,8 @@ if is_service_enabled node_exporter; then # no-op echo_summary "Stoping node_exporter service" stop_node_exporter + echo_summary "Cleaning node exporter service" + cleanup_node_exporter fi if [[ "$1" == "clean" ]]; then