Skip to content

Commit

Permalink
Use self instead of static for resolving recorder config (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher authored Nov 3, 2023
1 parent 083b02e commit ab91bfa
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Recorders/CacheInteractions.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function record(CacheHit|CacheMissed $event): ?Entry
protected function normalizeKey(string $key): Closure
{
return function () use ($key) {
foreach ($this->config->get('pulse.recorders.'.static::class.'.groups') as $pattern => $replacement) {
foreach ($this->config->get('pulse.recorders.'.self::class.'.groups') as $pattern => $replacement) {
$normalized = preg_replace($pattern, $replacement, $key, count: $count);

if ($count > 0 && $normalized !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/Concerns/Ignores.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait Ignores
protected function shouldIgnore(string $value): bool
{
// @phpstan-ignore argument.templateType, argument.templateType
return collect($this->config->get('pulse.recorders.'.static::class.'.ignore'))
return collect($this->config->get('pulse.recorders.'.self::class.'.ignore'))
->contains(fn (string $pattern) => preg_match($pattern, $value));
}
}
4 changes: 2 additions & 2 deletions src/Recorders/Concerns/Sampling.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait Sampling
*/
protected function shouldSample(): bool
{
$rate = $this->config->get('pulse.recorders.'.static::class.'.sample_rate');
$rate = $this->config->get('pulse.recorders.'.self::class.'.sample_rate');

return Lottery::odds($rate)->choose();
}
Expand All @@ -21,7 +21,7 @@ protected function shouldSample(): bool
*/
protected function shouldSampleDeterministically(string $seed): bool
{
$rate = $this->config->get('pulse.recorders.'.static::class.'.sample_rate');
$rate = $this->config->get('pulse.recorders.'.self::class.'.sample_rate');

$value = hexdec(md5($seed)) / pow(16, 32); // Scale to 0-1

Expand Down
6 changes: 3 additions & 3 deletions src/Recorders/Jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function record(JobReleasedAfterException|JobFailed|JobProcessed|JobProce
'date' => $now->toDateTimeString(),
'released_at' => $now->toDateTimeString(),
'duration' => $duration = $this->lastJobStartedProcessingAt->diffInMilliseconds($now), // @phpstan-ignore method.nonObject
'slow' => $duration >= $this->config->get('pulse.recorders.'.static::class.'.threshold'),
'slow' => $duration >= $this->config->get('pulse.recorders.'.self::class.'.threshold'),
],
),
new Entry($this->table, [
Expand All @@ -143,7 +143,7 @@ public function record(JobReleasedAfterException|JobFailed|JobProcessed|JobProce
'date' => $now->toDateTimeString(),
'processed_at' => $now->toDateTimeString(),
'duration' => $duration = $this->lastJobStartedProcessingAt->diffInMilliseconds($now), // @phpstan-ignore method.nonObject
'slow' => $duration >= $this->config->get('pulse.recorders.'.static::class.'.threshold'),
'slow' => $duration >= $this->config->get('pulse.recorders.'.self::class.'.threshold'),
],
), fn () => $this->lastJobStartedProcessingAt = null);
}
Expand All @@ -156,7 +156,7 @@ public function record(JobReleasedAfterException|JobFailed|JobProcessed|JobProce
'date' => $now->toDateTimeString(),
'failed_at' => $now->toDateTimeString(),
'duration' => $duration = $this->lastJobStartedProcessingAt->diffInMilliseconds($now), // @phpstan-ignore method.nonObject
'slow' => $duration >= $this->config->get('pulse.recorders.'.static::class.'.threshold'),
'slow' => $duration >= $this->config->get('pulse.recorders.'.self::class.'.threshold'),
],
), fn () => $this->lastJobStartedProcessingAt = null);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Recorders/OutgoingRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function record(RequestInterface $request, CarbonImmutable $startedAt): ?
'date' => $startedAt->toDateTimeString(),
'duration' => $duration = $startedAt->diffInMilliseconds($endedAt),
'user_id' => $this->pulse->authenticatedUserIdResolver(),
'slow' => $duration >= $this->config->get('pulse.recorders.'.static::class.'.threshold'),
'slow' => $duration >= $this->config->get('pulse.recorders.'.self::class.'.threshold'),
]);
}

Expand All @@ -79,7 +79,7 @@ protected function normalizeUri(RequestInterface $request): Closure
$uri = $request->getUri();

return function () use ($method, $uri) {
foreach ($this->config->get('pulse.recorders.'.static::class.'.groups') as $pattern => $replacement) {
foreach ($this->config->get('pulse.recorders.'.self::class.'.groups') as $pattern => $replacement) {
$normalized = preg_replace($pattern, $replacement, $uri, count: $count);

if ($count > 0 && $normalized !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function record(Carbon $startedAt, Request $request, Response $response):
'route' => $request->method().' '.$path.($via ? " ($via)" : ''),
'duration' => $duration = $startedAt->diffInMilliseconds(),
'user_id' => $this->pulse->authenticatedUserIdResolver(),
'slow' => $duration >= $this->config->get('pulse.recorders.'.static::class.'.threshold'),
'slow' => $duration >= $this->config->get('pulse.recorders.'.self::class.'.threshold'),
]);
}
}
2 changes: 1 addition & 1 deletion src/Recorders/SlowQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function record(QueryExecuted $event): ?Entry
{
$now = new CarbonImmutable();

if ($event->time < $this->config->get('pulse.recorders.'.static::class.'.threshold')) {
if ($event->time < $this->config->get('pulse.recorders.'.self::class.'.threshold')) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Recorders/SystemStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function record(Beat $event): ?Entry

return new Entry($this->table, [
'date' => $event->time->toDateTimeString(),
'server' => $this->config->get('pulse.recorders.'.static::class.'.server_name'),
'server' => $this->config->get('pulse.recorders.'.self::class.'.server_name'),
...match (PHP_OS_FAMILY) {
'Darwin' => [
'cpu_percent' => (int) `top -l 1 | grep -E "^CPU" | tail -1 | awk '{ print $3 + $5 }'`,
Expand All @@ -58,7 +58,7 @@ public function record(Beat $event): ?Entry
],
default => throw new RuntimeException('The pulse:check command does not currently support '.PHP_OS_FAMILY),
},
'storage' => collect($this->config->get('pulse.recorders.'.static::class.'.directories')) // @phpstan-ignore argument.templateType, argument.templateType
'storage' => collect($this->config->get('pulse.recorders.'.self::class.'.directories')) // @phpstan-ignore argument.templateType, argument.templateType
->map(fn (string $directory) => [
'directory' => $directory,
'total' => $total = intval(round(disk_total_space($directory) / 1024 / 1024)), // MB
Expand Down

0 comments on commit ab91bfa

Please sign in to comment.