diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php
index 1364a8637..6e2150f47 100644
--- a/app/Providers/AuthServiceProvider.php
+++ b/app/Providers/AuthServiceProvider.php
@@ -13,6 +13,7 @@
use App\Policies\UserPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Notifications\DatabaseNotification as Notification;
+use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
@@ -26,5 +27,8 @@ class AuthServiceProvider extends ServiceProvider
public function boot(): void
{
+ Gate::define('viewPulse', function (User $user) {
+ return $user->isAdmin();
+ });
}
}
diff --git a/composer.json b/composer.json
index 5c3f6e8d1..61a54db46 100644
--- a/composer.json
+++ b/composer.json
@@ -19,6 +19,7 @@
"laravel-notification-channels/twitter": "^8.1.1",
"laravel/framework": "^10.0",
"laravel/horizon": "^5.12",
+ "laravel/pulse": "^1.0@beta",
"laravel/sanctum": "^3.2",
"laravel/socialite": "^5.6",
"laravel/tinker": "^2.8",
@@ -98,6 +99,6 @@
"php-http/discovery": true
}
},
- "minimum-stability": "stable",
+ "minimum-stability": "beta",
"prefer-stable": true
}
diff --git a/composer.lock b/composer.lock
index c2e38d727..9ff2f9986 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "6a4cfee2c0ac01718453cc3227df33e2",
+ "content-hash": "aa8aa5fdbefcb23df8f63f901b603642",
"packages": [
{
"name": "abraham/twitteroauth",
@@ -1528,6 +1528,58 @@
],
"time": "2024-02-05T11:56:58+00:00"
},
+ {
+ "name": "doctrine/sql-formatter",
+ "version": "1.1.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/doctrine/sql-formatter.git",
+ "reference": "25a06c7bf4c6b8218f47928654252863ffc890a5"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/doctrine/sql-formatter/zipball/25a06c7bf4c6b8218f47928654252863ffc890a5",
+ "reference": "25a06c7bf4c6b8218f47928654252863ffc890a5",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.1 || ^8.0"
+ },
+ "require-dev": {
+ "bamarni/composer-bin-plugin": "^1.4"
+ },
+ "bin": [
+ "bin/sql-formatter"
+ ],
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Doctrine\\SqlFormatter\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jeremy Dorn",
+ "email": "jeremy@jeremydorn.com",
+ "homepage": "https://jeremydorn.com/"
+ }
+ ],
+ "description": "a PHP SQL highlighting library",
+ "homepage": "https://github.com/doctrine/sql-formatter/",
+ "keywords": [
+ "highlight",
+ "sql"
+ ],
+ "support": {
+ "issues": "https://github.com/doctrine/sql-formatter/issues",
+ "source": "https://github.com/doctrine/sql-formatter/tree/1.1.3"
+ },
+ "time": "2022-05-23T21:33:49+00:00"
+ },
{
"name": "dragonmantank/cron-expression",
"version": "v3.3.3",
@@ -2992,6 +3044,92 @@
},
"time": "2024-04-30T12:46:16+00:00"
},
+ {
+ "name": "laravel/pulse",
+ "version": "v1.0.0-beta12",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/laravel/pulse.git",
+ "reference": "fa9aedb2de38360412b1f7843c33a8142ec9901c"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/laravel/pulse/zipball/fa9aedb2de38360412b1f7843c33a8142ec9901c",
+ "reference": "fa9aedb2de38360412b1f7843c33a8142ec9901c",
+ "shasum": ""
+ },
+ "require": {
+ "doctrine/sql-formatter": "^1.1",
+ "guzzlehttp/promises": "^1.0|^2.0",
+ "illuminate/auth": "^10.34|^11.0",
+ "illuminate/cache": "^10.34|^11.0",
+ "illuminate/config": "^10.34|^11.0",
+ "illuminate/console": "^10.34|^11.0",
+ "illuminate/contracts": "^10.34|^11.0",
+ "illuminate/database": "^10.34|^11.0",
+ "illuminate/events": "^10.34|^11.0",
+ "illuminate/http": "^10.34|^11.0",
+ "illuminate/queue": "^10.34|^11.0",
+ "illuminate/redis": "^10.34|^11.0",
+ "illuminate/routing": "^10.34|^11.0",
+ "illuminate/support": "^10.34|^11.0",
+ "illuminate/view": "^10.34|^11.0",
+ "livewire/livewire": "^3.2",
+ "nesbot/carbon": "^2.67|^3.0",
+ "php": "^8.1"
+ },
+ "conflict": {
+ "nunomaduro/collision": "<7.7.0"
+ },
+ "require-dev": {
+ "guzzlehttp/guzzle": "^7.7",
+ "mockery/mockery": "^1.0",
+ "orchestra/testbench": "^8.16|^9.0",
+ "pestphp/pest": "^2.0",
+ "pestphp/pest-plugin-laravel": "^2.2",
+ "phpstan/phpstan": "^1.11",
+ "predis/predis": "^1.0|^2.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.x-dev"
+ },
+ "laravel": {
+ "providers": [
+ "Laravel\\Pulse\\PulseServiceProvider"
+ ],
+ "aliases": {
+ "Pulse": "Laravel\\Pulse\\Facades\\Pulse"
+ }
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Laravel\\Pulse\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Taylor Otwell",
+ "email": "taylor@laravel.com"
+ }
+ ],
+ "description": "Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.",
+ "homepage": "https://github.com/laravel/pulse",
+ "keywords": [
+ "laravel"
+ ],
+ "support": {
+ "issues": "https://github.com/laravel/pulse/issues",
+ "source": "https://github.com/laravel/pulse"
+ },
+ "time": "2024-02-13T14:50:59+00:00"
+ },
{
"name": "laravel/sanctum",
"version": "v3.3.3",
@@ -12935,7 +13073,7 @@
}
],
"aliases": [],
- "minimum-stability": "stable",
+ "minimum-stability": "beta",
"stability-flags": [],
"prefer-stable": true,
"prefer-lowest": false,
diff --git a/config/database.php b/config/database.php
index 137ad18ce..35c0862c4 100644
--- a/config/database.php
+++ b/config/database.php
@@ -93,6 +93,25 @@
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
],
+ 'pulse' => [
+ 'driver' => 'mysql',
+ 'url' => env('PULSE_DATABASE_URL'),
+ 'host' => env('PULSE_DB_HOST', '127.0.0.1'),
+ 'port' => env('PULSE_DB_PORT', '3306'),
+ 'database' => env('PULSE_DB_DATABASE', 'pulse'),
+ 'username' => env('PULSE_DB_USERNAME', 'pulse'),
+ 'password' => env('PULSE_DB_PASSWORD', ''),
+ 'unix_socket' => env('PULSE_DB_SOCKET', ''),
+ 'charset' => 'utf8mb4',
+ 'collation' => 'utf8mb4_unicode_ci',
+ 'prefix' => '',
+ 'prefix_indexes' => true,
+ 'strict' => true,
+ 'engine' => null,
+ 'options' => extension_loaded('pdo_mysql') ? array_filter([
+ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
+ ]) : [],
+ ],
],
/*
diff --git a/config/pulse.php b/config/pulse.php
new file mode 100644
index 000000000..9defa3a92
--- /dev/null
+++ b/config/pulse.php
@@ -0,0 +1,232 @@
+ env('PULSE_DOMAIN'),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Pulse Path
+ |--------------------------------------------------------------------------
+ |
+ | This is the path which the Pulse dashboard will be accessible from. Feel
+ | free to change this path to anything you'd like. Note that this won't
+ | affect the path of the internal API that is never exposed to users.
+ |
+ */
+
+ 'path' => env('PULSE_PATH', 'pulse'),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Pulse Master Switch
+ |--------------------------------------------------------------------------
+ |
+ | This configuration option may be used to completely disable all Pulse
+ | data recorders regardless of their individual configurations. This
+ | provides a single option to quickly disable all Pulse recording.
+ |
+ */
+
+ 'enabled' => env('PULSE_ENABLED', true),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Pulse Storage Driver
+ |--------------------------------------------------------------------------
+ |
+ | This configuration option determines which storage driver will be used
+ | while storing entries from Pulse's recorders. In addition, you also
+ | may provide any options to configure the selected storage driver.
+ |
+ */
+
+ 'storage' => [
+ 'driver' => env('PULSE_STORAGE_DRIVER', 'database'),
+
+ 'database' => [
+ 'connection' => env('PULSE_DB_CONNECTION', 'pulse'),
+ 'chunk' => 1000,
+ ],
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Pulse Ingest Driver
+ |--------------------------------------------------------------------------
+ |
+ | This configuration options determines the ingest driver that will be used
+ | to capture entries from Pulse's recorders. Ingest drivers are great to
+ | free up your request workers quickly by offloading the data storage.
+ |
+ */
+
+ 'ingest' => [
+ 'driver' => env('PULSE_INGEST_DRIVER', 'storage'),
+
+ 'buffer' => env('PULSE_INGEST_BUFFER', 5_000),
+
+ 'trim' => [
+ 'lottery' => [1, 1_000],
+ 'keep' => '7 days',
+ ],
+
+ 'redis' => [
+ 'connection' => env('PULSE_REDIS_CONNECTION'),
+ 'chunk' => 1000,
+ ],
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Pulse Cache Driver
+ |--------------------------------------------------------------------------
+ |
+ | This configuration option determines the cache driver that will be used
+ | for various tasks, including caching dashboard results, establishing
+ | locks for events that should only occur on one server and signals.
+ |
+ */
+
+ 'cache' => env('PULSE_CACHE_DRIVER'),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Pulse Route Middleware
+ |--------------------------------------------------------------------------
+ |
+ | These middleware will be assigned to every Pulse route, giving you the
+ | chance to add your own middleware to this list or change any of the
+ | existing middleware. Of course, reasonable defaults are provided.
+ |
+ */
+
+ 'middleware' => [
+ 'web',
+ Authorize::class,
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Pulse Recorders
+ |--------------------------------------------------------------------------
+ |
+ | The following array lists the "recorders" that will be registered with
+ | Pulse, along with their configuration. Recorders gather application
+ | event data from requests and tasks to pass to your ingest driver.
+ |
+ */
+
+ 'recorders' => [
+ Recorders\CacheInteractions::class => [
+ 'enabled' => env('PULSE_CACHE_INTERACTIONS_ENABLED', true),
+ 'sample_rate' => env('PULSE_CACHE_INTERACTIONS_SAMPLE_RATE', 1),
+ 'ignore' => [
+ ...Pulse::defaultVendorCacheKeys(),
+ ],
+ 'groups' => [
+ '/^job-exceptions:.*/' => 'job-exceptions:*',
+ // '/:\d+/' => ':*',
+ ],
+ ],
+
+ Recorders\Exceptions::class => [
+ 'enabled' => env('PULSE_EXCEPTIONS_ENABLED', true),
+ 'sample_rate' => env('PULSE_EXCEPTIONS_SAMPLE_RATE', 1),
+ 'location' => env('PULSE_EXCEPTIONS_LOCATION', true),
+ 'ignore' => [
+ // '/^Package\\\\Exceptions\\\\/',
+ ],
+ ],
+
+ Recorders\Queues::class => [
+ 'enabled' => env('PULSE_QUEUES_ENABLED', true),
+ 'sample_rate' => env('PULSE_QUEUES_SAMPLE_RATE', 1),
+ 'ignore' => [
+ // '/^Package\\\\Jobs\\\\/',
+ ],
+ ],
+
+ Recorders\Servers::class => [
+ 'server_name' => env('PULSE_SERVER_NAME', gethostname()),
+ 'directories' => explode(':', env('PULSE_SERVER_DIRECTORIES', '/')),
+ ],
+
+ Recorders\SlowJobs::class => [
+ 'enabled' => env('PULSE_SLOW_JOBS_ENABLED', true),
+ 'sample_rate' => env('PULSE_SLOW_JOBS_SAMPLE_RATE', 1),
+ 'threshold' => env('PULSE_SLOW_JOBS_THRESHOLD', 1000),
+ 'ignore' => [
+ // '/^Package\\\\Jobs\\\\/',
+ ],
+ ],
+
+ Recorders\SlowOutgoingRequests::class => [
+ 'enabled' => env('PULSE_SLOW_OUTGOING_REQUESTS_ENABLED', true),
+ 'sample_rate' => env('PULSE_SLOW_OUTGOING_REQUESTS_SAMPLE_RATE', 1),
+ 'threshold' => env('PULSE_SLOW_OUTGOING_REQUESTS_THRESHOLD', 1000),
+ 'ignore' => [
+ // '#^http://127\.0\.0\.1:13714#', // Inertia SSR...
+ ],
+ 'groups' => [
+ // '#^https://api\.github\.com/repos/.*$#' => 'api.github.com/repos/*',
+ // '#^https?://([^/]*).*$#' => '\1',
+ // '#/\d+#' => '/*',
+ ],
+ ],
+
+ Recorders\SlowQueries::class => [
+ 'enabled' => env('PULSE_SLOW_QUERIES_ENABLED', true),
+ 'sample_rate' => env('PULSE_SLOW_QUERIES_SAMPLE_RATE', 1),
+ 'threshold' => env('PULSE_SLOW_QUERIES_THRESHOLD', 1000),
+ 'location' => env('PULSE_SLOW_QUERIES_LOCATION', true),
+ 'highlighting' => env('PULSE_SLOW_QUERIES_HIGHLIGHTING', true),
+ 'ignore' => [
+ '/(["`])pulse_[\w]+?\1/', // Pulse tables...
+ '/(["`])telescope_[\w]+?\1/', // Telescope tables...
+ ],
+ ],
+
+ Recorders\SlowRequests::class => [
+ 'enabled' => env('PULSE_SLOW_REQUESTS_ENABLED', true),
+ 'sample_rate' => env('PULSE_SLOW_REQUESTS_SAMPLE_RATE', 1),
+ 'threshold' => env('PULSE_SLOW_REQUESTS_THRESHOLD', 1000),
+ 'ignore' => [
+ '#^/pulse$#', // Pulse dashboard...
+ '#^/telescope#', // Telescope dashboard...
+ ],
+ ],
+
+ Recorders\UserJobs::class => [
+ 'enabled' => env('PULSE_USER_JOBS_ENABLED', true),
+ 'sample_rate' => env('PULSE_USER_JOBS_SAMPLE_RATE', 1),
+ 'ignore' => [
+ // '/^Package\\\\Jobs\\\\/',
+ ],
+ ],
+
+ Recorders\UserRequests::class => [
+ 'enabled' => env('PULSE_USER_REQUESTS_ENABLED', true),
+ 'sample_rate' => env('PULSE_USER_REQUESTS_SAMPLE_RATE', 1),
+ 'ignore' => [
+ '#^/pulse$#', // Pulse dashboard...
+ '#^/telescope#', // Telescope dashboard...
+ ],
+ ],
+ ],
+];
diff --git a/database/migrations/2023_06_07_000001_create_pulse_tables.php b/database/migrations/2023_06_07_000001_create_pulse_tables.php
new file mode 100644
index 000000000..2666a0f98
--- /dev/null
+++ b/database/migrations/2023_06_07_000001_create_pulse_tables.php
@@ -0,0 +1,89 @@
+shouldRun() || ! Config::get('pulse.enabled')) {
+ return;
+ }
+
+ Schema::create('pulse_values', function (Blueprint $table) {
+ $table->id();
+ $table->unsignedInteger('timestamp');
+ $table->string('type');
+ $table->mediumText('key');
+ match ($this->driver()) {
+ 'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
+ 'pgsql' => $table->uuid('key_hash')->storedAs('md5("key")::uuid'),
+ 'sqlite' => $table->string('key_hash'),
+ };
+ $table->mediumText('value');
+
+ $table->index('timestamp'); // For trimming...
+ $table->index('type'); // For fast lookups and purging...
+ $table->unique(['type', 'key_hash']); // For data integrity and upserts...
+ });
+
+ Schema::create('pulse_entries', function (Blueprint $table) {
+ $table->id();
+ $table->unsignedInteger('timestamp');
+ $table->string('type');
+ $table->mediumText('key');
+ match ($this->driver()) {
+ 'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
+ 'pgsql' => $table->uuid('key_hash')->storedAs('md5("key")::uuid'),
+ 'sqlite' => $table->string('key_hash'),
+ };
+ $table->bigInteger('value')->nullable();
+
+ $table->index('timestamp'); // For trimming...
+ $table->index('type'); // For purging...
+ $table->index('key_hash'); // For mapping...
+ $table->index(['timestamp', 'type', 'key_hash', 'value']); // For aggregate queries...
+ });
+
+ Schema::create('pulse_aggregates', function (Blueprint $table) {
+ $table->id();
+ $table->unsignedInteger('bucket');
+ $table->unsignedMediumInteger('period');
+ $table->string('type');
+ $table->mediumText('key');
+ match ($this->driver()) {
+ 'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
+ 'pgsql' => $table->uuid('key_hash')->storedAs('md5("key")::uuid'),
+ 'sqlite' => $table->string('key_hash'),
+ };
+ $table->string('aggregate');
+ $table->decimal('value', 20, 2);
+ $table->unsignedInteger('count')->nullable();
+
+ $table->unique(['bucket', 'period', 'type', 'aggregate', 'key_hash']); // Force "on duplicate update"...
+ $table->index(['period', 'bucket']); // For trimming...
+ $table->index('type'); // For purging...
+ $table->index(['period', 'type', 'aggregate', 'bucket']); // For aggregate queries...
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ if (! $this->shouldRun() || ! Config::get('pulse.enabled')) {
+ return;
+ }
+
+ Schema::dropIfExists('pulse_values');
+ Schema::dropIfExists('pulse_entries');
+ Schema::dropIfExists('pulse_aggregates');
+ }
+};
diff --git a/phpunit.xml b/phpunit.xml
index 66d1728d8..e353914af 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -30,5 +30,6 @@
+
diff --git a/resources/macros/blade.php b/resources/macros/blade.php
index 1d82d40ef..7a1c31617 100644
--- a/resources/macros/blade.php
+++ b/resources/macros/blade.php
@@ -3,6 +3,11 @@
use Illuminate\Support\Facades\Blade;
Blade::directive('md', function ($expression) {
+
+ if (empty($expression)) {
+ return "";
+ }
+
return "";
});