Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3f0c4b5
Create codeql-analysis.yml
Oct 2, 2020
33f8cc2
Merge pull request #49 from spiral/security_code_scanning
Oct 2, 2020
7a3d77d
Server error details #50 [server configuration options, only 'debug' …
Oct 13, 2020
49c351c
Server error details #50 [add test]
Oct 13, 2020
b7d6bb7
Merge pull request #51 from aldump/issue-50/debug-mode-for-server
wolfy-j Oct 13, 2020
eaf06f9
release 1.4.1
Oct 13, 2020
4f92240
Merge pull request #52 from spiral/release_1.4.1
Oct 13, 2020
3918e66
Update composer.json
SerafimArts Dec 21, 2020
d6c0f99
fix reflection deprecated php 8.0 methods
lampatrampa Feb 9, 2021
fe8bf7f
remove whitespace
lampatrampa Feb 10, 2021
db2c503
Checking types are instance of ReflectionNamedType
lampatrampa Mar 10, 2021
da59a93
Merge pull request #55 from lampatrampa/bugfix/reflection-deprecated
wolfy-j Mar 25, 2021
7ce5f93
Code improvements
SerafimArts Mar 25, 2021
3ac8f78
Remove phpunit cache
SerafimArts Mar 25, 2021
96ce30f
Implement "Context::offsetSet" method
SerafimArts Mar 25, 2021
02b2e56
Improve Server code
SerafimArts Mar 30, 2021
7bffa8e
Add base support of RoadRunner 2.x
SerafimArts Mar 30, 2021
3617397
Improve example worker code
SerafimArts Mar 30, 2021
67578c8
Improve example composer
SerafimArts Mar 30, 2021
23f74d4
Rollback test paths
SerafimArts Mar 30, 2021
dc5c51b
Add php 8.0 CI tests and increase phpunit version
SerafimArts Mar 30, 2021
4d68ca7
Remove phpunit CI installation
SerafimArts Mar 30, 2021
98c420c
Fix test worker autoload file
SerafimArts Mar 30, 2021
af70c74
Fix server logic
SerafimArts Mar 31, 2021
aca6336
Extract some server logic from try/catch
SerafimArts Mar 31, 2021
1aa9f96
Fix invoker exceptions wrapping
SerafimArts Mar 31, 2021
faca40e
Improve exception handling
SerafimArts Mar 31, 2021
781d3b1
Remove JB attributes (phpcs bug)
SerafimArts Mar 31, 2021
fdd9e82
Fix unit tests
SerafimArts Mar 31, 2021
7d56393
AFix psalm errors and improve types
SerafimArts Mar 31, 2021
181d7c6
Using composer update command in CI instead of install
SerafimArts Mar 31, 2021
9fb357a
Remove "--ignore-platform-reqs" flag
SerafimArts Mar 31, 2021
b09bb8d
PHP8 support, refactoring
wolfy-j Mar 31, 2021
c0b8968
Add gRPC method to call metrics
rochacon Apr 20, 2021
09e1f93
#65 Add gRPC method to call metrics
rustatian Apr 21, 2021
2954b0d
Merge remote-tracking branch 'origin2/master' into update-fork-with-m…
Bibob7 May 7, 2021
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
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"

on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 12 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['go']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ vendor/
clover.xml
example/vendor/
go.sum
builds/
builds/
.phpunit.result.cache
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ install:
- popd
- export GO111MODULE=on
- go mod download
- composer install --no-interaction --prefer-source --ignore-platform-reqs
- composer install --no-interaction --prefer-source
- go get

script:
- go test -race -v -coverprofile=grpc.txt -covermode=atomic
- go test ./parser -race -v -coverprofile=parser.txt -covermode=atomic
- go test -race -v -coverprofile=protoc-gen-php-grpc.txt ./cmd/protoc-gen-php-grpc -covermode=atomic
- composer require phpunit/phpunit:~7.0 --ignore-platform-reqs
- vendor/bin/spiral-cs check src tests/GRPC
- vendor/bin/phpunit --coverage-clover=coverage.xml
- go build cmd/protoc-gen-php-grpc/main.go
Expand Down Expand Up @@ -62,3 +61,12 @@ jobs:
- sudo cp `which php7.4` `which php`
- php -v
- composer self-update
- stage: Test
env: "PHP=8.0"
before_install:
- sudo add-apt-repository -y ppa:ondrej/php
- sudo apt-get update
- sudo apt-get install -y php8.0-cli php8.0-xml php8.0-xdebug
- sudo cp `which php8.0` `which php`
- php -v
- composer self-update
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

v1.4.1 (13.10.2020)
-------------------
- RoadRunner version update to 1.8.3
- Golang version in go.mod bump to 1.15
- Add server configuration options (debug) (@aldump)

