NashTech Blog

Practicing Chaos Engineering in Testing

Table of Contents

In today’s fast-paced digital world, ensuring the reliability and resilience of cloud applications is crucial. Azure Chaos Studio, a powerful tool from Microsoft, helps developers and IT professionals test and improve their applications’ ability to withstand unexpected disruptions. This guide explores the fundamentals of chaos engineering, its importance, and how to use Azure Chaos Studio for conducting chaos experiments on Azure resources.

1. Introduction

What is chaos engineering?

Chaos engineering intentionally introduces controlled failures or stresses into a system to test its resilience. It simulates real-world scenarios that might not be predictable in traditional testing. The main goals are to:

  • Identify weaknesses before they cause problems
  • Build confidence in the system’s ability to withstand disruptions
  • Improve overall resilience and reliability

Why practicing Chaos Engineering matters:

Chaos Engineering identifies system weaknesses by simulating disruptions, prepare your infrastructure for real-world scenarios. This practice can:

  • Improve Resilience: Find and fix hidden vulnerabilities before they impact users.
  • Enhance Response: Prepare your team to handle actual outages.
  • Boost Confidence: Validate system reliability for stakeholders and users.

What is Azure Chaos Studio?

Azure Chaos Studio is a fully managed service for chaos engineering on Azure. It allows you to:

  • Create controlled chaos experiments on Azure resources
  • Simulate failures like service outages, network latency, or resource exhaustion
  • Observe your applications’ responses to these failures
  • Gain insights to improve system resilience

Key features include:

  • Fault injection: Introduce specific faults into your system
  • Experiment designer: Create and manage experiments
  • Targeting: Select specific resources or groups of resources for testing
  • Scheduling: Run experiments on a schedule
  • Monitoring and analytics: Observe experiment impacts on your system

How it works?

Now you might understand what Azure Chaos Studio is, but how exactly does it work? Let’s break it down.

  • Defining Targets: First, you select the Azure resources you want to test. These could be virtual machines, databases, or entire application stacks.
  • Creating Experiments: Next, you design experiments using the Chaos Studio interface. An experiment is a series of “faults” or disruptions you want to introduce to your system.
  • Choosing Faults: Azure Chaos Studio offers a variety of pre-defined faults, such as CPU stress, Memory pressure, Network latency, etc.
  • Scheduling: You can run experiments on-demand or schedule them to run at specific times.
  • Execution: When an experiment runs, Chaos Studio introduces the specified faults to your targeted resources
  • Monitoring: During the experiment, you monitor your application’s behavior using Azure’s native monitoring tools or your own monitoring stack.
  • Analysis: After the experiment, you analyze the results to understand how your system performed under stress.
  • Improvement: Based on the insights gained, you can make improvements to your system’s resilience.

2. Practicing Azure Chaos Studio

Before working with Azure Chaos Studio, we need to set up the environment and build a project for practicing.

Step 1: Set Up Your Environment

1.1 Prerequisites:

  • Azure Subscription: Ensure you have an active Azure subscription. If you don’t have one, click here to create an account.
  • Choose an Open-Source Project: Select an open-source project designed for testing. For this tutorial, we’ll use the SpringPetClinic project. (Click here to find more information about this project.)
  • Azure CLI: Install Azure CLI to interact with Azure services from your terminal.
  • Maven: Ensure Maven is installed to build the SpringPetClinic project.

1.2 Build the Project:

  • Clone the SpringPetClinic Repository: Open Windows PowerShell (WPS) and run this command:

git clone https://github.com/spring-projects/spring-petclinic.git

  • Build the Project: Run these commands

cd spring-petclinic
./mvnw package

Step 2: Deploy the SpringPetClinic Project to Azure

2.1 Create a Resource Group:

  1. Go to the Azure portal, click on Resource group in the left sidebar, then click on + Create.
  2. Fill in the required fields:
    • Subscription: Select your subscription.
    • Resource group: Enter myResourceTest.
    • Region: Select your preferred location.
  3. Click Review + Create and then Create.

2.2 Create an Azure App Service Plan:

  1. Click on App Services in the left sidebar, then click on + Create and select Web App.
  2. Fill in the required fields:
    • Subscription: Select your subscription.
    • Resource Group: Select myResourceTest.
    • Name: Enter a unique name for your web app, mySpringPetClinic.
    • Publish: Select Code.
    • Runtime stack: Select Java 11
    • Operating System: Select Windows.
    • Region: Select your preferred location (For practicing, select East US).
    • App Service Plan: Click on Create new, enter myAppServicePlan, and select the pricing tier (For practicing, select PricingPlan F1).
  3. Click Review + Create and then Create.

2.3 Create a Web App:

Open WPS and run this command:

az webapp create --resource-group <your resource>--plan <Your app plan> --name <Your app name> --runtime "java|11-java11"

Replace these parameters:
--resource-group : myResourceTest
--plan: myAppServicePlan
-- name: mySpringPetClinic

Notice that this project requires JDK version 11 and upper. In this practice, using Java 11.

2.4 Deploy the Application:

Open WPS and run this command:

az webapp deploy --resource-group <your resource>--name <Your app name>--src-path <your part> 

Replace these parameters:
--resource-group : myResourceTest
--name: mySpringPetClinic
-- src path: C:\Users\<your-username>\spring-petclinic\target\spring-petclinic-3.3.0-SNAPSHOT.jar

Step 3: Set Up Azure Chaos Studio

3.1 Register the Chaos Studio Provider:

  1. Go to the Azure portal, click on Subscriptions, and then select the subscription you want to use for Chaos Studio.
  2. In the subscription overview page, find the Settings section and click on Resource Providers.
  3. In the Resource Providers list, type Microsoft.Chaos in the search box to find the Chaos Studio provider. Then click on the Register button.

3.2 Create a Chaos Experiment:

  1. In the Chaos Studio interface, click on Experiments in the left sidebar.
  2. Click on + Add to create a new chaos experiment.
  3. Fill in the required fields:
    • Experiment name: Enter a name for your experiment (e.g., Stop App Service).
    • Resource Group: Select SpringPetClinicResourceGroup.
  4. Click Next to configure the experiment steps.

Step 4: Configure Chaos Targets

4.1 Add Target Resources:

Select the SpringPetClinic Web App as your target resource. Ensure you have added the appropriate permissions for Chaos Studio to manage the resource.

4.2 Define Chaos Actions:

Define chaos actions like CPU pressure, memory pressure, or network latency to simulate various failure scenarios. For this practice case, choose Stop App Service.

Step 5: Run and Analyze Chaos Experiments

5.1 Start the Experiment:

After configuring your experiment, start it from the Azure portal. Monitor the experiment’s progress and observe how the SpringPetClinic application responds to the induced faults.

5.2 Analyze the Results:

Evaluate the results of the experiment. Use monitoring tools to collect data on system performance and identify any failures. Use these insights to improve the resilience of the SpringPetClinic application. In this step, you should implement changes to improve resilience and re-run experiments to verify improvements.

Chaos engineering with Azure Chaos Studio helps you build more resilient systems by proactively identifying and addressing weaknesses. By following the steps in this blog, you can start practicing chaos engineering on your own projects and improve their robustness.

Resources:

Picture of Nga Le (Rose)

Nga Le (Rose)

A tester who is in the process of evolving into a well-rounded individual.

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

Scroll to Top