{"id":18454767,"url":"https://github.com/mcmartins/chaosproxy","last_synced_at":"2025-04-22T14:28:42.548Z","repository":{"id":91176201,"uuid":"71933712","full_name":"mcmartins/chaosproxy","owner":"mcmartins","description":"ChaosProxy is a server that creates instability on connections delaying or dropping requests and responses","archived":false,"fork":false,"pushed_at":"2017-07-20T12:19:00.000Z","size":34,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-25T04:42:14.628Z","etag":null,"topics":["failure-injection","forward-proxy","network","testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcmartins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-25T19:56:57.000Z","updated_at":"2017-07-06T15:26:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"dc191408-0402-40ed-81d3-25ff6fcf235e","html_url":"https://github.com/mcmartins/chaosproxy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmartins%2Fchaosproxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmartins%2Fchaosproxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmartins%2Fchaosproxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmartins%2Fchaosproxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcmartins","download_url":"https://codeload.github.com/mcmartins/chaosproxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239142747,"owners_count":19588875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["failure-injection","forward-proxy","network","testing"],"created_at":"2024-11-06T08:06:03.661Z","updated_at":"2025-02-16T14:41:50.471Z","avatar_url":"https://github.com/mcmartins.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ChaosProxy\n\nChaosProxy is a proxy server that creates an unstable environment where connections \nare delayed or dropped making requests not reach a remote host and responses not arriving.\n\nThis tool runs locally on a specific port and forwards all requests to a specific remote server.\n\n## Use Cases\n\nThis tool is useful for testing Web APIs, where one needs to test reconciliation on rainy day scenarios.\n\nChaosProxy will sit between both ends of a distributed system. E.g.: A system **A** sends requests to system **B**. \nSo system **A** should be configured with the ChaosProxy server address (e.g. http://localhost:9090) \nand the ChaosServer should be configured with system **B** server address (e.g. http://localhost:9091).\n\nEach request passing through the proxy will include information headers on the operations performed.\nThe main header is *chaosproxy-requestid* and will allow tracking the request across all systems.\n\nSample configuration for the mentioned example:\n\n```none\n{\n  \"local\": {\n    \"port\": 9090\n  },\n  \"remote\": {\n    \"host\": \"http://localhost:9091\"\n  },\n  \"connection\": {\n    \"stableInterval\": 60,\n    \"unstableInterval\": 15,\n    \"ignoreIfEndpointContains\": [\"login\"]\n    \"request\": {\n      \"dropRandomly\": true,\n      \"delay\": {\n        \"logNormal\": {\n          \"mean\": 200,\n          \"sigma\": 20\n        }\n      }\n    },\n    \"response\": {\n      \"dropRandomly\": true,\n      \"delay\": {\n        \"logNormal\": {\n          \"mean\": 200,\n          \"sigma\": 20\n        }\n      }\n    }\n  }\n}\n```\n\nSo, a request sent to *http://localhost:9090/rest/service/resource* will be forward to *http://localhost:9091/rest/service/resource*:\n\n```none\n2016-10-28 10:59:37,174 - [INFO] - 53fe99e8d9522L - [POST] Request received\n2016-10-28 10:59:37,176 - [INFO] - 53fe99e8d9522L - Forwarding request to [http://localhost:9091/rest/service/resource]\n2016-10-28 10:59:37,184 - [DEBUG] - 53fe99e8d9522L - Request headers:\n{\n  \"origin\": \"chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop\", \n  \"content-length\": \"419\", \n  \"accept-language\": \"pt-PT,pt;q=0.8,it-IT;q=0.6,it;q=0.4,en-US;q=0.2,en;q=0.2\", \n  \"chaosproxy-requestid\": \"53fe99e8d9522L\", \n  \"chaosproxy-host\": \"PC-25.local\", \n  \"connection\": \"keep-alive\", \n  \"accept\": \"*/*\", \n  \"user-agent\": \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36\", \n  \"cache-control\": \"no-cache\", \n  \"content-type\": \"application/json; charset=UTF-8\"\n}\n2016-10-28 10:59:37,180 - [DEBUG] - 53fe99e8d9522L - Request body:\n{\n  \"id\": \"123\", \n  \"name\": \"Name\"\n}\n2016-10-28 11:03:02,038 - [INFO] - 53fe99e8d9522L - Response Delayed for [0.5 s]\n2016-10-28 11:03:02,190 - [DEBUG] - 53fe99e8d9522L - Response headers:\n{\n  \"chaosproxy-drop-request\": \"False\", \n  \"chaosproxy-drop-response\": \"False\", \n  \"x-powered-by\": \"PHP/7.0.10\", \n  \"transfer-encoding\": \"chunked\", \n  \"chaosproxy-requestid\": \"53fe99e8d9522L\", \n  \"chaosproxy-host\": \"PC-25.local\", \n  \"chaosproxy-delay-request\": \"False\", \n  \"server\": \"ChaosServer/0.0.1 Python/2.7.11\", \n  \"connection\": \"close\", \n  \"date\": \"Fri, 28 Oct 2016 10:03:02 GMT\", \n  \"content-type\": \"text/html; charset=UTF-8\", \n  \"chaosproxy-delay-response\": \"0.5 s\"\n}\n2016-10-28 11:03:02,196 - [INFO] - 53fe99e8d9522L - [POST] Request processed\n```\n\n## How to use\n\n### System commands\n\nAdd the following command line helper functions:\n\n```bash\n[mcmartins@local ~]$ echo \"function conf_chaosproxy() { (wget -nc -O ~/.conf_chaosproxy.json https://raw.githubusercontent.com/mcmartins/chaosproxy/master/sample-conf.json \u0026\u003e /dev/null || true) \u0026\u0026 vi ~/.conf_chaosproxy.json ;}\" \u003e\u003e ~/.bashrc \u0026\u0026 source ~/.bashrc\n[mcmartins@local ~]$ echo \"function start_chaosproxy() { (wget -nc -O ~/.start_chaosproxy.sh https://raw.githubusercontent.com/mcmartins/chaosproxy/master/bin/chaosproxy.sh \u0026\u003e /dev/null \u0026\u0026 chmod +x ~/.start_chaosproxy.sh || true) \u0026\u0026 ~/.start_chaosproxy.sh ;}\" \u003e\u003e ~/.bashrc \u0026\u0026 source ~/.bashrc\n[mcmartins@local ~]$ echo \"function stop_chaosproxy() { (wget -nc -O ~/.stop_chaosproxy.sh https://raw.githubusercontent.com/mcmartins/chaosproxy/master/bin/kill_chaosproxy.sh \u0026\u003e /dev/null \u0026\u0026 chmod +x ~/.stop_chaosproxy.sh || true) \u0026\u0026 ~/.stop_chaosproxy.sh ;}\" \u003e\u003e ~/.bashrc \u0026\u0026 source ~/.bashrc\n```\n\nThis will create the basic commands to interact with ProxyChaos on your local machine. \n\nTo create and default configuration and change it:\n\n```bash\n[mcmartins@local ~]$ conf_chaosproxy\n```\n\nTo start the server:\n\n```bash\n[mcmartins@local ~]$ start_chaosproxy\n```\n\nTo stop the server:\n\n```bash\n[mcmartins@local ~]$ stop_chaosproxy\n```\n\n### Configure the server\n\nThe following is a configuration file with all options available:\n\n```json\n{\n  \"local\": {\n    \"port\": 8080\n  },\n  \"remote\": {\n    \"host\": \"http://some-remote-service.com:8080\"\n  },\n  \"connection\": {\n    \"stableInterval\": 60,\n    \"unstableInterval\": 15,\n    \"ignoreIfEndpointContains\": [\"endpoint\"],\n    \"ignoreIfBodyContains\": [\"initsession\"],\n    \"request\": {\n      \"dropRandomly\": true,\n      \"delay\": {\n        \"random\": {\n          \"min\": 100,\n          \"max\": 500\n        },\n        \"logNormal\": {\n          \"mean\": 200,\n          \"sigma\": 20\n        },\n        \"fixed\": 1000\n      }\n    },\n    \"response\": {\n      \"dropRandomly\": true,\n      \"delay\": {\n        \"random\": {\n          \"min\": 100,\n          \"max\": 500\n        },\n        \"logNormal\": {\n          \"mean\": 200,\n          \"sigma\": 20\n        },\n        \"fixed\": 1000\n      }\n    }\n  }\n}\n```\n\nA JSON configuration is needed for ChaosProxy to work. The configuration is split in 3 groups:\n\n1 Local: refers to the local environment for the ChaosProxy and the only available option is:\n\n- port: the local port where the server will be listening on\n\n2 Remote: refers to the remote server for which ChaosProxy will forward all requests:\n\n- host: the full address (including port if not a default for http 80 or https 443). Chaos proxy will use this address to forward the original request.\n\n3 Connection: refers to the instability that will be created on connections.\n\n- stableInterval:  an interval time where ChaosProxy **won't** interfere with the connections (in milliseconds)\n- unstableInterval: an interval time where ChaosProxy **will** interfere with the connections (in milliseconds)\n- ignoreIfEndpointContains: a list of strings for which ChaosProxy **will never** interfere, if they are present in the endpoint\n- ignoreIfBodyContains: a list of strings for which ChaosProxy **will never** interfere, if they are present in the body\n\n3.1 Request: refers to the instability to create on requests\n\n- dropRandomly: setting this to true, will drop requests on a random number divisible by 3 in a range of 1 to 5000, and **no response from server will be returned**\n- delay.random: delay requests based on a random number within the range a, b (inclusive) (in milliseconds)\n- delay.logNormal: delay requests based on an approximation on the 50th percentile (in milliseconds)\n- delay.fixed: delay requests based on this fixed value (in milliseconds)\n\n3.2 Response: refers to the instability to create on response\n\n- dropRandomly: setting this to true, will drop responses on a random number divisible by 3 in a range of 1 to 5000, and **a 500 http error code with all response headers will be returned**\n- delay.random: delay requests based on a random number within the range a, b (inclusive) (in milliseconds)\n- delay.logNormal: delay requests based on an approximation on the 50th percentile (in milliseconds)\n- delay.fixed: delay requests based on this fixed value (in milliseconds)\n\n# LICENSE\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmartins%2Fchaosproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcmartins%2Fchaosproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmartins%2Fchaosproxy/lists"}