Skip to content

Commit

Permalink
Improve config for 3rd party cards
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed May 17, 2024
1 parent 9b40a63 commit 963945f
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/Recorders/CacheInteractions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Carbon\CarbonImmutable;
use Illuminate\Cache\Events\CacheHit;
use Illuminate\Cache\Events\CacheMissed;
use Illuminate\Config\Repository;
use Laravel\Pulse\Pulse;

/**
Expand All @@ -30,7 +29,6 @@ class CacheInteractions
*/
public function __construct(
protected Pulse $pulse,
protected Repository $config,
) {
//
}
Expand Down
4 changes: 3 additions & 1 deletion src/Recorders/Concerns/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

namespace Laravel\Pulse\Recorders\Concerns;

use Illuminate\Support\Facades\Config;

trait Groups
{
/**
* Group the value based on the configured grouping rules.
*/
protected function group(string $value): string
{
foreach ($this->config->get('pulse.recorders.'.static::class.'.groups', []) as $pattern => $replacement) {
foreach (Config::get('pulse.recorders.'.static::class.'.groups', []) as $pattern => $replacement) {
$group = preg_replace($pattern, $replacement, $value, count: $count);

if ($count > 0 && $group !== null) {
Expand Down
4 changes: 3 additions & 1 deletion src/Recorders/Concerns/Ignores.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Laravel\Pulse\Recorders\Concerns;

use Illuminate\Support\Facades\Config;

trait Ignores
{
/**
Expand All @@ -10,7 +12,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(Config::get('pulse.recorders.'.static::class.'.ignore', []))
->contains(fn (string $pattern) => preg_match($pattern, $value));
}
}
5 changes: 3 additions & 2 deletions src/Recorders/Concerns/Sampling.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Pulse\Recorders\Concerns;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Lottery;

trait Sampling
Expand All @@ -12,7 +13,7 @@ trait Sampling
protected function shouldSample(): bool
{
return Lottery::odds(
$this->config->get('pulse.recorders.'.static::class.'.sample_rate')
Config::get('pulse.recorders.'.static::class.'.sample_rate', 1)
)->choose();
}

Expand All @@ -23,6 +24,6 @@ protected function shouldSampleDeterministically(string $seed): bool
{
$value = hexdec(md5($seed)) / pow(16, 32); // Scale to 0-1

return $value <= $this->config->get('pulse.recorders.'.static::class.'.sample_rate');
return $value <= Config::get('pulse.recorders.'.static::class.'.sample_rate', 1);
}
}
2 changes: 1 addition & 1 deletion src/Recorders/Concerns/Thresholds.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function threshold(string $key, ?string $recorder = null): int
{
$recorder ??= static::class;

$config = Config::get("pulse.recorders.{$recorder}.threshold");
$config = Config::get("pulse.recorders.{$recorder}.threshold", 1_000);

if (! is_array($config)) {
return $config;
Expand Down
2 changes: 0 additions & 2 deletions src/Recorders/SlowJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Laravel\Pulse\Recorders;

use Carbon\CarbonImmutable;
use Illuminate\Config\Repository;
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
Expand Down Expand Up @@ -39,7 +38,6 @@ class SlowJobs
*/
public function __construct(
protected Pulse $pulse,
protected Repository $config,
) {
//
}
Expand Down
2 changes: 0 additions & 2 deletions src/Recorders/SlowOutgoingRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Carbon\CarbonImmutable;
use GuzzleHttp\Promise\RejectedPromise;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Client\Factory;
use Laravel\Pulse\Concerns\ConfiguresAfterResolving;
Expand All @@ -29,7 +28,6 @@ class SlowOutgoingRequests
*/
public function __construct(
protected Pulse $pulse,
protected Repository $config,
) {
//
}
Expand Down
2 changes: 0 additions & 2 deletions src/Recorders/SlowRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Pulse\Recorders;

use Illuminate\Config\Repository;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
Expand All @@ -28,7 +27,6 @@ class SlowRequests
*/
public function __construct(
protected Pulse $pulse,
protected Repository $config,
) {
//
}
Expand Down
2 changes: 0 additions & 2 deletions src/Recorders/UserJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Laravel\Pulse\Recorders;

use Carbon\CarbonImmutable;
use Illuminate\Config\Repository;
use Illuminate\Queue\Events\JobQueued;
use Laravel\Pulse\Pulse;

Expand All @@ -28,7 +27,6 @@ class UserJobs
*/
public function __construct(
protected Pulse $pulse,
protected Repository $config,
) {
//
}
Expand Down
2 changes: 0 additions & 2 deletions src/Recorders/UserRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Pulse\Recorders;

use Illuminate\Config\Repository;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
Expand All @@ -27,7 +26,6 @@ class UserRequests
*/
public function __construct(
protected Pulse $pulse,
protected Repository $config,
) {
//
}
Expand Down

0 comments on commit 963945f

Please sign in to comment.