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.1.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.1-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: site24x7_chaos-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 418605ab3ca31bd29b1540d2f921edd958a19e9ca08eeeaf71ca330d20467a31
MD5 d091af6a184471f8f56b3dd868849822
BLAKE2b-256 0521b6641ed497a2d6d0e25130886a6733cc353f87d143f91905c124643ceda4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: site24x7_chaos-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a41e2db53fc0cfdb8cd41dec2823e531b22bff00b113b5df65d28428ef12d01d
MD5 59757d9ce21083c7de0f4001f56a75e2
BLAKE2b-256 b79ed2ae83d05afdf002035805ddbdc2f69eef51f7fa852b52bdde985470752d

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