• Stars
    star
    100
  • Rank 330,150 (Top 7 %)
  • Language
    Python
  • Created over 6 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Util script(s) to scrape data from git repositories to help teams improve.

Git Metrics

You can use the scripts in this repository to analyse another git repository for metrics such as lead time and open branches. You should clone the repository you wish to analyse, to a local directory before using these scripts. Some of the metrics, require there to be annotated tags on some of the commits.

Quick Start

Using python 3.7 or greater:

pip install -r requirements.txt

There are two scripts for calculating metrics (which may be combined into one soon). To find out how to use them:

python calculate_four_metrics.py --help
python git-metrics.py --help

Throughput metrics: Deployment Lead Time and Deploy Interval

Throughput metrics will help you to assess the length of your development cycle. That is, how quickly you can get changes that have been committed in version control, deployed and in front of users.

Deployment lead time is defined as the time taken from commit to deploy. In practice you often have more than one commit included in each deployment, so you might want to take an average as well as track the size of the range from oldest to newest. Deploy Interval is the average length of time between deployments.

In order to measure 'throughput' metrics, your repository will need to contain an annotated tag on each commit that was deployed. (Note, git also supports lightweight tags, but these lack any metadata and cannot be used for calculating throughput metrics). The tag needs to have the 'taggerdate' set to be the time the deploy happened. It is also convenient if you can name the deploy tags in such a way as you can write a simple matcher that will filter them out. For example, you could prepend every deployment tag with 'D-' (for 'Deploy'), then filter out all such tags with the fnmatch 'D-*'.

For example, to see all the tags you already have, you could use this command:

git for-each-ref --sort=taggerdate --format '%(refname) %(taggerdate)' refs/tags

If you need to add a deploy tag at a different time than the deployment, but don't want to mess up your metrics, you can set the time of a tag using an environment variable like this:

GIT_COMMITTER_DATE="Thu Jan 11 12:00:00 2019 +0100" git tag -a D-1.1.0 -m"Deployment 1.1.0"

That command will add a tag to the current HEAD commit with name 'D-1.1.0', with a 'taggerdate' set to midday CET on January 11th, 2019.

Once you have your repository annotated with tags for each deployment, you can use these scripts to calculate metrics. You might find it helpful to visualize the ages of all the commits in all the deployments in a specific time period. These scripts can produce a graph like this:

Example of release lead time in https://github.com/jenkinsci/configuration-as-code-plugin

Use a command like this to produce the raw data for this graph and store it in a csv file:

python git_metrics.py release-lead-time [--tag-pattern=<fn_match>] [--earliest-date=<timestamp>] <path_to_git_repo> > repo_data.csv

You can then plot this data with this command:

python git_metrics.py plot --release-lead-time <csv_file>

You can also print out average values for both release lead time and release interval like this:

calculate_four_metrics.py lead-time [--deploy-tag-pattern=<fn_match>] [--start-date=<timestamp>] <path_to_git_repo>
calculate_four_metrics.py deploy-interval [--deploy-tag-pattern=<fn_match>] [--start-date=<timestamp>] <path_to_git_repo>

For more information about how to install these scripts, see below under 'Installation'

Stability metrics: Mean time to Recover and Change Failure Rate

Stability metrics will help you assess how successful you are at avoiding bugs and having your service available for users. That is, how often do you need to patch your software, and how rapidly can you do so when needed.

Mean time to Recover is defined in these scripts as the time from when a bad deployment is made, until this is corrected via deployment of a patch. Change fail rate is defined as the proportion of deployments that are patches.

In order to measure 'stability' metrics, your repository will need to contain an annotated tag on each deployed commit that was a patch. (Note, git also supports lightweight tags, but these lack any metadata and cannot be used for calculating stability metrics). The tag needs to point at a commit that also has a 'deploy' tag as described in the previous section. The date of the patch tag is not significant. It is convenient if you can name the patch tags in such a way as you can write a simple matcher that will filter them out. For example, you could prepend every patch tag with 'P-' (for 'Patch'), then filter out all such tags with the fnmatch 'P-*'.

