Add metric change tracking scripts.

This commit is contained in:
Will Rouesnel 2018-11-11 16:56:36 +11:00
parent a2a2a1df2d
commit df0bb41a13
No known key found for this signature in database
GPG Key ID: 72DC65802A1091C5
6 changed files with 67 additions and 29 deletions

View File

@ -22,6 +22,8 @@ after_success:
; docker push wrouesnel/postgres_exporter:$TRAVIS_TAG ; fi
- if [ "$TRAVIS_BRANCH" == "master" ]; then docker push wrouesnel/postgres_exporter
; fi
- ./postgres-metrics-get-changes.sh
- if [ "$TRAVIS_BRANCH" == "support_shell_fixes" ]; then ./gh-metrics-push.sh ; fi
env:
global:
- DOCKER_USER=wrouesnel

View File

@ -2,8 +2,8 @@
# Script to setup the assets clone of the repository using GIT_ASSETS_BRANCH and
# GIT_API_KEY.
[ -z "$GIT_ASSETS_BRANCH" ] || exit 1
[ -z "$GIT_API_KEY" ] || exit 1
[ ! -z "$GIT_ASSETS_BRANCH" ] || exit 1
[ ! -z "$GIT_API_KEY" ] || exit 1
setup_git() {
git config --global user.email "travis@travis-ci.org" || exit 1

29
gh-metrics-push.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
# Script to copy and push new metric versions to the assets branch.
[ ! -z "$GIT_ASSETS_BRANCH" ] || exit 1
[ ! -z "$GIT_API_KEY" ] || exit 1
version=$(git describe HEAD) || exit 1
# Constants
ASSETS_DIR=".assets-branch"
METRICS_DIR="$ASSETS_DIR/metriclists"
# Ensure metrics dir exists
mkdir -p "$METRICS_DIR/"
# Remove old files so we spot deletions
rm -f "$METRICS_DIR/*.unique"
# Copy new files
cp -f -t "$METRICS_DIR/" ./*.unique || exit 1
# Enter the assets dir and push.
cd "$ASSETS_DIR" || exit 1
git add "$METRICS_DIR" || exit 1
git commit -m "Added unique metrics for build from $version" || exit 1
git push origin "$GIT_ASSETS_BRANCH" || exit 1
exit 0

34
postgres-metrics-get-changes.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# Script to parse a text exposition format file into a unique list of metrics
# output by the exporter and then build lists of added/removed metrics.
old_src="$1"
[ ! -e "$old_src" ] && exit 1
function generate_add_removed() {
type="$1"
pg_version="$2"
old_version="$3"
new_version="$4"
comm -23 "$old_version" "$new_version" > ".metrics.${type}.${pg_version}.removed"
comm -13 "$old_version" "$new_version" > ".metrics.${type}.${pg_version}.added"
}
for raw_prom in $(echo .*.prom) ; do
# Get the type and version
type=$(cut -d'.' -f3)
pg_version=$(cut -d'.' -f4)
unique_file="${raw_prom}.unique"
old_unique_file="$old_src/$unique_file"
# Strip, sort and deduplicate the label names
grep -v '#' "$raw_prom" | \
rev | cut -d' ' -f2- | \
rev | cut -d'{' -f1 | \
sort | \
uniq > "$unique_file"
generate_add_removed "$type" "$pg_version" "$old_unique_file" "$unique_file"
done

View File

@ -1,12 +0,0 @@
#!/bin/bash
# Script to determine added and removed metrics.
# Not currently used in CI but useful for inspecting complicated changes.
# valid types: single or replicated
type="$1"
pg_version="$2"
old_version="$3"
new_version="$4"
comm -23 "$old_version" "$new_version" > ".metrics.${type}.${pg_version}.removed"
comm -13 "$old_version" "$new_version" > ".metrics.${type}.${pg_version}.added"

View File

@ -1,15 +0,0 @@
#!/bin/bash
# Script to parse a text exposition format file into a unique list of metrics
# output by the exporter.
# Not currently used for CI, but useful for inspecting the differences of
# complicated PRs.
for raw_prom in $(echo .*.prom) ; do
# Strip, sort and deduplicate the label names
grep -v '#' "$raw_prom" | \
rev | cut -d' ' -f2- | \
rev | cut -d'{' -f1 | \
sort | \
uniq > "${raw_prom}.unique"
done