v1.4.0 (1.08.2020)
-------------------
- Add all major gRPC configuration options. [Docs](https://github.com/spiral/docs/blob/master/grpc/configuration.md#application-server)
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cd $(dirname "${BASH_SOURCE[0]}")
OD="$(pwd)"
# Pushes application version into the build information.
RR_VERSION=1.4.0
RR_VERSION=1.4.1

# Hardcode some values to the core package
LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.Version=${RR_VERSION}"
Expand Down
12 changes: 8 additions & 4 deletions cmd/rr-grpc/grpc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func newCollector() *metricCollector {
Name: "rr_grpc_call_total",
Help: "Total number of handled grpc requests after server restart.",
},
[]string{"code"},
[]string{"code", "method"},
),
callDuration: prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "rr_grpc_call_duration_seconds",
Help: "GRPC call duration.",
},
[]string{"code"},
[]string{"code", "method"},
),
workersMemory: prometheus.NewGauge(
prometheus.GaugeOpts{
Expand All @@ -103,8 +103,12 @@ func (c *metricCollector) listener(event int, ctx interface{}) {
code = st.Code().String()
}

c.callDuration.With(prometheus.Labels{"code": code}).Observe(uc.Elapsed().Seconds())
c.callCounter.With(prometheus.Labels{"code": code}).Inc()
method := "Unknown"
if uc.Info != nil {
method = uc.Info.FullMethod
}
c.callDuration.With(prometheus.Labels{"code": code, "method": method}).Observe(uc.Elapsed().Seconds())
c.callCounter.With(prometheus.Labels{"code": code, "method": method}).Inc()
}
}

Expand Down
84 changes: 53 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
{
"name": "spiral/php-grpc",
"type": "server",
"description": "High-Performance GRPC server for PHP applications",
"license": "MIT",
"authors": [
{
"name": "Anton Titov / Wolfy-J",
"email": "wolfy.jd@gmail.com"
}
],
"require": {
"php": "^7.2",
"ext-json": "*",
"google/protobuf": "^3.7",
"spiral/roadrunner": "^1.8"
},
"require-dev": {
"phpunit/phpunit": "~7.0",
"spiral/code-style": "^1.0"
},
"autoload": {
"psr-4": {
"Spiral\\GRPC\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"": "tests/src/",
"Spiral\\GRPC\\Tests\\": "tests/GRPC/"
}
}
"name": "spiral/php-grpc",
"type": "library",
"description": "High-Performance GRPC server for PHP applications",
"license": "MIT",
"authors": [
{
"name": "Anton Titov / Wolfy-J",
"email": "wolfy.jd@gmail.com"
}
],
"require": {
"php": ">=7.2",
"ext-json": "*",
"symfony/polyfill-php80": "^1.22",
"symfony/polyfill-php73": "^1.22",
"google/protobuf": "^3.7",
"spiral/roadrunner": "^1.8"
},
"require-dev": {
"phpunit/phpunit": "^8.5|^9.0",
"spiral/code-style": "^1.0",
"jetbrains/phpstorm-attributes": "^1.0",
"symfony/var-dumper": ">=4.4",
"vimeo/psalm": "^4.6"
},
"autoload": {
"psr-4": {
"Spiral\\GRPC\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"": "tests/src",
"Spiral\\GRPC\\Tests\\": "tests/GRPC"
}
},
"scripts": {
"test": [
"spiral-cs check src tests/GRPC",
"psalm --no-cache",
"phpunit"
]
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
29 changes: 21 additions & 8 deletions example/server/composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
{
"require": {
"spiral/php-grpc": "^1.0"
},
"autoload": {
"psr-4": {
"": "src/"
}
}
"name": "app/example-grpc-server",
"description": "Example GRPC Server",
"repositories": [
{
"type": "path",
"url": "../.."
}
],
"require": {
"spiral/php-grpc": "*"
},
"require-dev": {
"grpc/grpc": "^1.36"
},
"autoload": {
"psr-4": {
"": "src"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
26 changes: 18 additions & 8 deletions example/server/worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
* Sample GRPC PHP server.
*/

use Spiral\Goridge;
use Spiral\RoadRunner;
use Service\EchoInterface;
use Spiral\Goridge\StreamRelay;
use Spiral\GRPC\Server;
use Spiral\RoadRunner\Worker;

ini_set('display_errors', 'stderr');
require "vendor/autoload.php";
require __DIR__ . '/vendor/autoload.php';

$server = new \Spiral\GRPC\Server();
$server->registerService(\Service\EchoInterface::class, new EchoService());
$server = new Server(null, [
'debug' => false, // optional (default: false)
]);

$w = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT));
$server->serve($w);
$server->registerService(EchoInterface::class, new EchoService());

$worker = \method_exists(Worker::class, 'create')
// RoadRunner >= 2.x
? Worker::create()
// RoadRunner 1.x
: new Worker(new StreamRelay(STDIN, STDOUT))
;

$server->serve($worker);
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/spiral/php-grpc

go 1.13
go 1.15

require (
github.com/buger/goterm v0.0.0-20200322175922-2f3e71b85129
Expand All @@ -10,7 +10,7 @@ require (
github.com/prometheus/client_golang v1.6.0
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v1.0.0
github.com/spiral/roadrunner v1.8.2
github.com/spiral/roadrunner v1.8.3
github.com/stretchr/testify v1.5.1
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2
google.golang.org/grpc v1.29.1
Expand Down
14 changes: 8 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
processIsolation="false"
stopOnFailure="false"
stopOnError="false"
>

stderr="true">
<testsuites>
<testsuite name="High-Performance GRPC server for PHP applications">
<directory>./tests/</directory>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
</php>
</phpunit>
27 changes: 27 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<psalm
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

errorLevel="1"
hoistConstants="true"
resolveFromConfigFile="true"
allowPhpStormGenerics="true"
findUnusedPsalmSuppress="true"
findUnusedVariablesAndParams="true"
ensureArrayStringOffsetsExist="true"
addParamDefaultToDocblockType="true"
>
<issueHandlers>
<RedundantConditionGivenDocblockType errorLevel="suppress" />
<MixedReturnStatement errorLevel="suppress" />
<UnusedPsalmSuppress errorLevel="suppress" />
</issueHandlers>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
Loading