If you want to add a patch tag to a commit that has been deployed, and already has the tag 'D-1.1.1', you could do it like this:

git checkout D-1.1.1
git tag -a P-1.1.1 -m"Patch with version 1.1.1"

You can also print out average values for both mean time to recover and change failure rate like this:

calculate_four_metrics.py recovery-time [--deploy-tag-pattern=<fn_match>] [--patch-tag-pattern=<fn_match>] [--start-date=<timestamp>] <path_to_git_repo>
calculate_four_metrics.py change-fail-rate [--deploy-tag-pattern=<fn_match>] [--patch-tag-pattern=<fn_match>] [--start-date=<timestamp>] <path_to_git_repo>

Open branches

Open branches gathers information about the age of all commits in a branch that is not yet merged into the master branch. This can help visualize how much value is not yet integrated into the project, or the potential merge cost of all code that is not yet shared between developers.

Example of open branches in https://github.com/jenkinsci/configuration-as-code-plugin

Use these script commands to produce this kind of graph:

git_metrics.py open-branches [--master-branch=<branch>] <path_to_git_repo> > my_repo.csv
git_metrics.py plot --open-branches my_repo.csv

Installation

Requirement: Python 3.7 or later

To install dependencies: pip install -r requirements.txt

for more help run: python git_metrics.py --help

Python 2 systems

Those OS with Python 2 as default, e.g. Ubuntu 17/16, you need to use pip and python explicitly if you didn't change the default:

Call the script with:

python3 git_metrics.py --help

Install pip3 if not already installed and configure dependencies with pip3, e.g. Ubuntu 16/17:

sudo apt-get install python3-pip
pip3 install -r requirements.txt

On Ubuntu you might also miss the python3-tk package if doing plots

sudo apt install python3-tk

Usage

Call script with

python3 git_metrics.py --help

which will show basic usage information like:

Calculate age of commits in open remote branches

Usage:
    git_metrics.py open-branches [--master-branch=<branch>] <path_to_git_repo>
    git_metrics.py open-branches [--master-branch=<branch>] --plot <path_to_git_repo>
    git_metrics.py release-lead-time [--tag-pattern=<fn_match>] [--earliest-date=<timestamp>] <path_to_git_repo>
    git_metrics.py release-lead-time --plot [--tag-pattern=<fn_match>] <path_to_git_repo>
    git_metrics.py plot --open-branches <csv_file>
    git_metrics.py plot --release-lead-time <csv_file>
    git_metrics.py batch --open-branches <path_to_git_repos>...
    git_metrics.py batch --release-lead-time [--earliest-date=<timestamp>] <path_to_git_repos>...
    git_metrics.py (-h | --help)

    Options:
        --master-branch=<branch>    example: origin/gh-pages
  • --plot parameter will open a GnuPlot plot, and will not will not save your data.
  • To save data use without plot and pipe to file for csv format: git_metrics.py release-lead-time <path_to_git-repo> > my-csv-file.csv
  • Use plot command to plot existing csv files, e.g. git_metrics.py plot --release-lead-time my-csv-file.csv
  • batch (undocumented)

Developer information

Run the self-tests using pytest:

pytest -v

More Repositories

1

helmsman

Helm Charts as Code
Go
1,343
star
2

LearnKubernetes

Notes and resources collected together to help learn Kubernetes. This will eventually become a tutorial and later a blog post for praqma website (hopefully!)
Shell
510
star
3

Network-MultiTool

Multi-arch multitool for container network troubleshooting.
Dockerfile
270
star
4

JenkinsAsCodeReference

This repository is intended for the reference Jenkins configuration as code as well as JobDSL library
Groovy
142
star
5

git-merge-driver

Example of how to configure a custom git merge driver
Shell
96
star
6

learn-traefik

This repository contains examples on using traefik reverse proxy.
85
star
7

praqma-jenkins-casc

Repository for our casc demo setup
Dockerfile
70
star
8

kubernetes-ebook

Kubernetes ebook by Kamran Azeem from Praqma
39
star
9

jira

Atlassian Software in Kubernetes (ASK) - Jira. This repository is no longer being maintained. Please see main README file.
Dockerfile
38
star
10

