Skip to content

Commit

Permalink
initial version of Chaos AI (#606)
Browse files Browse the repository at this point in the history
* init push

Signed-off-by: Sandeep Hans <[email protected]>

* remove litmus + updated readme

Signed-off-by: Sandeep Hans <[email protected]>

* remove redundant files

Signed-off-by: Sandeep Hans <[email protected]>

* removed generated file+unused reference

---------

Signed-off-by: Sandeep Hans <[email protected]>
Co-authored-by: Naga Ravi Chaitanya Elluri <[email protected]>
  • Loading branch information
sandeephans and chaitanyaenr authored Apr 16, 2024
1 parent 804d7cb commit 19ad2d1
Show file tree
Hide file tree
Showing 24 changed files with 1,383 additions and 0 deletions.
39 changes: 39 additions & 0 deletions utils/chaos_ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# aichaos
Enhancing Chaos Engineering with AI-assisted fault injection for better resiliency and non-functional testing.

## Generate python package wheel file
```
python3.9 generate_wheel_package.py sdist bdist_wheel
```
This creates a python package file aichaos-0.0.1-py3-none-any.whl in the dist folder.

## Build Image
```
cd docker
podman build -t aichaos:1.0 .
OR
docker build -t aichaos:1.0 .
```

## Run Chaos AI
```
podman run -v aichaos-config.json:/config/aichaos-config.json --privileged=true --name aichaos -p 5001:5001 aichaos:1.0
OR
docker run -v aichaos-config.json:/config/aichaos-config.json --privileged -v /var/run/docker.sock:/var/run/docker.sock --name aichaos -p 5001:5001 aichaos:1.0
```

The output should look like:
```
$ podman run -v aichaos-config.json:/config/aichaos-config.json --privileged=true --name aichaos -p 5001:5001 aichaos:1.0
* Serving Flask app 'swagger_api' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5001
* Running on http://172.17.0.2:5001
```

You can try out the APIs in browser at http://<server-ip>:5001/apidocs (eg. http://127.0.0.1:5001/apidocs). For testing out, you can try “GenerateChaos” api with ‘kubeconfig’ file and application URLs to test.
Empty file.
21 changes: 21 additions & 0 deletions utils/chaos_ai/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM bitnami/kubectl:1.20.9 as kubectl
FROM python:3.9
WORKDIR /app
RUN pip3 install --upgrade pip
COPY config config/
COPY requirements.txt .
RUN mkdir -p /app/logs
RUN pip3 install -r requirements.txt

COPY --from=kubectl /opt/bitnami/kubectl/bin/kubectl /usr/local/bin/

COPY swagger_api.py .
ENV PYTHONUNBUFFERED=1

RUN curl -fsSLO https://get.docker.com/builds/Linux/x86_64/docker-17.03.1-ce.tgz && tar --strip-components=1 -xvzf docker-17.03.1-ce.tgz -C /usr/local/bin

RUN apt-get update && apt-get install -y podman

COPY aichaos-0.0.1-py3-none-any.whl .
RUN pip3 install aichaos-0.0.1-py3-none-any.whl
CMD ["python3", "swagger_api.py"]
7 changes: 7 additions & 0 deletions utils/chaos_ai/docker/aichaos-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"command": "podman",
"chaosengine": "kraken",
"faults": "pod-delete",
"iterations": 1,
"maxfaults": 5
}
15 changes: 15 additions & 0 deletions utils/chaos_ai/docker/config/experiments/log.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Get Log from the Chaos ID.---
tags:
- ChaosAI API Results
parameters:
- name: chaosid
in: path
type: string
required: true
description: Chaos-ID
responses:
500:
description: Error!
200:
description: Results for the given Chaos ID.
36 changes: 36 additions & 0 deletions utils/chaos_ai/docker/config/pod-delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"apiVersion": "1.0",
"kind": "ChaosEngine",
"metadata": {
"name": "engine-cartns3"
},
"spec": {
"engineState": "active",
"annotationCheck": "false",
"appinfo": {
"appns": "robot-shop",
"applabel": "service=payment",
"appkind": "deployment"
},
"chaosServiceAccount": "pod-delete-sa",
"experiments": [
{
"name": "pod-delete",
"spec": {
"components": {
"env": [
{
"name": "FORCE",
"value": "true"
},
{
"name": "TOTAL_CHAOS_DURATION",
"value": "120"
}
]
}
}
}
]
}
}
40 changes: 40 additions & 0 deletions utils/chaos_ai/docker/config/yml/chaosGen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

Generate chaos on an application deployed on a cluster.
---
tags:
- ChaosAI API
parameters:
- name: file
in: formData
type: file
required: true
description: Kube-config file
- name: namespace
in: formData
type: string
default: robot-shop
required: true
description: Namespace to test
- name: podlabels
in: formData
type: string
default: service=cart,service=payment
required: true
description: Pod labels to test
- name: nodelabels
in: formData
type: string
required: false
description: Node labels to test
- name: urls
in: formData
type: string
default: http://<application-url>:8097/api/cart/health,http://<application-url>:8097/api/payment/health
required: true
description: Application URLs to test

responses:
500:
description: Error!
200:
description: Chaos ID for the initiated chaos.
15 changes: 15 additions & 0 deletions utils/chaos_ai/docker/config/yml/episodes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Get Episodes from the Chaos ID.---
tags:
- ChaosAI API Results
parameters:
- name: chaosid
in: path
type: string
required: true
description: Chaos-ID
responses:
500:
description: Error!
200:
description: Results for the given Chaos ID.
15 changes: 15 additions & 0 deletions utils/chaos_ai/docker/config/yml/log.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Get Log from the Chaos ID.---
tags:
- ChaosAI API Results
parameters:
- name: chaosid
in: path
type: string
required: true
description: Chaos-ID
responses:
500:
description: Error!
200:
description: Results for the given Chaos ID.
15 changes: 15 additions & 0 deletions utils/chaos_ai/docker/config/yml/qtable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Get QTable from the Chaos ID.---
tags:
- ChaosAI API Results
parameters:
- name: chaosid
in: path
type: string
required: true
description: Chaos-ID
responses:
500:
description: Error!
200:
description: Results for the given Chaos ID.
15 changes: 15 additions & 0 deletions utils/chaos_ai/docker/config/yml/status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Get status of the Constraints ID.---
tags:
- ChaosAI API
parameters:
- name: chaosid
in: path
type: string
required: true
description: Chaos-ID
responses:
500:
description: Error!
200:
description: Chaos for the given ID.
6 changes: 6 additions & 0 deletions utils/chaos_ai/docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
numpy
pandas
requests
Flask==2.1.0
Werkzeug==2.2.2
flasgger==0.9.5
Loading

0 comments on commit 19ad2d1

Please sign in to comment.