-
Notifications
You must be signed in to change notification settings - Fork 187
[1.x] Allow thresholds of slow queries, jobs and requests to be customised by regex pattern #340
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 21 commits
d48c680
4e0f14c
09ed4fb
5584105
15a74bc
4c84b91
f590eb8
e4c6609
3a69b6e
b85cceb
01c1f92
eeb2dbf
22870a3
c49ceba
85071b4
42971b9
225ba26
ddc97ad
017c4f6
67e4f08
90ae7b9
5625346
9dcf182
71e1590
f0c6d69
e6b9794
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 |
---|---|---|
|
@@ -2,13 +2,36 @@ | |
|
||
namespace Laravel\Pulse\Recorders\Concerns; | ||
|
||
use Illuminate\Support\Facades\Config; | ||
|
||
trait Thresholds | ||
{ | ||
/** | ||
* Determine if the duration is under the configured threshold. | ||
*/ | ||
protected function underThreshold(int|float $duration): bool | ||
protected function underThreshold(int|float $duration, string $value): bool | ||
{ | ||
return $duration < $this->threshold($value); | ||
} | ||
|
||
/** | ||
* Get the threshold for the given value. | ||
*/ | ||
protected function threshold(string $value, ?string $recorder = null): int | ||
{ | ||
return $duration < $this->config->get('pulse.recorders.'.static::class.'.threshold'); | ||
$recorder ??= static::class; | ||
|
||
$config = Config::get("pulse.recorders.{$recorder}.threshold"); | ||
|
||
if (! is_array($config)) { | ||
return $config; | ||
} | ||
|
||
// @phpstan-ignore argument.templateType, argument.templateType | ||
$custom = collect($config) | ||
->except(['default']) | ||
->first(fn ($threshold, $pattern) => preg_match($pattern, $value)); | ||
|
||
return $custom ?? $config['default'] ?? 1_000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice that we have a hard-coded When a user changes from a single threshold to an array, if they forget the Not sure if we wanna keep this or just document that they need to have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if you want my opinion about this, but don't breaking the app even without a |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standardising use of the
@js
directive, which I've used in some of the changes in this PR.