alpine-sshd

No frills, simple alpine based SSHD server
Dockerfile
29
star
11

AndroidAospInDocker

This is repository with a setup helps to build custom Android aosp images inside docker containers.
Shell
28
star
12

gradle-plugin-bootstrap

All you need to create a custom Gradle plugin
Groovy
26
star
13

smallstep-ca-demo

Demo showing how to provide a behind the firewall Certificate Authority for development environments.
Shell
25
star
14

windows-jenkins-slaves-with-packer

Provision and start Windows Jenkins build slaves using Packer and Terraform.
HCL
23
star
15

git-hooks

Ruby
21
star
16

confluence

Atlassian Software in Kubernetes (ASK) - Confluence. This repository is no longer being maintained. Please see main README file.
Dockerfile
20
star
17

Praqmatic-Automated-Changelog

A repository for PAC (Praqmatic Automated Changelog)
Ruby
20
star
18

DAME

DAME is the Dockerized Arcade Machine Emulator, allowing you to play old games on your laptop!
Shell
17
star
19

2git

A Groovy DSL to migrate from ClearCase to Git
Groovy
16
star
20

code-utils

Continuous Delivery utilities - small scripts and concepts used by in continuous delivery setups.
Groovy
14
star
21

bitbucket

Atlassian Software in Kubernetes (ASK) - Bitbucket. This repository is no longer being maintained. Please see main README file.
Dockerfile
14
star
22

memory-map-plugin

A repository for the memory-map-plugin
Java
13
star
23

staci

Containerizing the Atlassian tools stack. Jira, Confluence, Bamboo and a MySQL database.
Shell
12
star
24

ask

Helm and Helmsman charts for ASK. This repository is no longer being maintained. Please see main README file.
Shell
11
star
25

job-dsl-collection

Job DSL collection library
Groovy
9
star
26

pretested-integration-plugin

A generic pretest commit plugin for Jenkins CI
Java
7
star
27

artifactory-retention

Clone & Own solution for Artifactory Retention Policies
Groovy
7
star
28

atlassian-metrics

Groovy
6
star
29

traefik-bitbucker-docker-demo

A demo of a dockerized Bitbucket instance proxied with Traefik and automated SSL cert management.
Shell
6
star
30

deploy2docker

A tool-set to deploy docker-compose apps to a plain docker-compose server
Shell
6
star
31

questionnaire-engine

Containerized web application to create and analyze surveys
JavaScript
6
star
32

reveals

HTML
5
star
33

jobdsl-helpers

Collection of classes to simplify JobDSL snippets
Groovy
4
star
34

GodotDevOps

A summer project exploring contemporary software development and DevOps in a game dev setting
GDScript
4
star
35

jcasc-core

docker images to be used for jcasc powered jenkins
Dockerfile
4
star
36

praqmajutils

Praqma Java Utils
Java
4
star
37

native

Examples of Native Builds
4
star
38

rook-ask-demo

A demo for Code-Conf 2019 showing Rook and ASK
Shell
4
star
39

k8s-cloud-loadbalancer

The Load Balancer is now a separate repository instead of being a sub directory inside praqma/LearnKubernetes
Shell
4
star
40

jcasc-conf

Example wrapper for running Jenkins with prebuilt docker images with JCasC
Shell
3
star
41

sdelements-plugin

Jenkins plugin for SD Elements risk assessment tool by Security Compass
Java
3
star
42

VersionedBinaryArtifacts

A gradle plugin to allow a build be defined in a properties file
Groovy
3
star
43

tracey

Initial repo for the Tracey implementation
Groovy
3
star
44

git-artifact

Shell
3
star
45

vaultReference

This is a reference project on how to easily and fast get Vault up and run in a production ready setup.
Shell
3
star
46

gradle-docker-plugin

Groovy
3
star
47

jenkins4casc

Dockerfile repository for a Jenkins preconfigured with Jenkins Configuration as Code plugin
Dockerfile
3
star
48

AWSProvisionWithAnsible

Configure Docker devicemapper storage for AWS RHEL 7 instance using Ansible
Python
3
star
49

