Skip to content

Add metrics #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
var
vendor
24 changes: 0 additions & 24 deletions .php_cs

This file was deleted.

1 change: 0 additions & 1 deletion .phpunit.result.cache

This file was deleted.

68 changes: 0 additions & 68 deletions .scrutinizer.yml

This file was deleted.

75 changes: 50 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,68 @@ SHELL=bash

.PHONY: *

DOCKER_CGROUP:=$(shell cat /proc/1/cgroup | grep docker | wc -l)
COMPOSER_CACHE_DIR:=$(shell composer config --global cache-dir -q || echo ${HOME}/.composer/cache)

ifneq ("$(wildcard /.dockerenv)","")
DOCKER_RUN=
IN_DOCKER:=TRUE
else ifneq ("$(DOCKER_CGROUP)","0")
IN_DOCKER:=TRUE
else
DOCKER_RUN=docker run --rm -it \
-v `pwd`:`pwd` \
-w `pwd` \
"wyrihaximusnet/php:7.4-zts-alpine3.11-dev"
IN_DOCKER:=FALSE
endif

all: lint cs-fix cs stan psalm unit infection composer-require-checker composer-unused
ifeq ("$(IN_DOCKER)","TRUE")
DOCKER_RUN:=
else
PHP_VERSION:=$(shell docker run --rm -v "`pwd`:`pwd`" jess/jq jq -r -c '.config.platform.php' "`pwd`/composer.json" | php -r "echo str_replace('|', '.', explode('.', implode('|', explode('.', stream_get_contents(STDIN), 2)), 2)[0]);")
DOCKER_RUN:=docker run --rm -it \
-v "`pwd`:`pwd`" \
-v "${COMPOSER_CACHE_DIR}:/home/app/.composer/cache" \
-w "`pwd`" \
"ghcr.io/wyrihaximusnet/php:${PHP_VERSION}-zts-alpine3.12-dev"
endif

lint:
$(DOCKER_RUN) vendor/bin/parallel-lint --exclude vendor .
all: ## Runs everything ###
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v "###" | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | xargs --open-tty $(MAKE)

cs:
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(nproc)
syntax-php: ## Lint PHP syntax
$(DOCKER_RUN) vendor/bin/parallel-lint --exclude vendor .

cs-fix:
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(nproc)
cs-fix: ## Fix any automatically fixable code style issues
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml -vvvv

stan:
$(DOCKER_RUN) vendor/bin/phpstan analyse src tests --level max --ansi -c phpstan.neon
cs: ## Check the code for code style issues
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(shell nproc) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml

psalm:
$(DOCKER_RUN) vendor/bin/psalm --threads=$(nproc) --shepherd --stats
stan: ## Run static analysis (PHPStan)
$(DOCKER_RUN) vendor/bin/phpstan analyse src tests --level max --ansi -c ./etc/qa/phpstan.neon

unit:
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c phpunit.xml.dist --coverage-text --coverage-html covHtml --coverage-clover ./build/logs/clover.xml
psalm: ## Run static analysis (Psalm)
$(DOCKER_RUN) vendor/bin/psalm --threads=$(shell nproc) --shepherd --stats --config=./psalm.xml

unit-ci: unit
if [ -f ./build/logs/clover.xml ]; then sleep 3; fi
unit-testing: ## Run tests
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c ./etc/qa/phpunit.xml --coverage-text --coverage-html ./var/tests-unit-coverage-html --coverage-clover ./var/tests-unit-clover-coverage.xml
$(DOCKER_RUN) test -n "$(COVERALLS_REPO_TOKEN)" && test -n "$(COVERALLS_RUN_LOCALLY)" && test -f ./var/tests-unit-clover-coverage.xml && vendor/bin/php-coveralls -v --coverage_clover ./build/logs/clover.xml --json_path ./var/tests-unit-clover-coverage-upload.json || true

infection:
$(DOCKER_RUN) vendor/bin/infection --ansi --min-msi=100 --min-covered-msi=100 --threads=$(nproc)
mutation-testing: ## Run mutation testing
$(DOCKER_RUN) vendor/bin/roave-infection-static-analysis-plugin --ansi --min-msi=100 --min-covered-msi=100 --threads=$(shell nproc) --ignore-msi-with-no-mutations

composer-require-checker:
$(DOCKER_RUN) vendor/bin/composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=composer-require-checker.json
composer-require-checker: ## Ensure we require every package used in this package directly
$(DOCKER_RUN) vendor/bin/composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=./etc/qa/composer-require-checker.json

composer-unused:
composer-unused: ## Ensure we don't require any package we don't use in this package directly
$(DOCKER_RUN) composer unused --ansi

backward-compatibility-check: ## Check code for backwards incompatible changes
$(DOCKER_RUN) vendor/bin/roave-backward-compatibility-check || true

shell: ## Provides Shell access in the expected environment ###
$(DOCKER_RUN) ash

task-list-ci: ## CI: Generate a JSON array of jobs to run, matches the commands run when running `make (|all)` ###
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v "###" | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | jq --raw-input --slurp -c 'split("\n")| .[0:-1]'

help: ## Show this help ###
@printf "\033[33mUsage:\033[0m\n make [target]\n\n\033[33mTargets:\033[0m\n"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-32s\033[0m %s\n", $$1, $$2}' | tr -d '#'
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ $eventLoopBridge->await($future)->then(function (string $message) {
$loop->run();
```

## Metrics

This package supports metrics through [`wyrihaximus/metrics`](https://github.com/wyrihaximus/php-metrics):

```php
use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
use ReactParallel\EventLoop\Metrics;
use WyriHaximus\Metrics\Configuration;
use WyriHaximus\Metrics\InMemory\Registry;

$loop = Factory::create();
$eventLoopBridge = (new EventLoopBridge($loop))->withMetrics(Metrics::create(new Registry(Configuration::create())));
```

## Contributing ##

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"react/event-loop": "^1.1",
"react/promise": "^2.7",
"reactivex/rxphp": "^2.0",
"wyrihaximus/constants": "^1.4.3"
"wyrihaximus/constants": "^1.4.3",
"wyrihaximus/metrics": "^1.0"
},
"require-dev": {
"wyrihaximus/async-test-utilities": "^2.2"
"wyrihaximus/async-test-utilities": "^3.2"
},
"config": {
"platform": {
Expand Down
Loading