Chaos Engineering with Redis
Introduction
Gremlin is a simple, safe and secure service for performing Chaos Engineering experiments through a SaaS-based platform. Redis is an open source in-memory data structure store. Datadog is a monitoring service for cloud-scale applications, providing monitoring of servers, databases, tools, and services, through a SaaS-based data analytics platform. Datadog provides an integration to monitor Redis.
Chaos Engineering Hypothesis
For the purposes of this tutorial we will run Chaos Engineering experiments on Redis. Our Chaos Engineering hypothesis is that we need to constantly ensure we are monitoring latency and crash frequency as these are common issues that can appear when running Redis in production. To begin with, view the guide on Problems With Redis published by the Redis team.
Latency measures the average time in milliseconds it takes the Redis server to respond. Typical Redis latency for a 1GBits/s network is about 200 μs. Tracking latency is the most useful way to see impacts to Redis performance.
We know from the official Redis Cluster documentation that a Redis Cluster does not guarantee strong consistency. This tutorial will focus on doing Chaos Engineering with one Redis instance. In a future tutorial we will focus on Redis Cluster.
Prerequisites
To complete this tutorial you will need the following:
- 1 cloud infrastructure instance running Ubuntu 16.04
- A Gremlin account (sign up here)
- A Datadog account
Overview
This tutorial will walk you through the required steps to do Chaos Engineering with Redis.
- Step 1 - Creating a Redis server
- Step 2 - Installing Docker on each host
- Step 3 - Installing Gremlin in a Docker container on each host
- Step 4 - Installing Datadog in a Docker container on each host
- Step 5 - Running the Redis Latency Chaos Engineering experiment
- Step 6 - Additional Chaos Engineering experiments you can run with Gremlin
Step 1 - Creating a Redis server
First update the server:
To compile Redis, run the following commands:
Now start redis by running the following command:
A successful result will end with:
Now use the redis cli to confirm you can connect:
You will see the following as a successful result:
Now type the following at the redis prompt:
The successful result will be
Now type the following to store data in Redis:
The successful result will be:
Now type the following to retrieve your stored data:
The successful result will be:
Now exit the Redis prompt:
Restart Redis:
Now use the redis cli:
Type the following at the redis cli prompt to return the data you stored previously:
You will see the following if it is successfully returned:
Now exit the Redis prompt:
Step 2 - Installing Docker
In this step, you’ll install Docker.
Add Docker’s official GPG key:
Use the following command to set up the stable repository.
Update the apt package index:
Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:
Install the latest version of Docker CE:
Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it is running:
Type <span class="code-class-custom">q</span> to return to the prompt.
Make sure you are in the Docker usergroup, replace redis with your username:
Step 3 - Installing Gremlin On Each Host
After you have created your Gremlin account (sign up here) you will need to find your Gremlin Daemon credentials. Login to the Gremlin App using your Company name and sign-on credentials. These were emailed to you when you signed up to start using Gremlin.
Navigate to Team Settings and click on your Team.
Store your Gremlin agent credentials as environment variables, for example:
Next run the Gremlin Daemon in a Container.
Use docker run to pull the official Gremlin Docker image and run the Gremlin daemon:
Use docker ps to see all running Docker containers:
Jump into your Gremlin container with an interactive shell (replace b281e749ac33 with the real ID of your Gremlin container):
From within the container, check out the available attack types:
Step 4 - Installing the Datadog agent in a Docker container
To install Datadog in a Docker container you can use the Datadog Docker easy one-step install.
Run the following command, replacing the item in red with your own API key:
It will take a few minutes for Datadog to spin up the Datadog container, collect metrics on your existing containers and display them in the Datadog App.
Step 5 - Running the Redis Latency Chaos Engineering Experiment
We will use the Gremlin CLI attack command to create a latency attack.
Now use the Gremlin CLI (gremlin) to run a latency attack against the host from a Gremlin container:
This attack will inject latency to the Redis host.
Now exit the container by running the following command:
Step 6 - Additional Chaos Engineering experiments to run on Redis
There are many Chaos Engineering experiments you could possibly run on your Redis infrastructure:
- Monitoring - do your monitoring tools enable you to monitor changes in Redis latency?
- Time Travel Gremlin - will changing the clock time of the host impact how Redis processes data?
- Latency & Packet Loss Gremlins - will they impact the ability to use Redis
- Disk Gremlin - will filling up the disk crash the host?
We encourage you to run these Chaos Engineering experiments and share your findings! To get access to Gremlin, sign up here.
Conclusion
This tutorial has explored how to install Redis and Gremlin in Docker containers for your Chaos Engineering experiments. We then ran a shutdown Chaos Engineering experiment on the Redis container using the Gremlin Latency attack.
Avoid downtime. Use Gremlin to turn failure into resilience.
Gremlin empowers you to proactively root out failure before it causes downtime. See how you can harness chaos to build resilient systems by requesting a demo of Gremlin.