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) <chkumar@redhat.com>
This commit is contained in:
Chandan Kumar (raukadah) 2025-03-17 12:46:53 +05:30
parent 14cc275efd
commit 489d13fc17
3 changed files with 27 additions and 7 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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