redmarker / doctor

此包最新版本(1.0.7)没有提供许可信息。

Red Marker Health Check包

1.0.7 2019-10-09 04:12 UTC

This package is auto-updated.

Last update: 2024-09-19 08:51:22 UTC


README

这是一个基于PHP的包,用于执行遵循https://tools.ietf.org/id/draft-inadarei-api-health-check-01.html格式的健康状态检查。

"我需要一位医生" - Dr. Dre

就像Dre一样,你可能也需要一位医生。

安装

composer require redmarker/doctor

Doctor使用

使用新的Examination()创建Doctor类的实例。

将RedMarker\Doctor\Checks\CheckInterface对象传递给Doctor,会将它们添加到医生的检查属性中。

在RedMarker\Doctor\Doctor()中必须设置releaseId和serviceId。

releaseId应该是当前的git提交hash。

serviceId应该是容器的id。

use ZendDiagnostics\Runner\Runner as Examination;

$doctor = new RedMarker\Doctor\Doctor(Examination $examination);
$doctor->setReleaseId($releaseId);
$doctor->setServiceId($serviceId);

向Doctor添加检查

将每个检查作为一个数组传递给Doctor。

$doctor->addChecks([ 
    new Doctor\Checks\Database()
]);

return $doctor->diagnose();

输出

{
    "status": "pass",
    "releaseID": "5113e3d0ad8fe3f1ac8393e17432353b194a060f",
    "serviceID": "34ebdffa9cba",
    "details": [
        {
            "database:connection": {
                "componentId": "api",
                "componentType": "datastore",
                "time": "2019-10-01T06:23:35.817073Z",
                "status": "pass"
            }
        }
    ]
}

Laravel使用

对于Laravel使用,以下服务提供者在config/app.php中应该被注册:

RedMarker\Doctor\Providers\Laravel\HealthProvider::class

Laravel检查的配置设置

/*
|--------------------------------------------------------------------------
| Service Id
|--------------------------------------------------------------------------
|
| Here you may specify the service_id that should be used
| by the health check. The service_id should be the containers id.
|
*/
'service_id' => env('CONTAINER_ID', 'container-id not found'),

/*
|--------------------------------------------------------------------------
| Release Id
|--------------------------------------------------------------------------
|
| Here you may specify the release_id that should be used
| by the health check. The release_id should be the current git hash.
|
*/
'release_id' => env('RELEASE_ID', 'release-id not found'),

/*
|--------------------------------------------------------------------------
| Vendor Folder Location
|--------------------------------------------------------------------------
|
| Here you may specify the location of that vendor folder that.
| This location is only used by the VendorFolder Check.
|
*/
'vendor_folder' => env('APP_ROOT') . '/vendor',

/*
|--------------------------------------------------------------------------
| .Env File Location
|--------------------------------------------------------------------------
|
| Here you may specify the location of the .env file.
| This location is used by the EnvFile Check.
|
*/
'env_file' => env('APP_ROOT') . '/.env',

/*
|--------------------------------------------------------------------------
| HttpResponse Check configurations
|--------------------------------------------------------------------------
|
*/
'services' => [
    'component_name' => [
        'endpoint' => env('API_URL'),
        'jwt' => env('API_JWT'),
        'see_in_response' => [
            'success'
        ]
    ],
]