-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add Memcached Reporter #206
Conversation
@Clivern thanks for starting this
I have a question regarding this, do we truly need such a daemon? I can think of: on reporting if the time has passed or if the max size has been reached we run the reporter. Does that sound reasonable? Also we should consider the max size for reporting, even with the daemon we should know how big is the reporting payload because server might have a limit (e.g. in zipkin-go it is https://github.com/openzipkin/zipkin-go/blob/master/reporter/http/http.go#L37) |
Thanks @jcchavezs for the review, i will check them case by case. |
It make sense, if you want to collect and send from one process. I tried to be flexible, didn't want to enforce a certain approach and also if you want to remove the daemon, you can simply run the above on each incoming request to the application, like middleware but still it is a lot to do indeed. So i can add that piece of logic too so memcached reporter will do the aggregation and reporting to zipkin if configurable size or time reached. only issue i see, when reporting time reached, reporting to zipkin will slow down things a bit but should be fine. include_once dirname(__FILE__) . "/vendor/autoload.php";
use Zipkin\Reporters\Aggregation\MemcachedClient;
use Zipkin\Reporters\Memcached;
use Zipkin\Reporters\Http;
$reporter = new Memcached([], new MemcachedClient('127.0.0.1'));
$httpReporter = new Http(['endpoint_url' => 'http://zipkin.local:9411/api/v2/spans']);
$last_reporting_time = /*call memcached here*/
if(time() - $last_reporting_time > 86400) {
$spans = $reporter->flush();
if (!empty($spans)){
$httpReporter->report($spans);
}
} |
So I think:
Does that make sense? |
Yes, will apply the first point first (aggregate & report in a single process) & from there, we can see how to make it easy for everyone to opt-in and opt-out by changing |
This is great work @Clivern I just added a couple of comments then I am happy to merge it. |
@jcchavezs I added test cases, did a few changes & tested it manually so please review it again. |
Great work @Clivern! I will merge it as soon as it gets green. |
it passes now locally, just trigger it one more time. $ zipkin-php git:(master) composer static-check
> phpstan analyse src --level 8
Note: Using configuration file /Users/Clivern/oss/zipkin-php/phpstan.neon.
72/72 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
[OK] No errors
$ composer test
> phpunit tests
PHPUnit 9.5.5 by Sebastian Bergmann and contributors.
............................................................... 63 / 210 ( 30%)
............................................................... 126 / 210 ( 60%)
............................................................... 189 / 210 ( 90%)
..................... 210 / 210 (100%)
Time: 00:01.358, Memory: 14.00 MB
OK (210 tests, 477 assertions) |
do you mind rebasing, I just added this #207 which I think will fix the problem. If this does not fix it I will merge this PR as it is. |
done |
it seems the github action |
Maybe we try specifing memcached explicitly?
shivammathur/setup-php#423 (comment)
José Carlos Chávez
ons. 30. jun. 2021 kl. 12:17 skrev Ahmed ***@***.***>:
… it seems the github action shivammathur/setup-php doesn't install
memcached extension even it is there.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#206 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXOYAWJTIIAE5CAWW63PX3TVLVMZANCNFSM46M3HGXA>
.
|
nope! it doesn't work, i tested it. they don't mention windows at all, all about ubuntu. not surprised! should be hard to get things right on windows (download extension dll file and append to php.ini) only workaround i can think of right now is to add the following to top of test cases in https://github.com/openzipkin/zipkin-php/blob/master/tests/Unit/Reporters/MemcachedTest.php. anyways sdk must work even if memcached not there and repository ubuntu workflow works fine with memcached extension. if (!class_exists('\Memcached')) {
$this->markTestSkipped('Memcached extension is missing.');
return;
} composer test
Do not run Composer as root/super user! See https://getcomposer.org/root for details
> phpunit tests
PHPUnit 9.5.6 by Sebastian Bergmann and contributors.
............................................................... 63 / 210 ( 30%)
............................................................... 126 / 210 ( 60%)
.....................SSSSSSSSSSSSSS............................ 189 / 210 ( 90%)
..................... 210 / 210 (100%)
Time: 00:00.172, Memory: 12.00 MB
OK, but incomplete, skipped, or risky tests!
Tests: 210, Assertions: 447, Skipped: 14. in that case we will have to skip these two files from phpstan analysis by adding these to end of excludePaths:
analyse:
- src/Zipkin/Reporters/Aggregation/MemcachedClient.php
- src/Zipkin/Reporters/Memcached.php |
Sounds like a good tradeoff for now. Do you ming opening a PR for that?
José Carlos Chávez
ons. 30. jun. 2021 kl. 15:18 skrev Ahmed ***@***.***>:
… nope! it doesn't work, i tested it. they don't mention windows at all, all
about ubuntu. not surprised! should be hard to get things right on windows
only workaround i can think of right now is to add the following to top of
test cases in
https://github.com/openzipkin/zipkin-php/blob/master/tests/Unit/Reporters/MemcachedTest.php.
anyways sdk must work even if memcached not there and repository ubuntu
workflow works fine with memcached extension.
if (!class_exists('\Memcached')) {
$this->markTestSkipped('Memcached extension is missing.');
return;
}
composer test
Do not run Composer as root/super user! See https://getcomposer.org/root for details> phpunit tests
PHPUnit 9.5.6 by Sebastian Bergmann and contributors.
............................................................... 63 / 210 ( 30%)
............................................................... 126 / 210 ( 60%)
.....................SSSSSSSSSSSSSS............................ 189 / 210 ( 90%)
..................... 210 / 210 (100%)
Time: 00:00.172, Memory: 12.00 MB
OK, but incomplete, skipped, or risky tests!
Tests: 210, Assertions: 447, Skipped: 14.
in that case we will have to skip these two files from phpstan analysis by
adding these to end of phpstan.neon. didn't find a better way so far to
bypass "not found memcached class" error if class not exist.
excludePaths:
analyse:
- src/Zipkin/Reporters/Aggregation/MemcachedClient.php
- src/Zipkin/Reporters/Memcached.php
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#206 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXOYATHSWQCMLXKJ4KSBZTTVMKTLANCNFSM46M3HGXA>
.
|
I moved this code temporary to a branch, I need to release 3.0 and I would like to do some tweaks to the implementation but I don't want to block 3.0 so this is most likely included in 3.1. |
This PR adds memcached reporter. So basically it is similar to
InMemory
but it stores the value in a memcached server. It also should work as expected in case of concurrent reads and writes. it uses this feature from memcached https://www.php.net/manual/en/memcached.cas.php. This requiresphp-memcached
extension, so it will be a breaking change.Usage
In application, we use
Memcached
reporter notHTTP
reporter.Then we create a cron job or a command to read from
Memcached
reporter and send toZipkin
usingHTTP
reporter. We may even add this as application middleware with a time interval.Flushing can be based on a time interval or the stored value size (Memcached support value up to 1MB by default that's ~1000000 chars). i didn't add any implementation since it is totally up to the developer and the scale zipkin is used. reporting 2 spans/second will have a different implementation than 1000 spans/second and I think this shouldn't be part of the package. in case you will hit the 1MB size limit in a second, you can either increase memcached maximum object size or report with different memcached keys, so basically you split the collected spans across different memcached keys to get more space before flushing.
Please let me know if something need to be adjusted!
Fix #22
Update:
To run as single process