Introducing Gitlab Performance Reporter

Posted by Sander van Kasteel on February 07, 2020 · 590 words, 4 mins read

Categories:

What is Gitlab Performance Reporter ?

Gitlab Performance Reporter, is a tool I wrote to fit one of my own needs. For my blog and other static websites I maintain, I wanted to be able to track what the performance impact certain commits and MRs had or has.

“That’s all very nice, but doesn’t Gitlab has that natively ?”, I hear you ask. Yes it does, with one MAJOR catch. You need to be a ‘Silver’ or ‘Premium’ subscriber with Gitlab. For a lone developer like me, costs a pretty penny ($19 a month). Especially if you take into consideration, that I don’t use the rest of the functionality since I am a ‘lone’ developer. The rest of the functionality of Gitlab ‘Silver’ / ‘Premium’ all revolves around team functionalities, which I am clearly not.

So that’s why I made “Gitlab Performance Reporter”. It allows me to replicate 0.001% of functionality, which Gitlab ‘Silver’ / ‘Premium’ offers which is interesting to me personally without spending $19 a month, for just 0.001% of functionalty.

Technical aspects / architecture

It’s is written in Python 3.8 and is being offered for use in a Gitlab CI/CD pipeline by using Docker. Gitlab by default integrates with sitespeed.io for “Browser Performance Testing” and that is what I am trying to mimick here.

This whole application revolves around the comparing the output of the ‘sitespeed.io’ docker container (called performance.json) with output of a previous run. In the context of an Merge Request, this is comparing the perfomance.json of the target branch with the performance.json of the source branch. That difference in perfomance is then being relayed as a comment (notes in Gitlab API speak) on the Merge Request.

A preview screenshot of the functionality can be found at the end of this blogpost or a real life you can look at the MR which made this blogpost possible

Nice little detail, it is licensed under the MIT license ;-)

Usage

“Talk is cheap, show me the integration”.

Luckely it’s quite simple, all you need to do the following, implement everything according to Browser Performance Testing guide by Gitlab, generate a personal token and add the following snippet to your .gitlab-ci.yaml file and that’s it!

performance_reporter:
  stage: performance_report
  image: sandervankasteel/gitlab-performance-reporter:1.0.1
  dependencies:
    - performance
  script:
    - python /app/src/main.py --token $GITLAB_ACCESS_TOKEN

For a more in-depth guide checkout the readme.md

A full example of this can be found in the gitlab-ci.yml of my blog, please note that I use Netlify to deploy to and use the ‘deploy previews’ functionality to have a live preview and a benchmarkable environment to use this on.

What’s possibly next?

  • Integration with Lighthouse-ci and possible others
  • Configurable non-zero exit codes based on the percentage of failed metrics
  • Allow external markdown templates to be used

Screenshot

Screenshot comment MR

Support

Should run into any issues (since it’s currently at version 1.0.1), don’t hesitate to create an issue or have the Tweet birds do their thing through Twitter

Notes

Please note, this project is in no way affiliated with Gitlab, GitLab Inc or it’s subsidiaries.

The header image is made by Chris Reid and is available on Unsplash.