github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/metrics/configs/pr-consistency-config.yaml (about) 1 metric: pr-consistency 2 description: Calculate PR flakiness for each day. 3 query: | 4 select /* Calculate the prob a commit flaked on at least one PR job at some point. + prob that a `/test all` command flakes. */ 5 timestamp_to_sec(day) day, 6 round(sum(consistent)/count(consistent),4) commit_consistency, 7 sum(consistent) consistent_commits, 8 count(consistent) commits, 9 round(sum(consistent_runs)/sum(runs), 4) run_consistency, /* should be approx. the nth root of consistency if there are n PR jobs and assumptions hold (job flake independence over the same commit). */ 10 sum(consistent_runs) consistent_runs, 11 sum(runs) runs, 12 sum(builds) builds 13 from ( /* For each day, count whether a (commit) flaked */ 14 select 15 day, 16 commit, 17 min(if(passed == runs or passed == 0, 1, 0)) consistent, 18 max(runs) builds, 19 sum(runs) runs, 20 sum(if(passed==0, runs, passed)) consistent_runs 21 from ( 22 select /* For each day, count runs and passes for a (job, commit) */ 23 cast(day as timestamp) day, 24 commit, 25 sum(if(result=='SUCCESS',1,0)) passed, 26 INTEGER(count(result)) runs 27 from ( 28 SELECT /* Find jobs, noting its commit, day it ran, and whether it passed */ 29 job, 30 regexp_extract(metadata.value, r'^[^,]+,\d+:([^,"]+)') commit, /* git hash of pr */ 31 result, 32 cast(date(started) as date) day 33 FROM [k8s-gubernator:build.all] 34 where 35 /* Select results that have occured on or after the day of <LAST_DATA_TIME> (those results were 36 for the day before), but don't include results from today, only return results for complete days. */ 37 cast(date(started) as date) >= cast(date(sec_to_timestamp(<LAST_DATA_TIME>)) as date) 38 and cast(date(started) as date) < cast(current_date() as date) /* Drop results from partial day */ 39 and metadata.key = 'repos' 40 and length(regexp_replace(replace(metadata.value, ", ", ""), r'[^,]+', '')) = 1 41 and job in ( /* only consider merge-blocking jobs */ 42 'pr:pull-kubernetes-bazel-build', 43 'pr:pull-kubernetes-bazel-test', 44 'pr:pull-kubernetes-e2e-gce-etcd3', 45 'pr:pull-kubernetes-e2e-kops-aws', 46 'pr:pull-kubernetes-kubemark-e2e-gce', 47 'pr:pull-kubernetes-node-e2e', 48 'pr:pull-kubernetes-unit', 49 'pr:pull-kubernetes-verify', 50 ) 51 ) 52 group by day, job, commit 53 ) 54 group by day, commit 55 ) 56 group by day 57 order by day 58 59 jqfilter: | 60 ([(.[] | .day|tonumber)] | max) as $newestday | 61 [(.[] | select((.day|tonumber)==$newestday) | { 62 day: .day, 63 commit_consistency: (.commit_consistency|tonumber), 64 commits: (.commits|tonumber), 65 consistent_commits: (.consistent_commits|tonumber), 66 run_consistency: (.run_consistency|tonumber), 67 runs: (.runs|tonumber), 68 consistent_runs: (.consistent_runs|tonumber), 69 builds: (.builds|tonumber) 70 })] 71 72 measurements: 73 backfill: pr_consistency 74 jq: | 75 [(.[] | { 76 measurement: "pr_consistency", 77 time: (.day|tonumber), 78 tags: { 79 day: (.day|tonumber) 80 }, 81 fields: { 82 commit_consistency: (.commit_consistency|tonumber), 83 commits: (.commits|tonumber), 84 consistent_commits: (.consistent_commits|tonumber), 85 run_consistency: (.run_consistency|tonumber), 86 runs: (.runs|tonumber), 87 consistent_runs: (.consistent_runs|tonumber), 88 builds: (.builds|tonumber) 89 } 90 })]