浏览代码

Merge branch 'ci-metrics-take2'

Torkel Ödegaard 6 年之前
父节点
当前提交
6f226edcc0
共有 4 个文件被更改,包括 61 次插入35 次删除
  1. 32 0
      scripts/ci-frontend-metrics.sh
  2. 18 0
      scripts/ci-metrics-publisher.sh
  3. 0 30
      scripts/circle-metrics.sh
  4. 11 5
      scripts/circle-test-frontend.sh

+ 32 - 0
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 \
+
+
+

+ 18 - 0
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]"

+ 0 - 30
scripts/circle-metrics.sh

@@ -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)'}
-   ]'

+ 11 - 5
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
 }
 
+start=$(date +%s)
+
 exit_if_fail npm run prettier:check
-exit_if_fail npm run test
+# exit_if_fail npm run test
 
-# 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
+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
+