Skip to content

Commit df0bb41

Browse files
committed
Add metric change tracking scripts.
1 parent a2a2a1d commit df0bb41

6 files changed

+67
-29
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ after_success:
2222
; docker push wrouesnel/postgres_exporter:$TRAVIS_TAG ; fi
2323
- if [ "$TRAVIS_BRANCH" == "master" ]; then docker push wrouesnel/postgres_exporter
2424
; fi
25+
- ./postgres-metrics-get-changes.sh
26+
- if [ "$TRAVIS_BRANCH" == "support_shell_fixes" ]; then ./gh-metrics-push.sh ; fi
2527
env:
2628
global:
2729
- DOCKER_USER=wrouesnel

gh-assets-clone.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Script to setup the assets clone of the repository using GIT_ASSETS_BRANCH and
33
# GIT_API_KEY.
44

5-
[ -z "$GIT_ASSETS_BRANCH" ] || exit 1
6-
[ -z "$GIT_API_KEY" ] || exit 1
5+
[ ! -z "$GIT_ASSETS_BRANCH" ] || exit 1
6+
[ ! -z "$GIT_API_KEY" ] || exit 1
77

88
setup_git() {
99
git config --global user.email "[email protected]" || exit 1

gh-metrics-push.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Script to copy and push new metric versions to the assets branch.
3+
4+
[ ! -z "$GIT_ASSETS_BRANCH" ] || exit 1
5+
[ ! -z "$GIT_API_KEY" ] || exit 1
6+
7+
version=$(git describe HEAD) || exit 1
8+
9+
# Constants
10+
ASSETS_DIR=".assets-branch"
11+
METRICS_DIR="$ASSETS_DIR/metriclists"
12+
13+
# Ensure metrics dir exists
14+
mkdir -p "$METRICS_DIR/"
15+
16+
# Remove old files so we spot deletions
17+
rm -f "$METRICS_DIR/*.unique"
18+
19+
# Copy new files
20+
cp -f -t "$METRICS_DIR/" ./*.unique || exit 1
21+
22+
# Enter the assets dir and push.
23+
cd "$ASSETS_DIR" || exit 1
24+
25+
git add "$METRICS_DIR" || exit 1
26+
git commit -m "Added unique metrics for build from $version" || exit 1
27+
git push origin "$GIT_ASSETS_BRANCH" || exit 1
28+
29+
exit 0

postgres-metrics-get-changes.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# Script to parse a text exposition format file into a unique list of metrics
3+
# output by the exporter and then build lists of added/removed metrics.
4+
5+
old_src="$1"
6+
[ ! -e "$old_src" ] && exit 1
7+
8+
function generate_add_removed() {
9+
type="$1"
10+
pg_version="$2"
11+
old_version="$3"
12+
new_version="$4"
13+
14+
comm -23 "$old_version" "$new_version" > ".metrics.${type}.${pg_version}.removed"
15+
comm -13 "$old_version" "$new_version" > ".metrics.${type}.${pg_version}.added"
16+
}
17+
18+
for raw_prom in $(echo .*.prom) ; do
19+
# Get the type and version
20+
type=$(cut -d'.' -f3)
21+
pg_version=$(cut -d'.' -f4)
22+
23+
unique_file="${raw_prom}.unique"
24+
old_unique_file="$old_src/$unique_file"
25+
26+
# Strip, sort and deduplicate the label names
27+
grep -v '#' "$raw_prom" | \
28+
rev | cut -d' ' -f2- | \
29+
rev | cut -d'{' -f1 | \
30+
sort | \
31+
uniq > "$unique_file"
32+
33+
generate_add_removed "$type" "$pg_version" "$old_unique_file" "$unique_file"
34+
done

postgres_metrics_added_and_removed

-12
This file was deleted.

postgres_metrics_parse_script

-15
This file was deleted.

0 commit comments

Comments
 (0)