You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2022/09/10 10:24:50 UTC
[skywalking-php] branch master updated: Support MacOS by repalce ipc-channel with socketpair, upgrade dependencies and improve CI. (#9)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-php.git
The following commit(s) were added to refs/heads/master by this push:
new 144a02b Support MacOS by repalce ipc-channel with socketpair, upgrade dependencies and improve CI. (#9)
144a02b is described below
commit 144a02b55ae830d11943af6cf4ff4ca2ff1aebf2
Author: jmjoy <jm...@apache.org>
AuthorDate: Sat Sep 10 18:24:46 2022 +0800
Support MacOS by repalce ipc-channel with socketpair, upgrade dependencies and improve CI. (#9)
---
.asf.yaml | 6 +
.github/workflows/license.yml | 4 +-
.github/workflows/pecl.yml | 33 +++-
.github/workflows/rust.yml | 70 ++++++--
.gitignore | 1 +
Cargo.lock | 396 +++++++++++++++---------------------------
Cargo.toml | 12 +-
.asf.yaml => Vagrantfile | 39 ++---
src/global.rs => build.rs | 27 +--
config.m4 | 9 +-
docker-compose.yml | 8 +-
src/channel.rs | 125 ++++++-------
src/lib.rs | 1 -
src/module.rs | 5 -
src/worker.rs | 14 +-
tests/common/mod.rs | 15 +-
16 files changed, 365 insertions(+), 400 deletions(-)
diff --git a/.asf.yaml b/.asf.yaml
index 7b128c8..8d96edd 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -30,6 +30,12 @@ github:
rebase: false
protected_branches:
master:
+ required_status_checks:
+ strict: true
+ contexts:
+ - license
+ - pecl-required
+ - required
required_pull_request_reviews:
dismiss_stale_reviews: true
required_approving_review_count: 1
diff --git a/.github/workflows/license.yml b/.github/workflows/license.yml
index 7f08004..6a40f82 100644
--- a/.github/workflows/license.yml
+++ b/.github/workflows/license.yml
@@ -24,8 +24,8 @@ on:
- "**"
jobs:
- check:
- name: Check
+ license:
+ name: license
runs-on: ubuntu-20.04
steps:
- name: Checkout
diff --git a/.github/workflows/pecl.yml b/.github/workflows/pecl.yml
index 601d71e..af42373 100644
--- a/.github/workflows/pecl.yml
+++ b/.github/workflows/pecl.yml
@@ -28,10 +28,19 @@ env:
RUST_BACKTRACE: "1"
RUSTFLAGS: "-D warnings"
LLVM_CONFIG_PATH: llvm-config-10
- RUSTUP_HOME: /opt/rustup
- CARGO_HOME: /opt/cargo
+ RUSTUP_HOME: /tmp/rustup
+ CARGO_HOME: /tmp/cargo
jobs:
+ pecl-required:
+ needs:
+ - pecl
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Check results
+ run: |
+ [[ ${{ needs.pecl.result }} == 'success' ]] || exit 1;
+
pecl:
name: PECL
strategy:
@@ -39,6 +48,7 @@ jobs:
matrix:
os:
- ubuntu-20.04
+ - macos-12
version:
- php: "8.1"
swoole: "5.0.0"
@@ -51,8 +61,13 @@ jobs:
submodules: 'recursive'
- name: Install libclang
+ if: matrix.os == 'ubuntu-20.04'
run: sudo apt-get install -y llvm-10-dev libclang-10-dev protobuf-compiler
+ - name: Install protobuf for Macos
+ if: matrix.os == 'macos-12'
+ run: brew install protobuf
+
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
@@ -62,14 +77,14 @@ jobs:
- name: Install Rust Stable Globally
run: |
- curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path
- ln -s $CARGO_HOME/bin/rustup /usr/local/bin/rustup
- ln -s $CARGO_HOME/bin/rustc /usr/local/bin/rustc
- ln -s $CARGO_HOME/bin/cargo /usr/local/bin/cargo
+ curl https://sh.rustup.rs -sSf | sudo -E sh -s -- -y --no-modify-path
+ sudo ln -sf $CARGO_HOME/bin/rustup /usr/local/bin/rustup
+ sudo ln -sf $CARGO_HOME/bin/rustc /usr/local/bin/rustc
+ sudo ln -sf $CARGO_HOME/bin/cargo /usr/local/bin/cargo
- name: PECL install
run: |
- sudo rustup default stable
- sudo cargo run -p scripts --release -- create-package-xml --version 0.0.0 --notes "Just for TEST."
- printf "\n" | sudo pecl install package.xml
+ sudo -E cargo run -p scripts --release -- create-package-xml --version 0.0.0 --notes "Just for TEST."
+ cat package.xml
+ printf "\n" | sudo -E pecl install package.xml
php -d "extension=skywalking_agent" --ri skywalking_agent
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index ce898e1..dba8c50 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -30,6 +30,17 @@ env:
LLVM_CONFIG_PATH: llvm-config-10
jobs:
+ required:
+ needs:
+ - test
+ - fmt
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Check results
+ run: |
+ [[ ${{ needs.test.result }} == 'success' ]] || exit 1;
+ [[ ${{ needs.fmt.result }} == 'success' ]] || exit 1;
+
test:
name: Test
strategy:
@@ -37,6 +48,7 @@ jobs:
matrix:
os:
- ubuntu-20.04
+ - macos-12
version:
# Many composer dependencies need PHP 7.2+
# - php: "7.0"
@@ -59,31 +71,44 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
with:
- submodules: 'recursive'
+ submodules: "recursive"
- - name: Install libclang
+ - name: Install libclang and protobuf for Linux
+ if: matrix.os == 'ubuntu-20.04'
run: sudo apt-get install -y llvm-10-dev libclang-10-dev protobuf-compiler
+ - name: Install protobuf for Macos
+ if: matrix.os == 'macos-12'
+ run: brew install protobuf
+
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.version.php }}
tools: php-config, composer:v2
- extensions: opcache, swoole-${{ matrix.version.swoole }}
+ extensions: >
+ bcmath, calendar, ctype, dom, exif, gettext, iconv, intl, json, mbstring,
+ mysqli, mysqlnd, opcache, pdo, pdo_mysql, phar, posix, readline,
+ swoole-${{ matrix.version.swoole }}, xml, xmlreader, xmlwriter, yaml, zip
- - name: Setup php-fpm
+ - name: Setup php-fpm for Linux
+ if: matrix.os == 'ubuntu-20.04'
run: |
sudo apt-get install -y php${{ matrix.version.php }}-fpm
- sudo rm -f /usr/sbin/php-fpm
- sudo ln -s /usr/sbin/php-fpm${{ matrix.version.php }} /usr/sbin/php-fpm
+ sudo ln -sf /usr/sbin/php-fpm${{ matrix.version.php }} /usr/sbin/php-fpm
- name: PHP version
run: |
+ which php || php --version || php -m
+ which php-fpm || php-fpm --version || php-fpm -m
php-config || true
- /usr/sbin/php-fpm --version
- php -r 'echo "Swoole version: " . phpversion("swoole");'
+ php -r 'echo "Swoole version: " . phpversion("swoole") . "\n";'
composer --version
+ [[ `php --version` == PHP\ ${{ matrix.version.php }}.* ]] || exit 1;
+ [[ `php-fpm --version` == PHP\ ${{ matrix.version.php }}.* ]] || exit 1;
+ [[ `php-config --version` == ${{ matrix.version.php }}.* ]] || exit 1;
+
- name: Install Rust Stable
uses: actions-rs/toolchain@v1
with:
@@ -91,23 +116,39 @@ jobs:
override: true
components: clippy
+ - name: Setup cargo cache
+ uses: actions/cache@v3
+ with:
+ path: |
+ ~/.cargo/bin/
+ ~/.cargo/registry/index/
+ ~/.cargo/registry/cache/
+ ~/.cargo/git/db/
+ target/
+ key: ${{ matrix.os }}-test-${{ matrix.version.php }}-${{ hashFiles('**/Cargo.lock') }}
+
- name: Cargo clippy
uses: actions-rs/cargo@v1
with:
toolchain: stable
command: clippy
- args: --release
+ args: --release --workspace
- name: Cargo build
uses: actions-rs/cargo@v1
with:
toolchain: stable
command: build
- args: --release
+ args: --release --workspace
- name: Docker compose
+ if: matrix.os == 'ubuntu-20.04'
run: docker compose up -d
+ - name: Vagrant up for docker compose
+ if: matrix.os == 'macos-12'
+ run: vagrant up
+
- name: Composer install
run: composer install --working-dir=tests/php
@@ -116,7 +157,12 @@ jobs:
with:
toolchain: stable
command: test
- args: --release
+ args: --release --workspace
+
+ - name: View logs
+ if: always()
+ run: |
+ cat /tmp/*.log
fmt:
name: Fmt
@@ -131,7 +177,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
with:
- submodules: 'recursive'
+ submodules: "recursive"
- name: Install Rust Nightly
uses: actions-rs/toolchain@v1
diff --git a/.gitignore b/.gitignore
index b885819..f52db58 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@
/skywalking_agent-*.tgz
/package.xml
+/.vagrant
*.lo
*.la
diff --git a/Cargo.lock b/Cargo.lock
index 3dc915b..4caee80 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2,6 +2,21 @@
# It is not intended for manual editing.
version = 3
+[[package]]
+name = "addr2line"
+version = "0.17.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
+dependencies = [
+ "gimli",
+]
+
+[[package]]
+name = "adler"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
+
[[package]]
name = "aho-corasick"
version = "0.7.19"
@@ -26,7 +41,7 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -34,6 +49,9 @@ name = "anyhow"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9a8f622bcf6ff3df478e9deba3e03e4e04b300f8e6a139e192c05fa3490afc7"
+dependencies = [
+ "backtrace",
+]
[[package]]
name = "async-stream"
@@ -75,7 +93,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -86,9 +104,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axum"
-version = "0.5.15"
+version = "0.5.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9de18bc5f2e9df8f52da03856bf40e29b747de5a84e43aefff90e3dc4a21529b"
+checksum = "c9e3356844c4d6a6d6467b8da2cffb4a2820be256f50a3a386c9d152bab31043"
dependencies = [
"async-trait",
"axum-core",
@@ -117,9 +135,9 @@ dependencies = [
[[package]]
name = "axum-core"
-version = "0.2.7"
+version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e4f44a0e6200e9d11a1cdc989e4b358f6e3d354fbf48478f345a17f4e43f8635"
+checksum = "d9f0c0a60006f2a293d82d571f635042a72edf927539b7685bd62d361963839b"
dependencies = [
"async-trait",
"bytes",
@@ -127,6 +145,23 @@ dependencies = [
"http",
"http-body",
"mime",
+ "tower-layer",
+ "tower-service",
+]
+
+[[package]]
+name = "backtrace"
+version = "0.3.66"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7"
+dependencies = [
+ "addr2line",
+ "cc",
+ "cfg-if",
+ "libc",
+ "miniz_oxide",
+ "object",
+ "rustc-demangle",
]
[[package]]
@@ -224,12 +259,6 @@ dependencies = [
"nom",
]
-[[package]]
-name = "cfg-if"
-version = "0.1.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
-
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -248,7 +277,7 @@ dependencies = [
"num-traits",
"time 0.1.44",
"wasm-bindgen",
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -360,7 +389,7 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"crossbeam-utils",
]
@@ -370,7 +399,7 @@ version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"once_cell",
]
@@ -390,7 +419,7 @@ version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"hashbrown",
"lock_api",
"once_cell",
@@ -444,7 +473,7 @@ version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
]
[[package]]
@@ -521,30 +550,13 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "form_urlencoded"
-version = "1.0.1"
+version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191"
+checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8"
dependencies = [
- "matches",
"percent-encoding",
]
-[[package]]
-name = "fuchsia-zircon"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
-dependencies = [
- "bitflags",
- "fuchsia-zircon-sys",
-]
-
-[[package]]
-name = "fuchsia-zircon-sys"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
-
[[package]]
name = "futures-channel"
version = "0.3.24"
@@ -613,28 +625,23 @@ dependencies = [
"version_check",
]
-[[package]]
-name = "getrandom"
-version = "0.1.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
-dependencies = [
- "cfg-if 1.0.0",
- "libc",
- "wasi 0.9.0+wasi-snapshot-preview1",
-]
-
[[package]]
name = "getrandom"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
+[[package]]
+name = "gimli"
+version = "0.26.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
+
[[package]]
name = "glob"
version = "0.3.0"
@@ -722,7 +729,7 @@ checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867"
dependencies = [
"libc",
"match_cfg",
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -837,7 +844,7 @@ dependencies = [
"js-sys",
"once_cell",
"wasm-bindgen",
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -851,6 +858,16 @@ dependencies = [
"unicode-normalization",
]
+[[package]]
+name = "idna"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6"
+dependencies = [
+ "unicode-bidi",
+ "unicode-normalization",
+]
+
[[package]]
name = "ignore"
version = "0.4.18"
@@ -885,34 +902,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
- "cfg-if 1.0.0",
-]
-
-[[package]]
-name = "iovec"
-version = "0.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
-dependencies = [
- "libc",
-]
-
-[[package]]
-name = "ipc-channel"
-version = "0.16.0"
-source = "git+https://github.com/servo/ipc-channel.git?branch=master#7f432aab1eb77bb2c860881153799087918558e9"
-dependencies = [
- "bincode",
- "crossbeam-channel",
- "fnv",
- "lazy_static",
- "libc",
- "mio 0.6.23",
- "rand 0.7.3",
- "serde",
- "tempfile",
- "uuid",
- "winapi 0.3.9",
+ "cfg-if",
]
[[package]]
@@ -923,7 +913,7 @@ checksum = "723519edce41262b05d4143ceb95050e4c614f483e78e9fd9e39a8275a84ad98"
dependencies = [
"socket2",
"widestring",
- "winapi 0.3.9",
+ "winapi",
"winreg 0.7.0",
]
@@ -957,16 +947,6 @@ dependencies = [
"wasm-bindgen",
]
-[[package]]
-name = "kernel32-sys"
-version = "0.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
-dependencies = [
- "winapi 0.2.8",
- "winapi-build",
-]
-
[[package]]
name = "lazy_static"
version = "1.4.0"
@@ -991,8 +971,8 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
dependencies = [
- "cfg-if 1.0.0",
- "winapi 0.3.9",
+ "cfg-if",
+ "winapi",
]
[[package]]
@@ -1017,7 +997,7 @@ version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
]
[[package]]
@@ -1066,22 +1046,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
-name = "mio"
-version = "0.6.23"
+name = "miniz_oxide"
+version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4"
+checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"
dependencies = [
- "cfg-if 0.1.10",
- "fuchsia-zircon",
- "fuchsia-zircon-sys",
- "iovec",
- "kernel32-sys",
- "libc",
- "log",
- "miow",
- "net2",
- "slab",
- "winapi 0.2.8",
+ "adler",
]
[[package]]
@@ -1096,18 +1066,6 @@ dependencies = [
"windows-sys",
]
-[[package]]
-name = "miow"
-version = "0.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d"
-dependencies = [
- "kernel32-sys",
- "net2",
- "winapi 0.2.8",
- "ws2_32-sys",
-]
-
[[package]]
name = "multimap"
version = "0.8.3"
@@ -1132,17 +1090,6 @@ dependencies = [
"tempfile",
]
-[[package]]
-name = "net2"
-version = "0.2.37"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae"
-dependencies = [
- "cfg-if 0.1.10",
- "libc",
- "winapi 0.3.9",
-]
-
[[package]]
name = "nom"
version = "7.1.1"
@@ -1191,6 +1138,15 @@ dependencies = [
"libc",
]
+[[package]]
+name = "object"
+version = "0.29.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "once_cell"
version = "1.14.0"
@@ -1204,7 +1160,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0"
dependencies = [
"bitflags",
- "cfg-if 1.0.0",
+ "cfg-if",
"foreign-types",
"libc",
"once_cell",
@@ -1264,7 +1220,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"libc",
"redox_syscall",
"smallvec",
@@ -1288,9 +1244,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "percent-encoding"
-version = "2.1.0"
+version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
+checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pest"
@@ -1372,7 +1328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf"
dependencies = [
"phf_shared",
- "rand 0.8.5",
+ "rand",
]
[[package]]
@@ -1387,9 +1343,9 @@ dependencies = [
[[package]]
name = "phper"
-version = "0.5.0"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a5987d6a0acd980136ddd6684aa68d8cdf1372ad03e0efd36bd026aa2a43307b"
+checksum = "6f00d5aaeb2c801be4ae2b649ca516f3d5673b1b183ff2f60a9fc824ee507442"
dependencies = [
"anyhow",
"clap",
@@ -1406,9 +1362,9 @@ dependencies = [
[[package]]
name = "phper-alloc"
-version = "0.5.0"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "93607a6d5d40fb3500510eaa3664f291ec62483c44fb3f4600f1ce768b5cc832"
+checksum = "b56bc8fe1e25cd77ae79eb5870dd1838e16f2f6bdb5f6c91650e4d2e39d108de"
dependencies = [
"phper-build",
"phper-sys",
@@ -1416,18 +1372,18 @@ dependencies = [
[[package]]
name = "phper-build"
-version = "0.5.0"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b689615085e0d8c771955eda3ebef8382e1e54ffc8d0df2f4faab01a84402e0d"
+checksum = "90c5bdb2c0c9501d557153ac8733b08c01ff8b2d81229a61089ea621786942dd"
dependencies = [
"phper-sys",
]
[[package]]
name = "phper-macros"
-version = "0.5.0"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d8a1f6448e7ca619879e762af0c0762dbed1841394a230f3c10c4681a835799e"
+checksum = "0fb09917092f9a1d9596eb1e0caa943373b686774174d92ce9decc78586145ce"
dependencies = [
"proc-macro2",
"quote",
@@ -1436,9 +1392,9 @@ dependencies = [
[[package]]
name = "phper-sys"
-version = "0.5.0"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "03b1f4f6caa24ac53f32b9af080eab16c98debb562a3cc5b5d8376dcbc42dba9"
+checksum = "bfadd8ae438b9cb5ce35b0f14bdad1755f58b3602c3a54e0b0f048180769b0e0"
dependencies = [
"bindgen",
"cc",
@@ -1484,9 +1440,9 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]]
name = "portable-atomic"
-version = "0.3.14"
+version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e27d61145bec6e13ec8e61feeb490d38de01c2346a804668d036a518a461c0de"
+checksum = "15eb2c6e362923af47e13c23ca5afb859e83d54452c55b0b9ac763b8f7c1ac16"
[[package]]
name = "ppv-lite86"
@@ -1605,19 +1561,6 @@ dependencies = [
"proc-macro2",
]
-[[package]]
-name = "rand"
-version = "0.7.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
-dependencies = [
- "getrandom 0.1.16",
- "libc",
- "rand_chacha 0.2.2",
- "rand_core 0.5.1",
- "rand_hc",
-]
-
[[package]]
name = "rand"
version = "0.8.5"
@@ -1625,18 +1568,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
- "rand_chacha 0.3.1",
- "rand_core 0.6.3",
-]
-
-[[package]]
-name = "rand_chacha"
-version = "0.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
-dependencies = [
- "ppv-lite86",
- "rand_core 0.5.1",
+ "rand_chacha",
+ "rand_core",
]
[[package]]
@@ -1646,16 +1579,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
- "rand_core 0.6.3",
-]
-
-[[package]]
-name = "rand_core"
-version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
-dependencies = [
- "getrandom 0.1.16",
+ "rand_core",
]
[[package]]
@@ -1664,16 +1588,7 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
- "getrandom 0.2.7",
-]
-
-[[package]]
-name = "rand_hc"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
-dependencies = [
- "rand_core 0.5.1",
+ "getrandom",
]
[[package]]
@@ -1708,7 +1623,7 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -1760,6 +1675,12 @@ dependencies = [
"quick-error",
]
+[[package]]
+name = "rustc-demangle"
+version = "0.1.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
+
[[package]]
name = "rustc-hash"
version = "1.1.0"
@@ -1897,7 +1818,7 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"cpufeatures",
"digest",
]
@@ -1941,7 +1862,7 @@ dependencies = [
"async-stream",
"base64",
"bytes",
- "cfg-if 1.0.0",
+ "cfg-if",
"futures-core",
"futures-util",
"portable-atomic",
@@ -1962,13 +1883,13 @@ version = "0.1.0"
dependencies = [
"anyhow",
"axum",
+ "bincode",
"chrono",
"dashmap",
"fastcgi-client",
"futures-util",
"helper",
"hostname",
- "ipc-channel",
"libc",
"once_cell",
"phper",
@@ -2016,7 +1937,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
dependencies = [
"libc",
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -2053,7 +1974,7 @@ dependencies = [
"libc",
"nom",
"time 0.3.14",
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -2062,12 +1983,12 @@ version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"fastrand",
"libc",
"redox_syscall",
"remove_dir_all",
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -2084,7 +2005,7 @@ dependencies = [
"percent-encoding",
"pest",
"pest_derive",
- "rand 0.8.5",
+ "rand",
"regex",
"serde",
"serde_json",
@@ -2144,7 +2065,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -2183,7 +2104,7 @@ dependencies = [
"bytes",
"libc",
"memchr",
- "mio 0.8.4",
+ "mio",
"num_cpus",
"once_cell",
"parking_lot",
@@ -2191,7 +2112,7 @@ dependencies = [
"signal-hook-registry",
"socket2",
"tokio-macros",
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -2238,9 +2159,9 @@ dependencies = [
[[package]]
name = "tokio-util"
-version = "0.7.3"
+version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45"
+checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740"
dependencies = [
"bytes",
"futures-core",
@@ -2252,9 +2173,9 @@ dependencies = [
[[package]]
name = "tonic"
-version = "0.8.0"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "498f271adc46acce75d66f639e4d35b31b2394c295c82496727dafa16d465dd2"
+checksum = "11cd56bdb54ef93935a6a79dbd1d91f1ebd4c64150fd61654031fd6b8b775c91"
dependencies = [
"async-stream",
"async-trait",
@@ -2306,7 +2227,7 @@ dependencies = [
"indexmap",
"pin-project",
"pin-project-lite",
- "rand 0.8.5",
+ "rand",
"slab",
"tokio",
"tokio-util",
@@ -2352,7 +2273,7 @@ version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"log",
"pin-project-lite",
"tracing-attributes",
@@ -2433,17 +2354,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c31f240f59877c3d4bb3b3ea0ec5a6a0cff07323580ff8c7a605cd7d08b255d"
dependencies = [
"async-trait",
- "cfg-if 1.0.0",
+ "cfg-if",
"data-encoding",
"enum-as-inner",
"futures-channel",
"futures-io",
"futures-util",
- "idna",
+ "idna 0.2.3",
"ipnet",
"lazy_static",
"log",
- "rand 0.8.5",
+ "rand",
"smallvec",
"thiserror",
"tinyvec",
@@ -2457,7 +2378,7 @@ version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4ba72c2ea84515690c9fcef4c6c660bb9df3036ed1051686de84605b74fd558"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"futures-util",
"ipconfig",
"lazy_static",
@@ -2571,13 +2492,12 @@ dependencies = [
[[package]]
name = "url"
-version = "2.2.2"
+version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c"
+checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643"
dependencies = [
"form_urlencoded",
- "idna",
- "matches",
+ "idna 0.3.0",
"percent-encoding",
]
@@ -2587,7 +2507,7 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f"
dependencies = [
- "getrandom 0.2.7",
+ "getrandom",
"serde",
]
@@ -2616,7 +2536,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [
"same-file",
- "winapi 0.3.9",
+ "winapi",
"winapi-util",
]
@@ -2630,12 +2550,6 @@ dependencies = [
"try-lock",
]
-[[package]]
-name = "wasi"
-version = "0.9.0+wasi-snapshot-preview1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
-
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
@@ -2654,7 +2568,7 @@ version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"wasm-bindgen-macro",
]
@@ -2679,7 +2593,7 @@ version = "0.4.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad"
dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
@@ -2741,12 +2655,6 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983"
-[[package]]
-name = "winapi"
-version = "0.2.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
-
[[package]]
name = "winapi"
version = "0.3.9"
@@ -2757,12 +2665,6 @@ dependencies = [
"winapi-x86_64-pc-windows-gnu",
]
-[[package]]
-name = "winapi-build"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
-
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
@@ -2775,7 +2677,7 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -2833,7 +2735,7 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69"
dependencies = [
- "winapi 0.3.9",
+ "winapi",
]
[[package]]
@@ -2842,15 +2744,5 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
- "winapi 0.3.9",
-]
-
-[[package]]
-name = "ws2_32-sys"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
-dependencies = [
- "winapi 0.2.8",
- "winapi-build",
+ "winapi",
]
diff --git a/Cargo.toml b/Cargo.toml
index dc2639c..c68a310 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -36,26 +36,26 @@ name = "skywalking_agent"
crate-type = ["lib", "cdylib"]
[dependencies]
-anyhow = "1.0.63"
+anyhow = { version = "1.0.64", features = ["backtrace"] }
+bincode = "1.3.3"
chrono = "0.4.22"
dashmap = "5.4.0"
futures-util = "0.3.24"
helper = "3.3.0"
hostname = "0.3.1"
-ipc-channel = { git = "https://github.com/servo/ipc-channel.git", branch = "master" }
libc = "0.2.132"
-once_cell = "1.13.1"
-phper = "0.5.0"
+once_cell = "1.14.0"
+phper = "0.5.1"
prost = "0.11.0"
skywalking = "0.4.0"
systemstat = "0.2.0"
-tokio = { version = "1.20.1", features = ["full"] }
+tokio = { version = "1.21.0", features = ["full"] }
tokio-stream = "0.1.9"
tonic = "0.8.0"
tracing = { version = "0.1.36", features = ["attributes"] }
tracing-appender = "0.2.2"
tracing-subscriber = "0.3.15"
-url = "2.2.2"
+url = "2.3.0"
[dev-dependencies]
axum = "0.5.15"
diff --git a/.asf.yaml b/Vagrantfile
similarity index 56%
copy from .asf.yaml
copy to Vagrantfile
index 7b128c8..6e8e8b2 100644
--- a/.asf.yaml
+++ b/Vagrantfile
@@ -13,23 +13,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-github:
- description: Apache SkyWalking PHP Agent
- homepage: https://skywalking.apache.org/
- labels:
- - skywalking
- - observability
- - apm
- - distributed-tracing
- - service-mesh
- - dapper
- - php
- enabled_merge_buttons:
- squash: true
- merge: false
- rebase: false
- protected_branches:
- master:
- required_pull_request_reviews:
- dismiss_stale_reviews: true
- required_approving_review_count: 1
+Vagrant.configure("2") do |config|
+ config.vm.box = "generic/alpine316"
+ config.vm.box_version = "4.1.10"
+ config.vm.box_check_update = false
+
+ config.vm.network "forwarded_port", guest: 19876, host: 19876
+ config.vm.network "forwarded_port", guest: 12800, host: 12800
+ config.vm.network "forwarded_port", guest: 6379, host: 6379
+
+ config.vm.synced_folder ".", "/vagrant"
+
+ config.vm.provision "shell", inline: <<-SHELL
+ apk add --no-cache docker docker-cli-compose
+ service docker restart
+ sleep 3
+ cd /vagrant
+ sudo docker compose up -d
+ SHELL
+end
diff --git a/src/global.rs b/build.rs
similarity index 56%
rename from src/global.rs
rename to build.rs
index 5ead796..dd029df 100644
--- a/src/global.rs
+++ b/build.rs
@@ -13,25 +13,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use ipc_channel::ipc::IpcSharedMemory;
-use once_cell::sync::Lazy;
-use std::{
- mem::{size_of, transmute},
- sync::atomic::AtomicUsize,
-};
-
-#[derive(Default)]
-pub struct Global {
- pub channel_size: AtomicUsize,
- // pub worker_pid: AtomicU32,
+fn main() {
+ #[cfg(target_os = "macos")]
+ {
+ println!("cargo:rustc-link-arg=-undefined");
+ println!("cargo:rustc-link-arg=dynamic_lookup");
+ }
}
-
-/// Global shared memory.
-pub static GLOBAL: Lazy<&Global> = Lazy::new(|| {
- static SHARE: Lazy<IpcSharedMemory> = Lazy::new(|| {
- let buf: [u8; size_of::<Global>()] = unsafe { transmute(Global::default()) };
- IpcSharedMemory::from_bytes(&buf)
- });
- let share: &[u8] = &SHARE;
- unsafe { (share.as_ptr() as *const Global).as_ref().unwrap() }
-});
diff --git a/config.m4 b/config.m4
index 6b280ab..132194f 100644
--- a/config.m4
+++ b/config.m4
@@ -49,7 +49,13 @@ if test "$PHP_SKYWALKING_AGENT" != "no"; then
CARGO_MODE_DIR="debug"
fi
- echo -e "./modules/skywalking_agent.so:\n\tPHP_CONFIG=$PHP_PHP_CONFIG cargo build $CARGO_MODE_FLAGS\n\tcp ./target/$CARGO_MODE_DIR/libskywalking_agent.so ./modules/skywalking_agent.so" > Makefile.objects
+ echo -e "./modules/skywalking_agent.so:\n\
+\tPHP_CONFIG=$PHP_PHP_CONFIG cargo build $CARGO_MODE_FLAGS\n\
+\tif [[ -f ./target/$CARGO_MODE_DIR/libskywalking_agent.dylib ]] ; then \
+cp ./target/$CARGO_MODE_DIR/libskywalking_agent.dylib ./modules/skywalking_agent.so ; fi\n\
+\tif [[ -f ./target/$CARGO_MODE_DIR/libskywalking_agent.so ]] ; then \
+cp ./target/$CARGO_MODE_DIR/libskywalking_agent.so ./modules/skywalking_agent.so ; fi\n\
+" > Makefile.objects
PHP_MODULES="./modules/skywalking_agent.so"
@@ -60,6 +66,7 @@ if test "$PHP_SKYWALKING_AGENT" != "no"; then
LICENSE:LICENSE \
NOTICE:NOTICE \
README.md:README.md \
+ build.rs:build.rs \
docker-compose.yml:docker-compose.yml \
docs:docs \
scripts:scripts \
diff --git a/docker-compose.yml b/docker-compose.yml
index b29c095..69a3a24 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -17,8 +17,8 @@ services:
collector:
image: ghcr.io/apache/skywalking-agent-test-tool/mock-collector:f4f5ef22b1df623464772816bb6b42ba611444ff
ports:
- - "127.0.0.1:19876:19876"
- - "127.0.0.1:12800:12800"
+ - "19876:19876"
+ - "12800:12800"
healthcheck:
test: [ "CMD", "curl", "http://127.0.0.1:12800/healthCheck" ]
interval: 5s
@@ -27,7 +27,7 @@ services:
mysql:
image: mysql:5.7.39
ports:
- - "127.0.0.1:3306:3306"
+ - "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=skywalking
@@ -35,6 +35,6 @@ services:
redis:
image: bitnami/redis:7.0.4
ports:
- - "127.0.0.1:6379:6379"
+ - "6379:6379"
environment:
- REDIS_PASSWORD=password
diff --git a/src/channel.rs b/src/channel.rs
index ba07882..abd786c 100644
--- a/src/channel.rs
+++ b/src/channel.rs
@@ -13,32 +13,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use crate::global::GLOBAL;
use anyhow::{anyhow, bail, Context};
-use ipc_channel::ipc::{self, IpcReceiver, IpcSender, TryRecvError};
use once_cell::sync::OnceCell;
use skywalking::reporter::{grpc::ColletcItemConsume, CollectItem, Report};
use std::{
- error::Error,
- sync::{atomic::Ordering, Mutex},
+ error::Error, io, mem::size_of, os::unix::net::UnixDatagram as StdUnixDatagram, sync::Mutex,
};
-use tokio::task;
+use tokio::net::UnixDatagram;
use tonic::async_trait;
-use tracing::{debug, error};
+use tracing::error;
-const MAX_COUNT: usize = 1000;
-
-static SENDER: OnceCell<Mutex<IpcSender<CollectItem>>> = OnceCell::new();
-static RECEIVER: OnceCell<Mutex<IpcReceiver<CollectItem>>> = OnceCell::new();
+static SENDER: OnceCell<StdUnixDatagram> = OnceCell::new();
+static RECEIVER: OnceCell<Mutex<Option<StdUnixDatagram>>> = OnceCell::new();
pub fn init_channel() -> anyhow::Result<()> {
- let channel = ipc::channel()?;
+ let (sender, receiver) = StdUnixDatagram::pair()?;
+ sender.set_nonblocking(true)?;
+ receiver.set_nonblocking(true)?;
- if SENDER.set(Mutex::new(channel.0)).is_err() {
+ if SENDER.set(sender).is_err() {
bail!("Channel has initialized");
}
- if RECEIVER.set(Mutex::new(channel.1)).is_err() {
+ if RECEIVER.set(Mutex::new(Some(receiver))).is_err() {
bail!("Channel has initialized");
}
@@ -46,48 +43,48 @@ pub fn init_channel() -> anyhow::Result<()> {
}
fn channel_send(data: CollectItem) -> anyhow::Result<()> {
- let old_count = GLOBAL.channel_size.fetch_add(1, Ordering::SeqCst);
- if old_count >= MAX_COUNT {
- bail!("Channel is fulled");
- }
- debug!("Channel remainder count: {}", old_count);
+ let buf = bincode::serialize(&data)?;
+
+ let sender = SENDER.get().context("Channel haven't initialized")?;
- SENDER
- .get()
- .context("Channel haven't initialized")?
- .lock()
- .map_err(|_| anyhow!("Get lock failed"))?
- .send(data)?;
+ sender.send(&buf.len().to_le_bytes())?;
+ sender.send(&buf)?;
Ok(())
}
-fn channel_receive() -> anyhow::Result<CollectItem> {
- let receiver = RECEIVER
- .get()
- .context("Channel haven't initialized")?
- .lock()
- .map_err(|_| anyhow!("Get lock failed"))?;
+async fn channel_receive(receiver: &UnixDatagram) -> anyhow::Result<CollectItem> {
+ let mut size_buf = [0u8; size_of::<usize>()];
+ receiver.recv(&mut size_buf).await?;
+ let size = usize::from_le_bytes(size_buf);
- let r = receiver.recv();
- GLOBAL.channel_size.fetch_sub(1, Ordering::SeqCst);
- Ok(r?)
+ let mut buf = vec![0u8; size];
+ receiver.recv(&mut buf).await?;
+
+ let item = bincode::deserialize(&buf)?;
+ Ok(item)
}
-fn channel_try_receive() -> anyhow::Result<Option<CollectItem>> {
- let receiver = RECEIVER
- .get()
- .context("Channel haven't initialized")?
- .lock()
- .map_err(|_| anyhow!("Get lock failed"))?;
-
- let r = match receiver.try_recv() {
- Ok(data) => Ok(Some(data)),
- Err(TryRecvError::Empty) => Ok(None),
- Err(e) => Err(e.into()),
- };
- GLOBAL.channel_size.fetch_sub(1, Ordering::SeqCst);
- r
+fn channel_try_receive(receiver: &UnixDatagram) -> anyhow::Result<Option<CollectItem>> {
+ let mut size_buf = [0u8; size_of::<usize>()];
+ if let Err(e) = receiver.try_recv(&mut size_buf) {
+ if e.kind() == io::ErrorKind::WouldBlock {
+ return Ok(None);
+ }
+ return Err(e.into());
+ }
+ let size = usize::from_le_bytes(size_buf);
+
+ let mut buf = vec![0u8; size];
+ if let Err(e) = receiver.try_recv(&mut buf) {
+ if e.kind() == io::ErrorKind::WouldBlock {
+ return Ok(None);
+ }
+ return Err(e.into());
+ }
+
+ let item = bincode::deserialize(&buf)?;
+ Ok(item)
}
pub struct Reporter;
@@ -100,27 +97,35 @@ impl Report for Reporter {
}
}
-pub struct Consumer;
+pub struct Consumer(UnixDatagram);
+
+impl Consumer {
+ pub fn new() -> anyhow::Result<Self> {
+ let receiver = RECEIVER.get().context("Channel haven't initialized")?;
+ let receiver = receiver
+ .lock()
+ .map_err(|_| anyhow!("Get Lock failed"))?
+ .take()
+ .context("The RECEIVER has been taked")?;
+ let receiver =
+ UnixDatagram::from_std(receiver).context("try into tokio unix datagram failed")?;
+ Ok(Self(receiver))
+ }
+}
#[async_trait]
impl ColletcItemConsume for Consumer {
async fn consume(&mut self) -> Result<Option<CollectItem>, Box<dyn Error + Send>> {
- match task::spawn_blocking(channel_receive).await {
- Ok(r) => match r {
- Ok(item) => Ok(Some(item)),
- Err(e) => Err(e.into()),
- },
- Err(e) => Err(Box::new(e)),
+ match channel_receive(&self.0).await {
+ Ok(item) => Ok(Some(item)),
+ Err(e) => Err(e.into()),
}
}
async fn try_consume(&mut self) -> Result<Option<CollectItem>, Box<dyn Error + Send>> {
- match task::spawn_blocking(channel_try_receive).await {
- Ok(r) => match r {
- Ok(item) => Ok(item),
- Err(e) => Err(e.into()),
- },
- Err(e) => Err(Box::new(e)),
+ match channel_try_receive(&self.0) {
+ Ok(item) => Ok(item),
+ Err(e) => Err(e.into()),
}
}
}
diff --git a/src/lib.rs b/src/lib.rs
index c36ccee..b20294a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -21,7 +21,6 @@ mod channel;
mod component;
mod context;
mod execute;
-mod global;
mod module;
mod plugin;
mod request;
diff --git a/src/module.rs b/src/module.rs
index 44633b8..ea96f16 100644
--- a/src/module.rs
+++ b/src/module.rs
@@ -16,7 +16,6 @@
use crate::{
channel::{self, init_channel},
execute::register_execute_functions,
- global::GLOBAL,
util::{get_sapi_module_name, IPS},
worker::init_worker,
SKYWALKING_AGENT_ENABLE, SKYWALKING_AGENT_LOG_FILE, SKYWALKING_AGENT_LOG_LEVEL,
@@ -47,12 +46,8 @@ pub fn init(_module: ModuleContext) -> bool {
return true;
}
- Lazy::force(&GLOBAL);
-
init_logger();
- // get_ready_for_request();
-
if let Err(e) = init_channel() {
error!("Init channel failed: {}", e);
return true;
diff --git a/src/worker.rs b/src/worker.rs
index 6efccef..fdccb33 100644
--- a/src/worker.rs
+++ b/src/worker.rs
@@ -14,7 +14,6 @@
// limitations under the License.
use crate::{channel, SKYWALKING_AGENT_SERVER_ADDR, SKYWALKING_AGENT_WORKER_THREADS};
-use libc::{fork, prctl, PR_SET_PDEATHSIG, SIGTERM};
use phper::ini::Ini;
use skywalking::reporter::grpc::GrpcReporter;
use std::{
@@ -38,13 +37,12 @@ pub fn init_worker() {
// operation.
// TODO Chagne the worker process name.
- let pid = fork();
+ let pid = libc::fork();
match pid.cmp(&0) {
Ordering::Less => {
error!("fork failed");
}
Ordering::Equal => {
- prctl(PR_SET_PDEATHSIG, SIGTERM);
let rt = new_tokio_runtime(worker_threads);
rt.block_on(start_worker(server_addr));
exit(0);
@@ -65,6 +63,7 @@ fn worker_threads() -> usize {
fn new_tokio_runtime(worker_threads: usize) -> Runtime {
runtime::Builder::new_multi_thread()
+ .thread_name("sw: worker")
.enable_all()
.worker_threads(worker_threads)
.build()
@@ -93,7 +92,14 @@ async fn start_worker(server_addr: String) {
};
let channel = connect(endpoint).await;
- let reporter = GrpcReporter::new_with_pc(channel, (), channel::Consumer);
+ let consumer = match channel::Consumer::new() {
+ Ok(consumer) => consumer,
+ Err(err) => {
+ error!(?err, "Create consumer failed");
+ return;
+ }
+ };
+ let reporter = GrpcReporter::new_with_pc(channel, (), consumer);
// report_instance_properties(channel.clone()).await;
// mark_ready_for_request();
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 226ab48..6701063 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -27,6 +27,7 @@ use libc::{kill, pid_t, SIGTERM};
use once_cell::sync::Lazy;
use std::{
env,
+ fs::File,
io::{self, Cursor},
net::SocketAddr,
process::{ExitStatus, Stdio},
@@ -56,6 +57,14 @@ pub const TARGET: &str = if cfg!(debug_assertions) {
"release"
};
+pub const EXT: &str = if cfg!(target_os = "linux") {
+ ".so"
+} else if cfg!(target_os = "macos") {
+ ".dylib"
+} else {
+ ""
+};
+
pub static HTTP_CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
pub struct Fixture {
@@ -244,7 +253,7 @@ fn setup_php_fpm(index: usize, fpm_addr: &str) -> Child {
"-c",
"tests/conf/php.ini",
"-d",
- &format!("extension=target/{}/libskywalking_agent.so", TARGET),
+ &format!("extension=target/{}/libskywalking_agent{}", TARGET, EXT),
"-d",
"skywalking_agent.enable=On",
"-d",
@@ -271,8 +280,8 @@ fn setup_php_fpm(index: usize, fpm_addr: &str) -> Child {
Command::new(&args[0])
.args(&args[1..])
.stdin(Stdio::null())
- .stdout(Stdio::null())
- .stderr(Stdio::null())
+ .stdout(File::create("/tmp/fpm-skywalking-stdout.log").unwrap())
+ .stderr(File::create("/tmp/fpm-skywalking-stderr.log").unwrap())
.spawn()
.unwrap()
}