snapd icon indicating copy to clipboard operation
snapd copied to clipboard

tests: add github KPIs script

Open maykathm opened this issue 6 months ago • 6 comments

The idea behind this script is to generate interesting data points of each PR merged in a given time frame. Once generated, then noteworthy metrics can be generated on the output json file trivially with jq. The script's help contains some example interesting jq queries.

This script collects data for each PR in a given time frame:

  • number of attempts on ci-tests.yaml before merging
  • merged timestamp
  • whether spread tests ran
  • whether nested tests ran
  • whether the PR was force merged
  • number of skipped tests (not counting variants)
  • total runtime across all attempts
  • runtime in first attempt
  • if the first attempt only included fundamental systems
  • total number of spread tests that ran in the PR (not counting retrys)

Example usage

$ ./github-kpis.sh --start '2026-05-02' --all > 2026-05-02.json
Fetching PRs merged between 2026-05-02 and now...                                                                                                                                             
PRs fetched: 8                                                                                                                                                                                
Fetching number of attempts for each PR...                                                                                                                                                    
Attempts progress: [##############################] 8/8                                                                                                                                       
Done.                                                                                                                                                                                         
Determining whether each PR was force merged...                                                                                                                                               
Force-merged progress: [##############################] 8/8                                                                                                                                   
Done.                                                                                                                                                                                         
Determining number of skipped tests for each PR...                                                                                                                                            
Skipped tests progress: [##############################] 8/8                                                                                                                                  
Done.                                                                                                                                                                                         
Calculating total runtime for each PR...                                                                                                                                                      
Runtime progress: [##############################] 8/8                                                                                                                                        
Done.                                                                                                                                                                                         
Calculating test totals for each PR...                                                                                                                                                        
Test totals progress: [##############################] 8/8                                                                                                                                    
Done.

https://warthogs.atlassian.net/browse/SNAPDENG-36830

maykathm avatar May 05 '26 17:05 maykathm

Thu Jun 4 19:13:05 UTC 2026

Spread tests skipped

github-actions[bot] avatar May 05 '26 17:05 github-actions[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 79.15%. Comparing base (6ef8a8e) to head (f160c7d). :warning: Report is 170 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17024      +/-   ##
==========================================
+ Coverage   79.04%   79.15%   +0.11%     
==========================================
  Files        1375     1374       -1     
  Lines      191012   192728    +1716     
  Branches     2465     2466       +1     
==========================================
+ Hits       150981   152562    +1581     
- Misses      30924    30993      +69     
- Partials     9107     9173      +66     
Flag Coverage Δ
unittests 79.15% <ø> (+0.11%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar May 19 '26 08:05 codecov[bot]

I have added some changes in order to fix the filter by dates and to reduce the amount of calls to the gh api. I see the total number of tests had 0 when I ran the queries, I still not sure if we are measuring properly that, and if we could avoid downloading all the artifacts which makes the process very slow.

sergiocazzolato avatar Jun 05 '26 13:06 sergiocazzolato

I have added some changes in order to fix the filter by dates and to reduce the amount of calls to the gh api. I see the total number of tests had 0 when I ran the queries, I still not sure if we are measuring properly that, and if we could avoid downloading all the artifacts which makes the process very slow.

Was the total number of 0 you saw for PRs that skipped spread? Those should all be 0. Just in local testing, the number of tests I see appears correct (though I need to manually check to make sure the numbers are effectively correct).

One alternative to downloading the spread-results json files is to parse the logs from each job. I originally discarded that approach since it was extremely slow in my local testing and resulted in many 500s. It requires going job by job since the logs are too large for a single API request.

We could also remove the total number of spread tests run if it's too problematic. Though if we run the script every day, it shouldn't be too bad.

maykathm avatar Jun 09 '26 07:06 maykathm

I ran the example command using --all.

I tried the example of your script, but 4 fields show up empty for all 181 PRs the script grabs, they are:

  • databaseId
  • total-runtime-minutes
  • first-attempt-minutes
  • fire-attempt-only-fundamental

I don't think all of these would be tagged to skip spread, so I think the error must be in the ensure_metadata() function, or the databaseId cannot be retrieved

Rnfudge02 avatar Jun 18 '26 16:06 Rnfudge02

The rest of the metrics work well

Rnfudge02 avatar Jun 18 '26 16:06 Rnfudge02