Skip to content

Commit 37fcc8e

Browse files
authored
[1.x] Improve config for 3rd party cards (#372)
* Provide fallback when group config is missing * Improve config for 3rd party cards
1 parent b5271c7 commit 37fcc8e

File tree

10 files changed

+10
-17
lines changed

10 files changed

+10
-17
lines changed

src/Recorders/CacheInteractions.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Carbon\CarbonImmutable;
66
use Illuminate\Cache\Events\CacheHit;
77
use Illuminate\Cache\Events\CacheMissed;
8-
use Illuminate\Config\Repository;
98
use Laravel\Pulse\Pulse;
109

1110
/**
@@ -30,7 +29,6 @@ class CacheInteractions
3029
*/
3130
public function __construct(
3231
protected Pulse $pulse,
33-
protected Repository $config,
3432
) {
3533
//
3634
}

src/Recorders/Concerns/Groups.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
namespace Laravel\Pulse\Recorders\Concerns;
44

5+
use Illuminate\Support\Facades\Config;
6+
57
trait Groups
68
{
79
/**
810
* Group the value based on the configured grouping rules.
911
*/
1012
protected function group(string $value): string
1113
{
12-
foreach ($this->config->get('pulse.recorders.'.static::class.'.groups') as $pattern => $replacement) {
14+
foreach (Config::get('pulse.recorders.'.static::class.'.groups', []) as $pattern => $replacement) {
1315
$group = preg_replace($pattern, $replacement, $value, count: $count);
1416

1517
if ($count > 0 && $group !== null) {

src/Recorders/Concerns/Ignores.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Laravel\Pulse\Recorders\Concerns;
44

5+
use Illuminate\Support\Facades\Config;
6+
57
trait Ignores
68
{
79
/**
@@ -10,7 +12,7 @@ trait Ignores
1012
protected function shouldIgnore(string $value): bool
1113
{
1214
// @phpstan-ignore argument.templateType, argument.templateType
13-
return collect($this->config->get('pulse.recorders.'.static::class.'.ignore'))
15+
return collect(Config::get('pulse.recorders.'.static::class.'.ignore', []))
1416
->contains(fn (string $pattern) => preg_match($pattern, $value));
1517
}
1618
}

src/Recorders/Concerns/Sampling.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravel\Pulse\Recorders\Concerns;
44

5+
use Illuminate\Support\Facades\Config;
56
use Illuminate\Support\Lottery;
67

78
trait Sampling
@@ -12,7 +13,7 @@ trait Sampling
1213
protected function shouldSample(): bool
1314
{
1415
return Lottery::odds(
15-
$this->config->get('pulse.recorders.'.static::class.'.sample_rate')
16+
Config::get('pulse.recorders.'.static::class.'.sample_rate', 1)
1617
)->choose();
1718
}
1819

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

26-
return $value <= $this->config->get('pulse.recorders.'.static::class.'.sample_rate');
27+
return $value <= Config::get('pulse.recorders.'.static::class.'.sample_rate', 1);
2728
}
2829
}

src/Recorders/Concerns/Thresholds.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function threshold(string $key, ?string $recorder = null): int
2121
{
2222
$recorder ??= static::class;
2323

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

2626
if (! is_array($config)) {
2727
return $config;

src/Recorders/SlowJobs.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Laravel\Pulse\Recorders;
44

55
use Carbon\CarbonImmutable;
6-
use Illuminate\Config\Repository;
76
use Illuminate\Queue\Events\JobFailed;
87
use Illuminate\Queue\Events\JobProcessed;
98
use Illuminate\Queue\Events\JobProcessing;
@@ -39,7 +38,6 @@ class SlowJobs
3938
*/
4039
public function __construct(
4140
protected Pulse $pulse,
42-
protected Repository $config,
4341
) {
4442
//
4543
}

src/Recorders/SlowOutgoingRequests.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Carbon\CarbonImmutable;
66
use GuzzleHttp\Promise\RejectedPromise;
7-
use Illuminate\Config\Repository;
87
use Illuminate\Contracts\Foundation\Application;
98
use Illuminate\Http\Client\Factory;
109
use Laravel\Pulse\Concerns\ConfiguresAfterResolving;
@@ -29,7 +28,6 @@ class SlowOutgoingRequests
2928
*/
3029
public function __construct(
3130
protected Pulse $pulse,
32-
protected Repository $config,
3331
) {
3432
//
3533
}

src/Recorders/SlowRequests.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Laravel\Pulse\Recorders;
44

5-
use Illuminate\Config\Repository;
65
use Illuminate\Contracts\Foundation\Application;
76
use Illuminate\Contracts\Http\Kernel;
87
use Illuminate\Http\Request;
@@ -28,7 +27,6 @@ class SlowRequests
2827
*/
2928
public function __construct(
3029
protected Pulse $pulse,
31-
protected Repository $config,
3230
) {
3331
//
3432
}

src/Recorders/UserJobs.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Laravel\Pulse\Recorders;
44

55
use Carbon\CarbonImmutable;
6-
use Illuminate\Config\Repository;
76
use Illuminate\Queue\Events\JobQueued;
87
use Laravel\Pulse\Pulse;
98

@@ -28,7 +27,6 @@ class UserJobs
2827
*/
2928
public function __construct(
3029
protected Pulse $pulse,
31-
protected Repository $config,
3230
) {
3331
//
3432
}

src/Recorders/UserRequests.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Laravel\Pulse\Recorders;
44

5-
use Illuminate\Config\Repository;
65
use Illuminate\Contracts\Foundation\Application;
76
use Illuminate\Contracts\Http\Kernel;
87
use Illuminate\Http\Request;
@@ -27,7 +26,6 @@ class UserRequests
2726
*/
2827
public function __construct(
2928
protected Pulse $pulse,
30-
protected Repository $config,
3129
) {
3230
//
3331
}

0 commit comments

Comments
 (0)