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.0.tar.gz (24.9 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.0-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: site24x7_chaos-1.1.0.tar.gz
  • Upload date:
  • Size: 24.9 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.0.tar.gz
Algorithm Hash digest
SHA256 233c01ebc8aac259d1642610360941841dc3274c5919da47484a4e84711a2d09
MD5 80228e86911ebd067ebad4f88736124c
BLAKE2b-256 c24925f7b9c0a386288142f43590c839f7779fa9151fb1faaf6208499b56ebe9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: site24x7_chaos-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da6f0b11500b1dd3478d6b64b9885cd41391dbdd857c81d33ff771d6486e8e95
MD5 77741ba03015aa34bf81262ecc0490b1
BLAKE2b-256 1ffc1e75877293e817931ad75851fefeb28bcacca3ede811b8ce6556a56c68eb

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