Refactoring the ci metrics a bit more making it easier to re-use

This commit is contained in:
Torkel Ödegaard 2019-03-13 10:10:26 +01:00
parent aa6a9329c3
commit 4f6fdd8665
4 changed files with 63 additions and 37 deletions

32
scripts/ci-frontend-metrics.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
echo -e "Collecting code stats (typescript errors & more)"
ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --noImplicitAny true | grep -oP 'Found \K(\d+)')"
DIRECTIVES="$(grep -r -o directive public/app/**/* | wc -l)"
CONTROLLERS="$(grep -r -oP 'class .*Ctrl' public/app/**/* | wc -l)"
echo -e "Typescript errors: $ERROR_COUNT"
echo -e "Directives: $DIRECTIVES"
echo -e "Controllers: $CONTROLLERS"
curl \
-d "{\"metrics\": {
\"ci.code.noImplicitAny\": $ERROR_COUNT,
\"ci.code.directives\": $DIRECTIVES,
\"ci.code.controllers\": $CONTROLLERS
}
}" \
-H "Content-Type: application/json" \
-u ci:$CIRCLE_STATS_PWD \
-X POST https://stats.grafana.org/metric-receiver
echo -e ""
./scripts/ci-metrics-publisher.sh \
grafana.ci-code.noImplicitAny=$ERROR_COUNT \
grafana.ci-code.directives=$DIRECTIVES \
grafana.ci-code.controllers=$CONTROLLERS \

18
scripts/ci-metrics-publisher.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
echo "Publishing CI Metrics"
data=""
for ((i = 1; i <= $#; i++ )); do
remainder="${!i}"
first="${remainder%%=*}"; remainder="${remainder#*=}"
if [ -n "$data" ]; then
data="$data,"
fi
data=''$data'{"name": "'${first}'", "value": '${remainder}', "interval": 60, "mtype": "gauge", "time": '$(date +%s)'}'
done
curl https://6371:$GRAFANA_MISC_STATS_API_KEY@graphite-us-central1.grafana.net/metrics \
-H 'Content-type: application/json' \
-d "[$data]"

View File

@ -1,30 +0,0 @@
#!/bin/bash
echo "Collecting code stats (typescript errors & more)"
ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --noImplicitAny true | grep -oP 'Found \K(\d+)')"
DIRECTIVES="$(grep -r -o directive public/app/**/* | wc -l)"
CONTROLLERS="$(grep -r -oP 'class .*Ctrl' public/app/**/* | wc -l)"
echo "Typescript errors: $ERROR_COUNT"
echo "Directives: $DIRECTIVES"
echo "Controllers: $CONTROLLERS"
curl \
-d "{\"metrics\": {
\"ci.code.noImplicitAny\": $ERROR_COUNT,
\"ci.code.directives\": $DIRECTIVES,
\"ci.code.controllers\": $CONTROLLERS
}
}" \
-H "Content-Type: application/json" \
-u ci:$CIRCLE_STATS_PWD \
-X POST https://stats.grafana.org/metric-receiver
curl https://6371:$GRAFANA_MISC_STATS_API_KEY@graphite-us-central1.grafana.net/metrics \
-H 'Content-type: application/json' \
-d '[
{"name":"grafana.ci-code.noImplicitAny", "interval":60, "value": '$ERROR_COUNT', "mtype": "gauge", "time": '$(date +%s)'},
{"name":"grafana.ci-code.directives", "interval":60, "value": '$DIRECTIVES', "mtype": "gauge", "time": '$(date +%s)'},
{"name":"grafana.ci-code.controllers", "interval":60, "value": '$CONTROLLERS', "mtype": "gauge", "time": '$(date +%s)'}
]'

View File

@ -1,4 +1,5 @@
#!/bin/bash
function exit_if_fail {
command=$@
echo "Executing '$command'"
@ -10,11 +11,16 @@ function exit_if_fail {
fi
}
exit_if_fail npm run prettier:check
exit_if_fail npm run test
start=$(date +%s)
exit_if_fail npm run prettier:check
# exit_if_fail npm run test
end=$(date +%s)
seconds=$((end - start))
# if [ "${CIRCLE_BRANCH}" == "master" ]; then
exit_if_fail ./scripts/ci-frontend-metrics.sh
exit_if_fail ./scripts/ci-metrics-publisher.sh grafana.ci-performance.frontend-tests=$seconds
# fi
# On master also collect some and send some metrics
branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "${branch}" == "master" ]; then
exit_if_fail ./scripts/circle-metrics.sh
fi