No Pain Performance Tests for Your CI/CD

Jevgenij Melnik
Revel Systems Engineering Blog
4 min readDec 17, 2020

In nowadays fast-paced world and oversaturated universe of choices and alternatives, how one does not fall into abyss? — женьшень

Taking little steps towards a goal with constant feedback.. sounds lean. You wouldn’t want to invest into something grand when you are still finding your ways, but even then — when you do think you’ve found a way, it drags you down, is it worth investing even more? Who is to benefit?

You all heard how single responsibility is good for your code, so is for risk mitigation. So how do you deliver value quickly? Probably by refining the requirements and scoping your tasks.

Let’s talk performance-tests

Here at Revel we like to start with the business value, and it could be any of the benefits of having performance tests, to mention a few:

  • they could tell us how many people can shop online at the same time
  • they could tell us how many orders could be processed when our SEO kicks in and customer engagement spikes up
  • they could get us moving one step closer to the CI/CD we all dream about
  • or they could just give a good night rest for all the souls out there releasing new application versions right now

We would want to raise our confidence in the early stages, but it is never too late. Early — means lots of other things to care about, but doesn’t mean we would gamble and sacrifice one of the key principles of modern software development. What if I told you could write automated performance tests for your API in 5 minutes? Most likely all the QA Engineers would slaughter me right here- right now.

The simple use case for a task should not start from buying a product, hiring a dedicated resource, or taking a 2-week training. Not everyone can afford, or have time at hand, but that doesn’t mean we have to sacrifice 100% of the value we are getting writing performance tests. Remember — we want the feedback first. 80/20 rule, you know it all.

Let’s run performance-tests

A unit load test is testing a single unit in isolation, e.g. API /login endpoint.
A scenario load test is testing flows of interactions, e.g. creating an order.

For the sake of simplicity, let’s take an example PetStore OpenAPI / Swagger API for our performance tests, but rest assured — you can obviously target a GraphQL or any other HTTP APIs

Ok- we have 5 minutes or less :)

# copy gist index.js (script below)$ npm install -g npx
$ npx k6 run index.js
# to debug http errors
$ npx k6 run index.js --http-debug="full"

You should see the test results after you execute:
npx k6 run index.js

Let’s visualize performance-tests

To get full benefits of the test execution results, you can integrate with the best monitoring tools out there, including DataDog, Grafana, New Relic, AWS CloudWatch, or k6 Cloud Tests.

Here is an example of a Grafana dashboard, taken from the GrafanaLabs library of visualization dashboards built by fellow developers.

You could use the potential of the monitoring tools and take it further into setting up various alerts and triggers to figure out performance degradation in your application.

Let’s pipeline performance-tests

Once you are ready and want to enable your performance tests as part of your CI/CD pipeline, you can do it fairly straightforward. Please refer to full k6 integration with GitHub guide.

Another interesting step in your pipelines that could boost your confidence is the GitLab Pipelines k6 widget providing a simple diff for your merge requests, which could highlight performance degradation before merging requests to master. Another step closer to continuous integration and continuous delivery.

K6 is a relatively new tool in the spotlight, but it lives up to the expectations, doing simple things right, and is well supported with the best tools out there.

  • CLI tool with developer-friendly APIs. Allowing you to configure execution, environment, threshold
  • Scripting in JavaScript ES2015/ES6 — with support for local and remote modules
  • Checks and Thresholds — for goal-oriented, automation-friendly load testing
  • and more...

Check out their website and Github, it’s open-source. There is plenty of information, including beliefs around performance testing and various examples and tutorials.

--

--