File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,28 @@ INCOMING=incoming
55PROCESSED=processed
66VENV=" $( mktemp -d) "
77METRICS_DIR=" $( mktemp -d) "
8+ METRIC_TIMEOUT_IN_SECONDS=172800 # 48h in seconds
89
910PUSHGATEWAY_URL=${PUSHGATEWAY_URL%/ }
1011
1112# Cleanup the temporary directories
1213trap ' rm -rf "$VENV" "$METRICS_DIR"' EXIT
1314
15+ # First, we should detect any stale metrics and purge them if needed
16+ METRICS_LAST_UPDATED=$( curl " $PUSHGATEWAY_URL /metrics" | grep " ^push_time_seconds{.*" | grep osde2e | sed ' s/^.*job="\([[:alnum:]_.-]*\)".*\}\s*\(.*\)$/\1,\2/' | sort | uniq)
17+ CURRENT_TIMESTAMP=$( date +%s)
18+ for metric_and_timestamp in $METRICS_LAST_UPDATED ; do
19+ JOB_NAME=$( echo -e $metric_and_timestamp | cut -f 1 -d,)
20+ TIMESTAMP=$( echo -e $metric_and_timestamp | cut -f 2 -d, | xargs -d ' \n' printf " %.f" )
21+ if (( (($TIMESTAMP + $METRIC_TIMEOUT_IN_SECONDS )) < $CURRENT_TIMESTAMP )); then
22+ echo " Metrics for job $JOB_NAME are greater than $METRIC_TIMEOUT_IN_SECONDS seconds old. Removing them from the pushgateway."
23+ if ! curl -X DELETE " $PUSHGATEWAY_URL /metrics/job/$JOB_NAME " ; then
24+ echo " Error deleting old results for $JOB_NAME ."
25+ exit 3
26+ fi
27+ fi
28+ done
29+
1430virtualenv " $VENV "
1531. " $VENV /bin/activate"
1632
You can’t perform that action at this time.
0 commit comments