Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Add view-release-stats utility to see lead time by release and in window#28

Closed
jessemortenson wants to merge 2 commits intomainfrom
add-view-release-stats
Closed

Add view-release-stats utility to see lead time by release and in window#28
jessemortenson wants to merge 2 commits intomainfrom
add-view-release-stats

Conversation

@jessemortenson
Copy link

@jessemortenson jessemortenson commented Nov 10, 2022

Adds a utility script to view release statistics (eg lead time).

I wanted to examine some of the commit->release lead time by hand, to see what data in recent releases looks like and compare to the Average Time from Commit to Release stat we currently collect in Grafana.

Usage examples:

python view-release-stats.py -c config.yml -w 30 --timestamp 1665360585

Analyzed 7 releases found in 30 days before 2022-10-10 00:09:45
Average lead time in hours: 205
Median lead time in hours: 68
python view-release-stats.py -c config.yml -w 30

Analyzed 8 releases found in 30 days before 2022-11-10 00:10:48.963188
Average lead time in hours: 145
Median lead time in hours: 74

Also includes per-release output for each release in the window, like:

enview/v0.168.2 on 2022-11-04T20:06:25+00:00 by NewAgeAirbender
Average delta for release, in hours: 18
Median delta for release, in hours: 23

logger.log(logging.INFO, f"{release['tag_name']} on {release_date_in_utc} by {release['author']['login']}")

if (last_release):
commit_times_output = subprocess.check_output(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step should be a function in github_stats/gitops.py to:

  1. leverage the existing auth that we're using with pygit2
  2. make the pattern consistent
  3. allow for more consistent error handling

delta_in_minutes = get_time_delta_in_minutes_from_iso_strings(release_date_in_utc, commit_time)
deltas_in_minutes.append(delta_in_minutes)
total_delta += delta_in_minutes
release_average_delta_in_hours = round(total_delta / 60 / len(commit_times))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic numbers aren't great. If we can either add comments explaining them or use a variable instead...

release_average_delta_in_hours = round(total_delta / 60 / len(commit_times))
release_median_delta_in_hours = round(statistics.median(deltas_in_minutes) / 60)
lead_time_msg = "lead time for commit in release, in hours"
logger.log(logging.INFO, f"Average {lead_time_msg}: {release_average_delta_in_hours}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.info instead of logger.log(logging.INFO, is the standard format for log messages.

all_releases_total_delta_in_minutes = 0
all_releases_total_commits = 0
for release in releases:
release_date_in_utc = release['published_at'].rstrip('Z') + '+00:00' # datetime.fromisoformat hates the Z
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should see if another library doesn't hate the Z to avoid a brittle string comparison here.

release_date_in_utc = release['published_at'].rstrip('Z') + '+00:00' # datetime.fromisoformat hates the Z
logger.log(logging.INFO, f"{release['tag_name']} on {release_date_in_utc} by {release['author']['login']}")

if (last_release):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No parentheses when there's no need.

releases = []
for release in gh.return_releases(timestamp, args.window):
releases.append(release)
releases.reverse() # Reverse so we have chronological
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the return_releases function handle the reverse instead? Or even make that a switch (e.g. return_releases(timestamp, args.window, reverse=True)) that we could use?

starttime = time.time()
gh = GithubAccess(local_config)
last_release = None
releases = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably just be releases = return_releases(timestamp, args.window) instead of a loop.

@johnseekins
Copy link
Contributor

Being re-worked in #35

@johnseekins johnseekins closed this Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants