Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add updater script and fingerprint for Prometheus #300

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/usr/bin/env bash

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# set -e

source ../../common.sh

SCRIPT_PATH="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
# Root path to the web fingerprinter plugin.
PROJECT_ROOT="$(cd -- "${SCRIPT_PATH}/../../../.." >/dev/null 2>&1 ; pwd -P)"
# App name
APP="prometheus"
# docker hub image name
DOCKER_IMAGE="prom/prometheus"
# GIT repository URL
GIT_URL="https://github.com/prometheus/prometheus"
# Path to the temporary data holder.
TMP_DATA="/tmp/${APP}_fingerprints"
# Path to the local git repository.
GIT_REPO="${TMP_DATA}/repo"
# Path to the directory of all the updated fingerprints data.
FINGERPRINTS_PATH="${TMP_DATA}/fingerprints"
# Json data of the final result.
JSON_DATA="${FINGERPRINTS_PATH}/fingerprint.json"
# Binary proto data of the final result.
BIN_DATA="${FINGERPRINTS_PATH}/fingerprint.binproto"
# Binary proto path to copy the final result.
BINPROTO="${PROJECT_ROOT}/src/main/resources/fingerprinters/web/data/community/${APP}.binproto"

mkdir -p "${FINGERPRINTS_PATH}"

updateFingerprint() {
local app_name="$1"
local app_version="$2"
local fingerprint_path="$3"
local git_repo="$4"
local remote_url="$5"

local fingerprint_input="${fingerprint_path}/fingerprint.json"
local fingerprint_versioned_output="${fingerprint_path}/fingerprint.${app_version}.json"

echo "Updating fingerprint ..."
args=(
--software-name="${app_name}"
--fingerprint-data-path="${fingerprint_input}"
--local-repo-path="${git_repo}"
--remote-url="${remote_url}"
--version="${app_version}"
--crawl-seed-path=/
)

pushd "${PROJECT_ROOT}" >/dev/null || exit
echo ./gradlew :runFingerprintUpdater --args="${args[*]}"
./gradlew :runFingerprintUpdater --args="${args[*]}"
popd >/dev/null || exit

if grep -Fq "\"${app_version}\"" "${fingerprint_versioned_output}"; then
echo "Fingerprint updated successfully"
cp "${fingerprint_versioned_output}" "${fingerprint_input}"
else
echo "fingerprint updating failed"
exit 1
fi
}


startApp() {
local version="$1"
# Start docker container
docker run --rm -d --name "${APP}_${version}" -p 9090:9090 "${DOCKER_IMAGE}:v${version}" || exit

echo "Waiting for ${APP} ${version} to be ready ..."

until [[ $(docker ps -q -f name="${APP}_${version}") ]]
do
echo -n "."
sleep 5
done

}

stopApp() {
local version="$1"
docker stop "${APP}_${version}" || exit
}

convertFingerprint "${BINPROTO}" "${JSON_DATA}"

# Fetch codebase
if [[ ! -d "${GIT_REPO}" ]] ; then
git clone "${GIT_URL}" "${GIT_REPO}"
fi

cd "${GIT_REPO}" || exit

# Read all the versions to be fingerprinted.
readarray -t ALL_VERSIONS < "${SCRIPT_PATH}/versions.txt"

# Update for all the versions listed in versions.txt file.
for app_version in "${ALL_VERSIONS[@]}"; do

echo "Fingerprinting ${APP} version ${app_version} ..."

# Starting app
startApp "${app_version}"

# Checkout the repository to the correct tag.
checkOutRepo "${GIT_REPO}" "v${app_version}"
cd "${GIT_REPO}" || exit

# Download buildinfo information to repo directory
mkdir -p api/v1/status/
curl http://localhost:9090/api/v1/status/buildinfo -o api/v1/status/buildinfo

updateFingerprint \
"${APP}" \
"${app_version}" \
"${FINGERPRINTS_PATH}" \
"${GIT_REPO}" \
"http://localhost:9090"

# Stop the live instance of application.
stopApp "${app_version}"

rm -rf api

done

convertFingerprint "${JSON_DATA}" "${BIN_DATA}"

echo "Fingerprint updated for ${APP}. Please commit the following file:"
echo " ${BIN_DATA}"
echo "to"
echo " ${BINPROTO}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
2.43.0
2.42.0
2.41.0
2.40.7
2.40.6
2.40.5
2.40.4
2.40.3
2.40.2
2.40.1
2.40.0
2.39.2
2.39.1
2.39.0
2.38.0
2.37.5
2.37.4
2.37.3
2.37.2
2.37.1
2.37.0
2.36.2
2.36.1
2.36.0
2.35.0
2.34.0
2.33.5
2.33.4
2.33.3
2.33.2
2.33.1
2.33.0
2.32.1
2.32.0
2.31.2
2.31.1
2.31.0
2.30.4
2.30.3
2.30.2
2.30.1
2.30.0
2.29.2
2.29.1
2.29.0
2.28.1
2.28.0
2.27.1
2.27.0
2.26.1
2.26.0
2.25.2
2.25.1
2.25.0
2.24.1
2.24.0
2.23.0
2.22.2
2.22.1
2.22.0
2.21.0
2.20.1
2.20.0
2.19.3
2.19.2
2.19.1
2.19.0
2.18.2
2.18.1
2.18.0
2.17.2
2.17.1
2.17.0
2.16.0
2.15.2
2.15.1
2.15.0
2.14.0
2.13.1
2.13.0
2.12.0
2.11.2
2.11.1
2.11.0
2.10.0
2.9.2
2.9.1
2.9.0
2.8.1
2.8.0
2.7.2
2.7.1
2.7.0
2.6.1
2.6.0
2.5.0
2.4.3
2.4.2
2.4.1
2.4.0
2.3.2
2.3.1
2.3.0
2.2.1
2.2.0
2.1.0
2.0.0
1.8.2
1.8.1
1.8.0
1.7.2
1.7.1
1.7.0
1.6.3
1.6.2
1.6.1
1.6.0
1.5.3
1.5.2
1.5.1
1.5.0
1.4.1
1.4.0
1.3.1
1.3.0
1.2.3
1.2.2
1.2.1
1.2.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.2
1.0.1
1.0.0
Loading
Loading