laraveljutsu/bazooka
Composer 安装命令:
composer require laraveljutsu/bazooka
包简介
Bazooka is a Laravel package that allows developers to simulate controlled failures (like API timeouts) inside their application for resilience testing.
README 文档
README
Introduction
Inject chaos into your Laravel application with ease!
Laravel Bazooka is a powerful Laravel package that allows you to inject controlled chaos into your application. Whether you're testing resilience, simulating failures, or just having fun, Bazooka provides a simple and configurable way to disrupt your application's behavior.
Features
- Inject Chaos Points: Add
Bazooka::chaos()calls to your controller methods with a configurable probability. - Disruption Strategies: Choose from built-in strategies like latency delays or exception throwing.
- Command-Line Tools:
- Inject chaos points into controllers.
- List all chaos points in your application.
- Remove chaos points from your codebase.
- Dry Run Mode: Safely test the removal of chaos points without modifying files.
- Configurable Probability: Control the likelihood of chaos being injected or triggered.
Installation
You can install the package via Composer:
composer require laraveljutsu/bazooka
Laravel will automatically register the service provider.
If needed, add to config/app.php providers array:
'providers' => [ // ... LaravelJutsu\Bazooka\BazookaServiceProvider::class, ],
Configuration
After publishing the configuration file, you can customize the behavior of Bazooka by editing config/bazooka.php:
To publish the configuration file, run the following command:
php artisan vendor:publish --provider="LaravelJutsu\Bazooka\BazookaServiceProvider" --tag="config"
return [ 'enabled' => env('BAZOOKA_ENABLED', true), // Enable or disable Bazooka globally 'probability' => 0.2, // Probability of chaos being injected or triggered (0 to 1) 'strategies' => [ 'latency' => [ 'min_delay' => 100, // Minimum delay in milliseconds 'max_delay' => 500, // Maximum delay in milliseconds ], 'exception' => [ 'exceptions' => [ \RuntimeException::class => 'Something went wrong!', // Exception class and message ], ], ], ];
Usage
Inject Chaos Points
Inject chaos points into your controller methods:
php artisan bazooka:inject
You can target specific controllers:
php artisan bazooka:inject --controller=TestController
List Chaos Points
List all chaos points in your application:
php artisan bazooka:list
Example output:
+-----------------------------------+------+--------+
| File | Line | Method |
+-----------------------------------+------+--------+
| Http/Controllers/TestController.php | 10 | index |
+-----------------------------------+------+--------+
Remove Chaos Points
Remove all chaos points from your codebase:
php artisan bazooka:remove
Use the --dry-run option to preview changes without modifying files:
php artisan bazooka:remove --dry-run
Disruption Strategies
Bazooka comes with built-in disruption strategies. You can configure them in config/bazooka.php.
Latency Disruption
Add a delay to your application.
Exception Disruption
Throw a prepared exception.
Example
Controller Before Injection
namespace App\Http\Controllers; class TestController { public function index() { return 'Hello World'; } }
Controller After Injection
namespace App\Http\Controllers; class TestController { public function index() { \LaravelJutsu\Bazooka\Facades\Bazooka::chaos(); // Chaos point injected here return 'Hello World'; } }
Testing
Run the test suite to ensure everything works as expected:
composer test
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This package is open-source software licensed under the MIT License.
Credits
- Developed by ludo 🐆
- Inspired by the need for chaos engineering in Laravel applications.
Enjoy injecting chaos into your Laravel applications with Laravel Bazooka! 🎉
laraveljutsu/bazooka 适用场景与选型建议
laraveljutsu/bazooka 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 208 次下载、GitHub Stars 达 29, 最近一次更新时间为 2025 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 laraveljutsu/bazooka 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laraveljutsu/bazooka 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 208
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 29
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-17
