From df0bb41a13a943b8895740bfdf71a25128106a18 Mon Sep 17 00:00:00 2001 From: Will Rouesnel Date: Sun, 11 Nov 2018 16:56:36 +1100 Subject: [PATCH] Add metric change tracking scripts. --- .travis.yml | 2 ++ gh-assets-clone.sh | 4 ++-- gh-metrics-push.sh | 29 +++++++++++++++++++++++++ postgres-metrics-get-changes.sh | 34 ++++++++++++++++++++++++++++++ postgres_metrics_added_and_removed | 12 ----------- postgres_metrics_parse_script | 15 ------------- 6 files changed, 67 insertions(+), 29 deletions(-) create mode 100755 gh-metrics-push.sh create mode 100755 postgres-metrics-get-changes.sh delete mode 100755 postgres_metrics_added_and_removed delete mode 100755 postgres_metrics_parse_script diff --git a/.travis.yml b/.travis.yml index 4d31f3d5..0ea69a19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/gh-assets-clone.sh b/gh-assets-clone.sh index fe05b0d4..a4f93b0e 100755 --- a/gh-assets-clone.sh +++ b/gh-assets-clone.sh @@ -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 diff --git a/gh-metrics-push.sh b/gh-metrics-push.sh new file mode 100755 index 00000000..362fda53 --- /dev/null +++ b/gh-metrics-push.sh @@ -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 \ No newline at end of file diff --git a/postgres-metrics-get-changes.sh b/postgres-metrics-get-changes.sh new file mode 100755 index 00000000..24200ff1 --- /dev/null +++ b/postgres-metrics-get-changes.sh @@ -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 diff --git a/postgres_metrics_added_and_removed b/postgres_metrics_added_and_removed deleted file mode 100755 index 334f9b6a..00000000 --- a/postgres_metrics_added_and_removed +++ /dev/null @@ -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" diff --git a/postgres_metrics_parse_script b/postgres_metrics_parse_script deleted file mode 100755 index 48da760c..00000000 --- a/postgres_metrics_parse_script +++ /dev/null @@ -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