DEV Community

mikotian
mikotian

Posted on

1

Running a simple chaos toolkit experiment

Install Chaos Toolkit & required drivers as mentioned here:

  1. Setting up ChaosToolkit Execution Environment

Make sure the virtual environment is activated.

Create the following file:

{
  "version": "1.0.0",
  "title": "random website testing",
  "description": "Just checking the chaostoolkit base stuff",
  "steady-state-hypothesis": {
    "title": "Website is OK",
    "probes": [
      {
        "type": "probe",
        "name": "website-must-be-up",
        "tolerance": 200,
        "provider": {
          "type": "http",
          "timeout": [
            3,
            5
          ],
          "url": "https://httpbin.org/forms/post",
          "method": "GET"
        }
      }
    ]
  },
  "method": [
    {
      "type": "probe",
      "name": "website-must-return-202",
      "tolerance": 202,
      "provider": {
        "type": "http",
        "url": "https://httpbin.org/status/202"
      }
    },
    {
      "type": "probe",
      "name": "response should be json",
      "tolerance": {
        "type": "jsonpath",
        "path": "$.slideshow.author",
        "expect": [
          "failed"
        ],
        "target": "body"
      },
      "provider": {
        "type": "http",
        "url": "https://httpbin.org/json"
      }
    }
  ],
  "rollbacks": []
}
Enter fullscreen mode Exit fullscreen mode

Running the experiment:

chaos run SimpleExperiment.json
Enter fullscreen mode Exit fullscreen mode

ScreenGrab:

The same can be run in a Jenkins Pipeline:

The jenkins pipeline script is as follows:

pipeline {
    agent any

    stages {
        stage('Deploy') {
            steps {
                // Get some code from a GitHub repository
                git 'https://github.com/mikotian/resilientchaos.git'

            }

            post {
                success {
                    echo 'Hello World'
                }
            }
        }
        stage('Run Chaos Script') {
            steps {

                sh ". /home/mithun/.venvs/chaostk/bin/activate && chaos run SimpleExperiment.json"
            }

            post {
                success {
                    echo 'Success'
                }
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

The execution looks like this:

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay