fivelab/diagnostic 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fivelab/diagnostic

Composer 安装命令:

composer require fivelab/diagnostic

包简介

The library for diagnostic application.

关键字:

README 文档

README

 #StandWithUkraine 

Diagnostic

The library for diagnostic application.

Build Status

Why?

This library helps for developers and devops for setup any applications.

If developer correct configure all diagnostics (paths, services, etc...) the devops before run the instance with our application only run diagnostic and can sees all problems (if it exist).

Primary problem:

The developer can add any parameter or service to application. As an example - add redis service for use in runtime. And lost provide this information before release application. The devops (or developer) release new version application and the system not have any problems. But, we have a major issue because the redis only used in runtime and not processed in deploy process.

Devops add this instance to load balancer (if exist), and in next times the application not correct work ;(

Solution:

Before add the instance to load balancer (or processed scope), devops run diagnostic and can see all major problems.

Restrictions

If you want work with this mechanism you MUST add diagnostic check to all end points. As an example:

  • Are you use cache? You MUST add check for verify access to cache directory.
  • Are you use logs? You MUST add check for verify access to logs directory.
  • Are you use DB? You MUST add check for connect to Database.
  • Are you use Redis? You MUST add check for connect to Redis.
  • Are you use any client for connect via HTTP? You MUST add check for connect to this endpoint.
  • etc...

Attention: the devops (infrastructure team, release manager, developer) is not magic person and cannot see all required services by sky stars.

Configure and Run

For easy configure the diagnostic, you can use \FiveLab\Component\Diagnostic\Check\Definition\DefinitionCollectionBuilder:

<?php

declare(strict_types = 1);

namespace Example;

use FiveLab\Component\Diagnostic\Check\Definition\CheckDefinitionsBuilder;
use FiveLab\Component\Diagnostic\Check\Definition\Filter\CheckDefinitionsInGroupFilter;
use FiveLab\Component\Diagnostic\Check\Definition\Filter\OrXFilter;
use FiveLab\Component\Diagnostic\Check\PathReadableCheck;
use FiveLab\Component\Diagnostic\Check\PathWritableCheck;
use FiveLab\Component\Diagnostic\Runner\Runner;

$builder = new CheckDefinitionsBuilder();

$builder->addCheck('cache_dir', new PathWritableCheck('./var/cache'), 'system_dir');
$builder->addCheck('logs_dir', new PathWritableCheck('./var/logs'), 'system_dir');

$builder->addCheck('shared_dir', new PathWritableCheck('./var/shared'), 'shared_dir');
$builder->addCheck('shared_efs', new PathReadableCheck('./var/shared/.efs'), 'shared_dir');

$builder->addCheck('tmp_dir', new PathWritableCheck('./var/tmp'), ['tmp_dir', 'system_dir']);

$definitions = $builder->build();

$runner = new Runner();

// Run all checks
$success = $runner->run($definitions);

// Run only for system dirs
$definitions = $definitions->filter(new CheckDefinitionsInGroupFilter('system_dir'));
$success = $runner->run($definitions);

// Run tmp dir and shared dir
$definitions = $definitions->filter(new OrXFilter(
    new CheckDefinitionsInGroupFilter('tmp_dir'),
    new CheckDefinitionsInGroupFilter('shared_dir')
));

$success = $runner->run($definitions);

Integrate with applications

Dependency Injection

You can easily integrate this library to Symfony application, or application with DependencyInjection support.

For integrate, you can add the compiler pass to your container builder:

<?php

namespace Example;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use FiveLab\Component\Diagnostic\DependencyInjection\AddDiagnosticToBuilderCheckPass;

$containerBuilder = new ContainerBuilder();
$containerBuilder->addCompilerPass(new AddDiagnosticToBuilderCheckPass());

$containerBuilder->compile();

And add check services:

services:
    diagnostic.check.cache_dir:
        class: \FiveLab\Component\Diagnostic\Check\PathWritableCheck
        arguments: [ '%kernel.cache_dir%' ]
        tags:
            - { name: diagnostic.check }

    diagnostic.check.logs_dir:
        class: \FiveLab\Component\Diagnostic\Check\PathWritableCheck
        arguments: [ '%kernel.logs_dir%' ]
        tags:
            - { name: diagnostic.check }

The tag diagnostic.check support next attributes:

  • key - the unique key of check (default is service name).
  • group - the group of this check (default is null).
  • error_on_failure - if false, system not return error code from process (ignore failures, default is true).

Console commands

We provide console commands for easy integrate to any applications:

  • \FiveLab\Component\Diagnostic\Command\RunDiagnosticCommand - command for run diagnostic.
  • \FiveLab\Component\Diagnostic\Command\ListChecksCommand - command for list all available checks.
  • \FiveLab\Component\Diagnostic\Command\ListGroupsCommand - command for list all available groups.

Development

For easy development you can use the Docker and Docker compose.

docker compose up
docker compose exec diagnostic bash

After success run and attach to container you must install vendors:

composer install

Before create the PR or merge into develop, please run next commands for validate code:

./bin/phpunit

./bin/phpcs --config-set show_warnings 0
./bin/phpcs --standard=src/phpcs-ruleset.xml src/
./bin/phpcs --standard=tests/phpcs-ruleset.xml tests/

php -d memory_limit=-1 ./bin/phpstan

fivelab/diagnostic 适用场景与选型建议

fivelab/diagnostic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33.08k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「check」 「health」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fivelab/diagnostic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fivelab/diagnostic 我们能提供哪些服务?
定制开发 / 二次开发

基于 fivelab/diagnostic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 33.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-23