From b447aaf4fecf36686557260cb5b678e150fe898b Mon Sep 17 00:00:00 2001 From: Karuppiah Natarajan Date: Fri, 2 Jul 2021 17:47:40 +0530 Subject: [PATCH] scripts: add script to measure percentage of commits with failed status This is to start measuring the test flakyness and see the numbers improving once we improve and deflake flaky tests Fixes #13167 --- .gitignore | 3 ++- scripts/measure-test-flakyness.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 scripts/measure-test-flakyness.sh diff --git a/.gitignore b/.gitignore index dbb48c6e1535..bd21a4b042c4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ hack/tls-setup/certs *.bak .gobincache/ /Documentation/dev-guide/api_reference_v3.md -/Documentation/dev-guide/api_concurrency_reference_v3.md \ No newline at end of file +/Documentation/dev-guide/api_concurrency_reference_v3.md +commit-and-check-data.json \ No newline at end of file diff --git a/scripts/measure-test-flakyness.sh b/scripts/measure-test-flakyness.sh new file mode 100755 index 000000000000..2bc3b8fcf1d0 --- /dev/null +++ b/scripts/measure-test-flakyness.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e +set -o pipefail + +if [[ -z ${GITHUB_TOKEN} ]] +then + echo "Please set the \$GITHUB_TOKEN environment variable for the script to work" + exit 1 +fi + +curl --fail --show-error --silent -H "Authorization: token ${GITHUB_TOKEN}" \ + -X POST \ + -d '{ + "query": "query { repository(owner: \"etcd-io\", name: \"etcd\") { defaultBranchRef { target { ... on Commit { history(first: 100) { edges { node { ... on Commit { commitUrl statusCheckRollup { state } } } } } } } } } }" + }' \ + https://api.github.com/graphql | jq . > commit-and-check-data.json + +failure_percentage=$(jq '.data.repository.defaultBranchRef.target.history.edges | reduce .[] as $item (0; if $item.node.statusCheckRollup.state == "FAILURE" then (. + 1) else . end)' commit-and-check-data.json) + +echo "Commit status failure percentage is - ${failure_percentage} %"