From 4f6fdd866579881357c9b7d33059a5a9c08abdf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 13 Mar 2019 10:10:26 +0100 Subject: [PATCH] Refactoring the ci metrics a bit more making it easier to re-use --- scripts/ci-frontend-metrics.sh | 32 ++++++++++++++++++++++++++++++++ scripts/ci-metrics-publisher.sh | 18 ++++++++++++++++++ scripts/circle-metrics.sh | 30 ------------------------------ scripts/circle-test-frontend.sh | 20 +++++++++++++------- 4 files changed, 63 insertions(+), 37 deletions(-) create mode 100755 scripts/ci-frontend-metrics.sh create mode 100755 scripts/ci-metrics-publisher.sh delete mode 100755 scripts/circle-metrics.sh diff --git a/scripts/ci-frontend-metrics.sh b/scripts/ci-frontend-metrics.sh new file mode 100755 index 00000000000..c9bd3f1a904 --- /dev/null +++ b/scripts/ci-frontend-metrics.sh @@ -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 \ + + + diff --git a/scripts/ci-metrics-publisher.sh b/scripts/ci-metrics-publisher.sh new file mode 100755 index 00000000000..bb7d042caf1 --- /dev/null +++ b/scripts/ci-metrics-publisher.sh @@ -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]" diff --git a/scripts/circle-metrics.sh b/scripts/circle-metrics.sh deleted file mode 100755 index b52347d0755..00000000000 --- a/scripts/circle-metrics.sh +++ /dev/null @@ -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)'} - ]' diff --git a/scripts/circle-test-frontend.sh b/scripts/circle-test-frontend.sh index 3366bf3d4fb..f8e96853514 100755 --- a/scripts/circle-test-frontend.sh +++ b/scripts/circle-test-frontend.sh @@ -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