TIP
🔥 Checkout the Azure Developer page at azure.com/developer (opens new window).
💡 Learn more : What is Azure Chaos Studio (opens new window).
📺 Watch the video : How to test for resilience with Azure Chaos Studio (opens new window).
# How to test for resilience with Azure Chaos Studio
# Prepare your app for chaos
When you run a mission-critical application, it needs to stay up and running in every circumstance. It could be that its cache is unavailable, that the database fails or that the connection to another service is temporarily blocked. The application should be able to deal with all of these circumstances. But how do you test for that? Azure Chaos Studio (opens new window) can help, by using chaos engineering and fault injection to create real-world chaos. This helps you to understand and improve your application and infrastructure resilience, to keep it up and running when things go wrong.
In this post, we'll use Azure Chaos Studio (opens new window) to target Azure Cache for Redis (opens new window) that is used by an existing website.
# Prerequisites
If you want to follow along, you'll need the following:
- An Azure subscription (If you don't have an Azure subscription, create a free account (opens new window) before you begin)
- An existing application that uses Azure Cache for Redis. You can create one with this tutorial (opens new window)
# Configure and use Azure Chaos Studio
You can use Azure Chaos Studio to create chaos experiments that test the resilience of your applications. To get started, we first need to make sure that the chaos resource provider is registered for our Azure subscription.
- Go to the Azure portal (opens new window)
- Click on the menu on the top left and select Subscriptions
- Select the Azure subscription that you want to use for Azure Chaos Studio
- In the subscription, navigate to the Resource providers menu
- In the "Filter by name..." field, enter "Chaos"
- You'll find the Microsoft.Chaos resource provider. If the Status is NotRegistered, select it and click Register to register the provider
(Register the Microsoft.Chaos resource provider)
Next, we need to enable targets for Chaos Studio. This enables Azure resources to be directed and monitored by Azure Chaos Studio. Some resources can be enabled directly and others, like VMs, can be enabled with agents.
- In the Azure portal, search for Chaos Studio and select the result. This will open Azure Chaos Studio
- Click on the Targets menu. Here you'll see the Azure resources that can be enabled and used by Azure Chaos Studio
- Select the Azure Cache for Redis that you want to use. Click on Enable targets > Enable service-direct targets
- Next, select the Azure Cache for Redis again. This opens the Manage actions menu which allows you to enable the capabilities that Chaos Studio has for the resource
- Select Azure Cache for Redis (Reboot) and click Save
(Enable Chaos Studio targets)
Now that we have targets for Chaos Studio, we can create an experiment. A chaos experiment consists of actions that are executed against targets in one or more steps.
- In Azure Chaos Studio, click on the Experiments menu
- Click Add an experiment
- Select a Resource Group
- Enter a Name for the experiment
- Select a Location
- Click Next: Experiment designer
- We'll create one step with one branch
- Click Add Action and Add Fault after that
- Create a new fault by selecting Azure Cache for Redis (Reboot). There are many faults that can be used by Chaos Studio. You can find a list of them here (opens new window)
- Select Unknown for rebootType
- Click Next: Target resources
- Next, select the Azure Cache for Redis as the target for this fault and click Add
- Click Create to create the experiment
(Create a Chaos Experiment)
Before we can start the experiment, we need to allow it to execute faults on the target Azure Cache for Redis. This step is built in so that we don't accidentally create chaos in the wrong applications.
- Navigate to the Azure Cache for Redis
- Click on the Access Control (IAM) menu
- Select Add role assignment
- We will assign the chaos experiment the Contributor role. So click Contributor and click Next
- For Assign access to, select Managed identity
- Click Select members
- In the Managed identity dropdown, select Chaos Experiment, and select the experiment that we just created
- Click Select to add the experiment as a member
- Now click Review + assign to assign the role to Azure Cache for Redis
(Add role assignment to Azure Cache for Redis)
Everything is in place to start the chaos experiment.
- Go back to Azure Chaos Studio and select the experiment
- Click Start to run the experiment
- After a while, the experiment results will be visible. Click on the details link to see the results. This shows the steps, branches and faults that were executed and if they succeeded or failed. In our case, the fault rebooted the Azure Cache for Redis
(The experiment ran successfully)
- Additionally, you can investigate the resources that are affected by the experiment. In our case, the Azure Cache for Redis is used by a website that runs in an Azure App Service Web App, which has Application Insights enabled. With that, we can see that its availability wasn't affected by the experiment, which is the outcome that we want
(The Web App availability is unaffected)
# Conclusion
Azure Chaos Studio (opens new window) is a great tool to model and execute real-world chaos for your applications by injecting many types of faults (opens new window) into your solution. You can use this to test and improve the resilience of your applications and infrastructure. Go and check it out!