-
-
Notifications
You must be signed in to change notification settings - Fork 27
refactor(sentry): improve timer cleanup in metrics listeners #1046
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,7 @@ | |
| use FriendsOfHyperf\Sentry\Feature; | ||
| use FriendsOfHyperf\Sentry\Metrics\Event\MetricFactoryReady; | ||
| use FriendsOfHyperf\Sentry\Metrics\Traits\MetricSetter; | ||
| use Hyperf\Coordinator\Constants; | ||
| use Hyperf\Coordinator\CoordinatorManager; | ||
| use Hyperf\Coordinator\Timer; | ||
| use Hyperf\Engine\Coroutine; | ||
| use Hyperf\Event\Contract\ListenerInterface; | ||
| use Hyperf\Server\Event\MainCoroutineServerStart; | ||
| use Psr\Container\ContainerInterface; | ||
|
|
@@ -100,7 +97,11 @@ public function process(object $event): void | |
| 'ru_stime_tv_sec', | ||
| ]; | ||
|
|
||
| $timerId = $this->timer->tick($this->feature->getMetricsInterval(), function () use ($metrics) { | ||
| $this->timer->tick($this->feature->getMetricsInterval(), function ($isClosing = false) use ($metrics) { | ||
| if ($isClosing) { | ||
| return Timer::STOP; | ||
| } | ||
|
Comment on lines
+100
to
+103
|
||
|
|
||
| defer(fn () => metrics()->flush()); | ||
|
|
||
| $this->trySet('gc_', $metrics, gc_status()); | ||
|
|
@@ -119,10 +120,5 @@ public function process(object $event): void | |
| Unit::megabyte() | ||
| ); | ||
| }); | ||
|
|
||
| Coroutine::create(function () use ($timerId) { | ||
| CoordinatorManager::until(Constants::WORKER_EXIT)->yield(); | ||
| $this->timer->clear($timerId); | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,6 @@ | |
| use FriendsOfHyperf\Sentry\Metrics\CoroutineServerStats; | ||
| use FriendsOfHyperf\Sentry\Metrics\Event\MetricFactoryReady; | ||
| use FriendsOfHyperf\Sentry\Metrics\Traits\MetricSetter; | ||
| use Hyperf\Coordinator\Constants; | ||
| use Hyperf\Coordinator\CoordinatorManager; | ||
| use Hyperf\Coordinator\Timer; | ||
| use Hyperf\Engine\Coroutine; | ||
| use Hyperf\Event\Contract\ListenerInterface; | ||
|
|
@@ -98,7 +96,11 @@ public function process(object $event): void | |
| } | ||
| } | ||
|
|
||
| $timerId = $this->timer->tick($this->feature->getMetricsInterval(), function () use ($metrics, $serverStatsFactory, $workerId) { | ||
| $this->timer->tick($this->feature->getMetricsInterval(), function ($isClosing = false) use ($metrics, $serverStatsFactory, $workerId) { | ||
| if ($isClosing) { | ||
| return Timer::STOP; | ||
| } | ||
|
Comment on lines
+99
to
+102
|
||
|
|
||
| defer(fn () => metrics()->flush()); | ||
|
|
||
| $this->trySet('', $metrics, Coroutine::stats(), $workerId); | ||
|
|
@@ -131,10 +133,5 @@ public function process(object $event): void | |
| Unit::megabyte() | ||
| ); | ||
| }); | ||
|
|
||
| Coroutine::create(function () use ($timerId) { | ||
| CoordinatorManager::until(Constants::WORKER_EXIT)->yield(); | ||
| $this->timer->clear($timerId); | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,7 @@ | |
| use FriendsOfHyperf\Sentry\Feature; | ||
| use FriendsOfHyperf\Sentry\Metrics\Event\MetricFactoryReady; | ||
| use FriendsOfHyperf\Sentry\Metrics\Traits\MetricSetter; | ||
| use Hyperf\Coordinator\Constants; | ||
| use Hyperf\Coordinator\CoordinatorManager; | ||
| use Hyperf\Coordinator\Timer; | ||
| use Hyperf\Engine\Coroutine; | ||
| use Hyperf\Event\Contract\ListenerInterface; | ||
| use Hyperf\Framework\Event\BeforeWorkerStart; | ||
| use Psr\Container\ContainerInterface; | ||
|
|
@@ -90,7 +87,11 @@ public function process(object $event): void | |
| 'ru_stime_tv_sec', | ||
| ]; | ||
|
|
||
| $timerId = $this->timer->tick($this->feature->getMetricsInterval(), function () use ($metrics, $event) { | ||
| $this->timer->tick($this->feature->getMetricsInterval(), function ($isClosing = false) use ($metrics, $event) { | ||
| if ($isClosing) { | ||
| return Timer::STOP; | ||
| } | ||
|
Comment on lines
+90
to
+93
This comment was marked as outdated.
Sorry, something went wrong.
Comment on lines
+90
to
+93
|
||
|
|
||
| defer(fn () => metrics()->flush()); | ||
|
|
||
| $server = $this->container->get(Server::class); | ||
|
|
@@ -121,10 +122,5 @@ public function process(object $event): void | |
| Unit::megabyte() | ||
| ); | ||
| }); | ||
|
|
||
| Coroutine::create(function () use ($timerId) { | ||
| CoordinatorManager::until(Constants::WORKER_EXIT)->yield(); | ||
| $this->timer->clear($timerId); | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,7 @@ | |
| namespace FriendsOfHyperf\Sentry\Metrics\Listener; | ||
|
|
||
| use FriendsOfHyperf\Sentry\Feature; | ||
| use Hyperf\Coordinator\Constants; | ||
| use Hyperf\Coordinator\CoordinatorManager; | ||
| use Hyperf\Coordinator\Timer; | ||
| use Hyperf\Engine\Coroutine; | ||
| use Hyperf\Event\Contract\ListenerInterface; | ||
| use Hyperf\Framework\Event\BeforeWorkerStart; | ||
| use Hyperf\Pool\Pool; | ||
|
|
@@ -65,11 +62,15 @@ public function watch(Pool $pool, string $poolName, int $workerId): void | |
| return; | ||
| } | ||
|
|
||
| $timerId = $this->timer->tick($this->feature->getMetricsInterval(), function () use ( | ||
| $this->timer->tick($this->feature->getMetricsInterval(), function ($isClosing = false) use ( | ||
| $pool, | ||
| $workerId, | ||
| $poolName | ||
| ) { | ||
| if ($isClosing) { | ||
| return Timer::STOP; | ||
| } | ||
|
Comment on lines
+65
to
+72
|
||
|
|
||
| defer(fn () => metrics()->flush()); | ||
|
|
||
| metrics()->gauge( | ||
|
|
@@ -97,10 +98,5 @@ public function watch(Pool $pool, string $poolName, int $workerId): void | |
| ] | ||
| ); | ||
| }); | ||
|
|
||
| Coroutine::create(function () use ($timerId) { | ||
| CoordinatorManager::until(Constants::WORKER_EXIT)->yield(); | ||
| $this->timer->clear($timerId); | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,7 @@ | |
| use FriendsOfHyperf\Sentry\Metrics\Event\MetricFactoryReady; | ||
| use Hyperf\AsyncQueue\Driver\DriverFactory; | ||
| use Hyperf\Contract\ConfigInterface; | ||
| use Hyperf\Coordinator\Constants; | ||
| use Hyperf\Coordinator\CoordinatorManager; | ||
| use Hyperf\Coordinator\Timer; | ||
| use Hyperf\Engine\Coroutine; | ||
| use Hyperf\Event\Contract\ListenerInterface; | ||
| use Psr\Container\ContainerInterface; | ||
|
|
||
|
|
@@ -55,7 +52,11 @@ public function process(object $event): void | |
| return; | ||
| } | ||
|
|
||
| $timerId = $this->timer->tick($this->feature->getMetricsInterval(), function () { | ||
| $this->timer->tick($this->feature->getMetricsInterval(), function ($isClosing = false) { | ||
| if ($isClosing) { | ||
| return Timer::STOP; | ||
| } | ||
|
Comment on lines
+55
to
+58
|
||
|
|
||
| defer(fn () => metrics()->flush()); | ||
|
|
||
| $config = $this->container->get(ConfigInterface::class); | ||
|
|
@@ -87,10 +88,5 @@ public function process(object $event): void | |
| ); | ||
| } | ||
| }); | ||
|
|
||
| Coroutine::create(function () use ($timerId) { | ||
| CoordinatorManager::until(Constants::WORKER_EXIT)->yield(); | ||
| $this->timer->clear($timerId); | ||
| }); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.