shared-pipeline

Repository with shared global pipeline libs. Usable within sandboxed objects
Groovy
2
star
50

drmemory-plugin

Java
2
star
51

logging-plugin

Java
2
star
52

PrometheusGrafana

This is a repository for the demo at the christmas workshop. People have asked for it as a repository. :)
Shell
2
star
53

packer-made-win-slave

Templates and tools to build Windows-based using packer
PowerShell
2
star
54

CodeCamp

Java
2
star
55

helmsman-demo

2
star
56

ngingo

A tiny web server that makes a point
Go
2
star
57

onboarding-as-code

Automating the onboarding process
Python
2
star
58

commit-message-parser

Collection of parsers to extract issues from commit messages
Java
2
star
59

AbstractVcsApi

Java
2
star
60

OctoCopDD

OctoCop (Traffic) Director for Docker
Shell
2
star
61

native-example-scons

C++
2
star
62

concourse-git-phlow

concourse wrapper for git-phlow
Go
2
star
63

metricviz

Code metrics visualization POC
Java
2
star
64

toggleR

A simple R package to read data from toggl
R
2
star
65

dcn-2018-introduction-to-k8s

Kamran's presentation / workshop on Day Of CloudNative 2018.
Shell
2
star
66

k8s-probes-demo

A small Docker image, and related files to demonstrate how kubernetes probes work
Shell
1
star
67

memory-map-examples

Repository to hold example projects for our memory map plugin
1
star
68

ansible4win-poc

Showcase for Ansible configuration and management of Windows nodes as build and test agents
Ruby
1
star
69

CI-with-HAProxy

Shell
1
star
70

MonKit-Plugin

Java
1
star
71

terraform-google-gke

Terraform modules for creating kubernetes clusters in Google cloud (GKE)
HCL
1
star
72

helm-echoserver

A simple Go echoserver built with Echo framework.
Go
1
star
73

drmemory-api

Java
1
star
74

simple-website

A very simple HTML website which is often needed during git/docker/kubernetes labs/demos
HTML
1
star
75

topdesk-linker

Java
1
star
76

native-example-bazel

C++
1
star
77

makeable-deployment-poc

POC for makeable
Shell
1
star
78

toggl-metric

R library to fetch toggl data and generic methods to handle it.
R
1
star
79

selenoid

This is a simple Selenoid example. Selenoid is basically selenium grid as containers. See https://aerokube.com/selenoid/.
Shell
1
star
80

jekyll

Docker built Jekyll image for building Praqma's website.
Shell
1
star
81

Matrix-Reloaded-Plugin

A Jenkins plugin to rebuild matrix builds
Java
1
star
82

First

Java
1
star
83

luci-gradle

Gradle plugin for Luci
Groovy
1
star
84

docker-gh-pages

Dockerfile for creating a docker container for building jekyll enabled Github pages.
Ruby
1
star
85

rqm-plugin

Java
1
star
86

tracey-rabbitmq-neo4j-bridge

Java
1
star
87

Docker-Birthday-3-Oslo

Repo to contain some helpful stuff related to Docker Birthday event - 2016
HTML
1
star
88

vcs-bridge-plugin

Java
1
star
89

dgoss-docker-image

Shell
1
star
90

MonKit

Java
1
star
91

ccanalyzer

Java
1
star
92

docker-linkchecker

Shell
1
star
93

praqma.github.io

The home of http://code.praqma.com. It's repo that will host documentation for all our development
CSS
1
star
94

file-pattern-scanner

Simple script that scans flat/plain text files for patterns predefined in rules
Groovy
1
star
95

yocto-build-container

Ubuntu-based Docker base image for building Yocto images
Dockerfile
1
star
96

makeable-deployment-poc-code

PHP code for makable repository
PHP
1
star
97

terraform-jenkins-artifactory

A terraform/packer setup to create a simple CI system
HCL
1
star
98

PlusBump

This project was previously known as by its temp name "Wincrementor". Content will be updated soon to match the new name.
Ruby
1
star
99

tracey-protocol-eiffel

Ericsson Eiffel protocol implementation for the Tracey framework
Java
1
star