Skip to content

Commit

Permalink
support c level plugin in php (pinpoint-apm#623)
Browse files Browse the repository at this point in the history
* test c-level plugins

* test pinpoint_join_cut

* use zend_string_release

- fix bug in pinpoint_interceptor_handler_entry

* add try_end

* test pinpoint_join_cut

* test pdo

* ci(versions): test php versions (#63)

- covered all phpt by docker compose
- pdo,redis,curl
- fix CI

* remote php5 support

* support ci for php7

* add php8.0 testCI

* add php8.3

* rename internal API

- pinpoint_start_trace => _pinpoint_start_trace

* update pinpoint_php module version

* add testcase for simplephp

* update docs

* Feat join cut get caller (#64)

* feat(php): pinpoint_get_caller_arg
* pinpoint_get_caller_arg and phpt
* update pinpoint_php module version 0.5.2
* - remove `fastapi==0.109.1` , it crashes CI
* simple_php for curl/redis/memcache/mysql

* test pack_php_module

* test wordpress

* enable logger

* test phpmyadmin

* fix phpmyadmin

* test(php): more popular project (#65)

- php wordpress, phpmyadmin
- java_call_app

* fix simplephp

* for wilderness test

* change package naming

* update docs

* fix extends bug in pinpoint-php

* support flarum

* support cachethq
  • Loading branch information
eeliu authored Jul 5, 2024
1 parent 5d86c28 commit 1e7c3f0
Show file tree
Hide file tree
Showing 96 changed files with 5,473 additions and 2,737 deletions.
79 changes: 40 additions & 39 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: CI

on: [pull_request, workflow_dispatch,push]
on: [pull_request, workflow_dispatch, push]

env:
MODULE_PAK: pinpoint_php@${{ github.head_ref || github.ref_name }}

jobs:
cpp:
strategy:
Expand Down Expand Up @@ -29,10 +32,6 @@ jobs:
runs-on: [windows-latest]
steps:
- uses: actions/checkout@v2
# - name: actions-setup-cmake
# uses: jwlawson/actions-setup-cmake@v1.14
# with:
# cmake-version: 'latest'

- name: powershell allow...
shell: cmd
Expand All @@ -46,6 +45,7 @@ jobs:
./build/bin/Debug/TestCommon.exe
memory-leak:
needs: [cpp, cpp-windows]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -73,55 +73,56 @@ jobs:
with:
name: valgrind-out
path: common/build/valgrind-out.txt
# PHP5:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php-versions: ["5.6", "5.4", "5.5"]
# steps:
# - uses: actions/checkout@v2
# - uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php-versions }}
# - run: |
# phpize
# ./configure
# make
# make test TESTS=tests5/

PHP7:
PHP:
runs-on: ubuntu-latest
needs: cpp
strategy:
matrix:
# php-versions: ["7.0", "7.1", "7.2", "7.3", "7.4", "8.0"]
php-versions: ["7.4", "8.0"]
php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: redis-phpredis/phpredis@5.3.4
- name: testapp
submodules: "true"
- name: update docker compose
run: |
phpize
./configure
make
make test
# sudo make install
# sudo echo "extension=pinpoint_php.so" >> /etc/php/${{ matrix.php-versions }}/cli/php.ini
# sudo echo "error_log = /home/runner/work/pinpoint-c-agent/pinpoint-c-agent/testapps/PHP/tests/php_error.log" >> /etc/php/${{ matrix.php-versions }}/cli/php.ini
# sudo echo "pinpoint_php.DebugReport=true" >> /etc/php/${{ matrix.php-versions }}/cli/php.ini
# cd testapps/PHP
# composer install
# cp tests/think .
# php think unit -v
wget "https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64"
chmod +x docker-compose-linux-x86_64
./docker-compose-linux-x86_64 version
- name: start test environment
run: |
./docker-compose-linux-x86_64 -f "testapps/compose.yaml" build php-compatible --build-arg PHP_VERSION=${{ matrix.php-version }}
./docker-compose-linux-x86_64 -f "testapps/compose.yaml" up php-compatible
- name: Stop containers
# if: always()
run: ./docker-compose-linux-x86_64 -f "testapps/compose.yaml" down php-compatible

pack_php_module:
runs-on: ubuntu-latest
needs: PHP
steps:
- uses: actions/checkout@v2
- name: Package pinpoint_php
id: pack
run: |
tar -czf ${{ env.MODULE_PAK }} common/ src/PHP config.m4 tests LICENSE
md5=($(md5sum ${{ env.MODULE_PAK }} ))
PACK_NAME=${{ env.MODULE_PAK }}-${md5}-$(date '+%Y-%m-%d').tar.gz
mv ${{ env.MODULE_PAK }} $PACK_NAME
echo "PACK=$PACK_NAME" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v3
with:
name: ${{ env.MODULE_PAK }}
path: ${{ steps.pack.outputs.PACK }}

Python:
strategy:
matrix:
os: [ubuntu-latest, macos-13]
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ${{ matrix.os }}
needs: [cpp, cpp-windows]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ testapps/PHP/composer.phar
wheelhouse/
*.so
.clangd
.vs
.vs
*.dep
downloads
testapps/java_call_app/target
9 changes: 1 addition & 8 deletions DOC/PHP/Readme-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,13 @@ collector-agent| [installed ?](../collector-agent/readme.md)
#################################################
define('APPLICATION_NAME','APP-2');
define('APPLICATION_ID','app-2');
define('AOP_CACHE_DIR',__DIR__.'./Cache/');
define('PLUGINS_DIR',__DIR__.'./Plugins/');
define('PINPOINT_USE_CACHE','YES');
define('PP_REQ_PLUGINS', '\Plugins\PerRequestPlugins');
#define('USER_DEFINED_CLASS_MAP_IMPLEMENT',"\Plugins\Framework\app\ClassMapInFile");
require_once __DIR__. path to 'vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';
#################################################
```
1. ```APPLICATION_NAME```: 应用名称.
2. ```APPLICATION_ID```: Agent ID.
3. ```AOP_CACHE_DIR```: 保存```Cache```文件夹的位置.
4. ```PLUGINS_DIR```: ```Plugins```文件夹的路径.
5. ```PINPOINT_USE_CACHE```: 'YES'-有请求时不会自动更新 ```Cache```; 'No'-有请求时将会自动更新 ```Cache```(您也可以手动更新```Cache```,直接删除```Cache```就可以)。考虑到性能,建议设置为'YES'.如果您修改了Plugins,需要更新```Cache```后才能生效。
6. ```PP_REQ_PLUGINS```: ```PerRequestPlugins```的路径(```PerRequestPlugins```是基本的请求拦截器, 不同的PHP框架的拦截器不同,我们已经为您准备了一些框架的```PerRequestPlugins```,[请到这里获取](../../plugins/PHP/Plugins/Framework),(例如:[swoole's PerRequestPlugins](../../plugins/PHP/Plugins/Framework/Swoole/Http/PerReqPlugin.php))。欢迎PR其他框架哟~
3. ```PP_REQ_PLUGINS```: ```PerRequestPlugins```的路径(```PerRequestPlugins```是基本的请求拦截器, 不同的PHP框架的拦截器不同,我们已经为您准备了一些框架的```PerRequestPlugins```,[请到这里获取](../../plugins/PHP/Plugins/Framework),(例如:[swoole's PerRequestPlugins](../../plugins/PHP/Plugins/Framework/Swoole/Http/PerReqPlugin.php))。欢迎PR其他框架哟~
7. ```require_once __DIR__. path to 'vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';```: 导入pinpoint的auto_pinpointed.php。**请在```require_once __DIR__."/../vendor/autoload.php";```之后添加,这很重要**
3. 拷贝[Plugins](../../plugins/PHP/Plugins)到您的项目根路径下,并在```composer.josn```中自动加载```Plugins```.
Expand Down
119 changes: 41 additions & 78 deletions DOC/PHP/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,74 +17,51 @@ collector-agent| [installed ?](../collector-agent/readme.md)
### Installation

#### Steps
1. git clone https://github.com/pinpoint-apm/pinpoint-c-agent.git

2. Build pinpoint_php module, goto the root directory of pinpoint-c-agent installation package, and do following steps:
1. phpize
2. ./configure
3. make
4. make test
ps: We recommend you to test whether the module is RIGHT. For PHP5: ```make test TESTS=tests5/```
5. make install
6. Activate pinpoint-php-module, please add the following configuration into your ```php.ini```

> php.ini
```ini
extension=pinpoint_php.so
; Collector-agent's TCP address, ip,port:Collector-Agent's ip,port, please ensure it consistent with the `PP_ADDRESS` of `Collector-Agent` in step2(Build Collector-Agent).
pinpoint_php.CollectorHost=Tcp:ip:port
pinpoint_php.SendSpanTimeOutMs=0 # 0 is recommanded
; request should be captured duing 1 second. < 0 means no limited
pinpoint_php.TraceLimit=-1
; DEBUG the agent, PHP's log_error should turn on too.
;pinpoint_php.DebugReport=true
;error_reporting = E_ALL
;log_errors = On
;error_log = /tmp/php_fpm_error.log
```

3. Use Pinpoint PHP-Agent in your project, and follow the steps below:

We assume that you have installed composer and known how to use it. [How to Use Composer?](https://getcomposer.org/doc/00-intro.md)

1. Use `composer require`
```
composer require pinpoint-apm/pinpoint-php-aop:v2.1.0
```
2. Add the following constants in the index file of your project:

```
define('APPLICATION_NAME','APP-2');
define('APPLICATION_ID','app-2');
define('AOP_CACHE_DIR',__DIR__.'./Cache/');
## if yii2
define('PP_REQ_PLUGINS',\Pinpoint\Plugins\Yii2PerRequestPlugins::class);
require_once __DIR__. path to 'vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';
# require_once __DIR__. '/vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';
```
1. ```APPLICATION_NAME```: Application name.
2. ```APPLICATION_ID```: Agent ID.
3. ```AOP_CACHE_DIR```: Where to generate ```Cache```.
4. ```require_once __DIR__. path to 'vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';```: Require pinpoint's ```auto_pinpointed.php```.**Please add after ```require_once __DIR__."/../vendor/autoload.php";```, this is very important!**

>We have prepared some examples for you, try [playground](https://github.com/pinpoint-apm/pinpoint-c-agent/tree/dev/testapps#playground).

1. Install pinpoint_php

curl -sL https://github.com/***pinpoint-apm***/pinpoint-c-agent/releases/download/**v0.1.11**/install_pinpoint_php.sh | sh

2. Check your pinpoint_php.ini is right

```ini
extension=pinpoint_php.so
; Collector-agent's TCP address, ip,port:Collector-Agent's ip,port, please ensure it consistent with the `PP_ADDRESS` of `Collector-Agent` in step2(Build Collector-Agent).
pinpoint_php.CollectorHost=Tcp:ip:port
pinpoint_php.SendSpanTimeOutMs=0 # 0 is recommanded
; request should be captured duing 1 second. < 0 means no limited
pinpoint_php.TraceLimit=-1
; DEBUG the agent, PHP's log_error should turn on too.
;pinpoint_php.DebugReport=true
;error_reporting = E_ALL
;log_errors = On
;error_log = /tmp/php_fpm_error.log
```

3. Install pinpoint-php-aop by composer

composer require -w pinpoint-apm/pinpoint-php-aop

4. Add entry into your `index.php`

```php
// enable `vendor/autoload.php` if need
// require_once __DIR__ . '/vendor/autoload.php';
define('APPLICATION_NAME', 'cd.dev.test.php'); // your application name
define('APPLICATION_ID', 'cd.dev.test.run'); // your application id
define('PP_REQ_PLUGINS', Pinpoint\Plugins\DefaultRequestPlugin::class);
require_once __DIR__ . '/vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';
```

## Changes
>We have prepared some examples for you, try [playground](https://github.com/pinpoint-apm/pinpoint-c-agent/tree/dev/testapps#playground).
- Fully support ZTS
- More stability
- Higher performance
- Easily use and maintain
- Support GRPC

## F & Q
## Feedback & Question

### 1. How to regenerate all AOP files?

Delete *__class_index_table* in Cache/
Delete /tmp/.cache/.__class_index.php

### 2. Why not support automatically update AOP files?
### 2. Why does not support automatically update AOP files?

We can DO but prefer not to DO! Because we have not yet found an efficient way to implement this and monitoring these files status every time is a bad idea.

Expand All @@ -94,9 +71,7 @@ After full test, the AOP code could spend at least 1ms in our env(E5-2660 v4 @ 2

#### Performance Test Result

##### 3.1 [Test Result ☚](./detail_versions.md#performance-loss-under-stress-test)

##### 3.2 [Flarum Test Result ☚](./User%20Manual.md#1.1-performance-result)
On the way

### For the developer

Expand All @@ -108,21 +83,9 @@ After full test, the AOP code could spend at least 1ms in our env(E5-2660 v4 @ 2

#### 1. Exception or error message with a wrong file path.

https://github.com/pinpoint-apm/pinpoint-c-agent/issues/99
https://github.com/pinpoint-apm/pinpoint-c-agent/issues/99

#### 2. If I do not use composer/autoloader, can I use this version?

Sorry, `pinpoint-php-aop` does not support to wrap the user class (or internal class) without composer/autoloader. By the way, [Composer](https://getcomposer.org/) is GOOD. O(∩_∩)O

https://github.com/pinpoint-apm/pinpoint-c-agent/issues/103

#### 3. ~Why not support PHP5.x.~ Already done!

https://www.php.net/supported-versions.php

#### 4. ~Generator function is not supported.~ Already done!

https://github.com/pinpoint-apm/pinpoint-c-agent/issues/100
we supported none framework(yii,tp,...) project,even a simple php script, try example in testapps/php_wordpress,SimplePHP

#### 5. ~Some built-in functions can't AOP~ Already done!
https://github.com/pinpoint-apm/pinpoint-c-agent/issues/102
27 changes: 23 additions & 4 deletions collector-agent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,35 @@ go 1.18

require (
github.com/golang/protobuf v1.5.3
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/onsi/gomega v1.14.0 // indirect
github.com/shirou/gopsutil v3.21.2+incompatible
github.com/shirou/gopsutil/v3 v3.21.2
github.com/sirupsen/logrus v1.8.1
github.com/spaolacci/murmur3 v1.1.0
github.com/stretchr/testify v1.8.3
github.com/x-cray/logrus-prefixed-formatter v0.5.2
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.34.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)

require (
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/onsi/gomega v1.14.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tklauser/go-sysconf v0.3.4 // indirect
github.com/tklauser/numcpus v0.2.1 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 1e7c3f0

Please sign in to comment.