Skip to main content

Site24x7 Labs Chaos SDK for Python — inject realistic faults into Flask and FastAPI applications

Project description

Site24x7 Labs Chaos SDK for Python

Inject realistic application-level faults into Python/Flask and Python/FastAPI microservices during Site24x7 demos. Faults are controlled from the Site24x7 Labs UI, injected via this SDK embedded in the target app, and captured by Site24x7 APM to showcase its monitoring capabilities.

Quick Start

Install

# Flask app
pip install site24x7-chaos[flask]

# FastAPI app
pip install site24x7-chaos[fastapi]

# All optional dependencies
pip install site24x7-chaos[all]

Initialize (one line)

Flask:

from flask import Flask
from site24x7_chaos.flask import init_chaos

app = Flask(__name__)
init_chaos(app)

FastAPI:

from fastapi import FastAPI
from site24x7_chaos.fastapi import init_chaos

app = FastAPI()
init_chaos(app)

Set environment variables

export CHAOS_SDK_ENABLED=true
export CHAOS_SDK_APP_NAME=order-service
export CHAOS_SDK_CONFIG_DIR=/var/site24x7-labs/faults

Mount the shared volume

In Docker Compose, add a shared volume so the agent can write config files and the SDK can read them:

services:
  order-service:
    volumes:
      - chaos_config:/var/site24x7-labs/faults:ro

That's it. No other code changes required.

Supported Fault Types (19)

# Fault Type Category Description
1 http_exception Inbound HTTP Raise a mapped Python exception
2 http_latency Inbound HTTP Add artificial latency to requests
3 http_error_response Inbound HTTP Return a static error response
4 http_connection_reset Inbound HTTP Abort the socket connection
5 http_slow_body Inbound HTTP Stream a response body with inter-chunk delays
6 http_client_latency Outbound HTTP Add latency to outbound requests/httpx calls
7 http_client_exception Outbound HTTP Raise an exception on outbound calls
8 http_client_error_response Outbound HTTP Return a fake error response from outbound calls
9 jdbc_exception Database Raise a SQLAlchemy exception before queries
10 jdbc_latency Database Add latency before queries
11 jdbc_connection_pool_drain Database Hold connections from the pool
12 redis_exception Redis Raise a redis-py exception on commands
13 redis_latency Redis Add latency before Redis commands
14 thread_pool_exhaustion Resource Spawn busy-sleeping threads
15 memory_pressure Resource Allocate large bytearrays on the heap
16 cpu_burn Resource Tight math loops across threads
17 gc_pressure Resource Rapid short-lived allocations to stress the GC
18 thread_deadlock Resource Two threads that deadlock on locks
19 disk_fill Resource Write temp files to consume disk space

Optional Dependencies

Extra Libraries Purpose
flask Flask >= 2.0 Flask middleware integration
fastapi FastAPI >= 0.68, Starlette >= 0.14 FastAPI/ASGI middleware integration
sqlalchemy SQLAlchemy >= 1.4 Database fault injection
redis redis-py >= 4.0 Redis fault injection
requests requests >= 2.20 Outbound HTTP fault injection (requests)
httpx httpx >= 0.23 Outbound HTTP fault injection (httpx)
all All of the above Everything

Documentation

See docs/integration-guide.md for the full integration guide including:

  • Architecture overview and how faults flow from UI to SDK
  • Detailed config for all 19 fault types
  • Docker and Kubernetes deployment examples
  • init_chaos() parameter reference
  • Troubleshooting guide

Requirements

  • Python >= 3.9
  • Flask >= 2.0 or FastAPI >= 0.68
  • Access to the Site24x7 Labs agent shared volume

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

site24x7_chaos-1.1.2.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

site24x7_chaos-1.1.2-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file site24x7_chaos-1.1.2.tar.gz.

File metadata

  • Download URL: site24x7_chaos-1.1.2.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for site24x7_chaos-1.1.2.tar.gz
Algorithm Hash digest
SHA256 e0d39eaa905a8571f268d7f0c657966ea4891360721d72dc4928be196a564609
MD5 9b924ce4c25a772208baa2f0426688d9
BLAKE2b-256 7a2f821d9c44c7723dd1e8701454859faa76842534fa7562569fafd79f79a046

See more details on using hashes here.

File details

Details for the file site24x7_chaos-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: site24x7_chaos-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for site24x7_chaos-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 03ecb60175c39d433bbf58b2907811b1a88d4041c0b1ea124cb27fe53ace424f
MD5 f43e9aa63318899904ddf9dc3bdda512
BLAKE2b-256 d7860fb6a3e8df5794e6b49eee884eccc6b44471f4142ce2d6dc4eeb4376c270

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page