An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat(traffic): add traffic and GeoIP Sentinel config settings
Aditya Tripathi825a5206ad23
diff --git a/app/Actions/Server/StartSentinel.php b/app/Actions/Server/StartSentinel.phpindex 82f620ed34..04c980c80b 100644--- a/app/Actions/Server/StartSentinel.php+++ b/app/Actions/Server/StartSentinel.php@@ -17,13 +17,19 @@ class StartSentinel}$logPath = rtrim($server->proxyPath(), '/').'/access.log';+ $settings = $server->settings;$env = ['TRAFFIC_ENABLED' => 'true','TRAFFIC_PROXY_TYPE' => 'auto','TRAFFIC_ACCESS_LOG_PATH' => $logPath,- 'GEOIP_ENABLED' => 'true',+ 'TRAFFIC_TOPN' => (string) ($settings->traffic_topn ?: 50),+ 'TRAFFIC_SAMPLE_THRESHOLD' => (string) ($settings->traffic_sample_threshold ?? 0),+ 'TRAFFIC_RETENTION_1H_DAYS' => (string) ($settings->traffic_retention_1h_days ?: 30),+ 'TRAFFIC_RETENTION_1D_DAYS' => (string) ($settings->traffic_retention_1d_days ?: 395),+ 'GEOIP_ENABLED' => $settings->is_geoip_enabled ? 'true' : 'false',+ 'GEOIP_REFRESH_DAYS' => (string) ($settings->geoip_refresh_days ?: 30),];- $license = data_get($server, 'settings.geoip_maxmind_license_key');+ $license = data_get($settings, 'geoip_maxmind_license_key');if (filled($license)) {$env['GEOIP_MAXMIND_LICENSE_KEY'] = $license;}diff --git a/app/Http/Controllers/Api/ServerSentinelController.php b/app/Http/Controllers/Api/ServerSentinelController.phpindex f52bdb4c39..98b1b39e8c 100644--- a/app/Http/Controllers/Api/ServerSentinelController.php+++ b/app/Http/Controllers/Api/ServerSentinelController.php@@ -20,6 +20,13 @@ class ServerSentinelController extends Controller'sentinel_metrics_history_days','sentinel_push_interval_seconds','sentinel_custom_url',+ 'traffic_topn',+ 'traffic_sample_threshold',+ 'traffic_retention_1h_days',+ 'traffic_retention_1d_days',+ 'is_geoip_enabled',+ 'geoip_refresh_days',+ 'geoip_maxmind_license_key',];private function findServerForTeam(int $teamId, string $uuid): ?Server@@ -43,11 +50,18 @@ class ServerSentinelController extends Controller'sentinel_metrics_history_days' => (int) $settings->sentinel_metrics_history_days,'sentinel_push_interval_seconds' => (int) $settings->sentinel_push_interval_seconds,'sentinel_updated_at' => $server->sentinel_updated_at,+ 'traffic_topn' => (int) $settings->traffic_topn,+ 'traffic_sample_threshold' => (int) $settings->traffic_sample_threshold,+ 'traffic_retention_1h_days' => (int) $settings->traffic_retention_1h_days,+ 'traffic_retention_1d_days' => (int) $settings->traffic_retention_1d_days,+ 'is_geoip_enabled' => (bool) $settings->is_geoip_enabled,+ 'geoip_refresh_days' => (int) $settings->geoip_refresh_days,];if ($this->canReadSensitive()) {$payload['sentinel_token'] = $settings->sentinel_token;$payload['sentinel_custom_url'] = $settings->sentinel_custom_url;+ $payload['geoip_maxmind_license_key'] = $settings->geoip_maxmind_license_key;}return $payload;@@ -78,6 +92,13 @@ class ServerSentinelController extends Controllernew OA\Property(property: 'sentinel_push_interval_seconds', type: 'integer'),new OA\Property(property: 'sentinel_custom_url', type: 'string', description: 'Only present with read:sensitive.'),new OA\Property(property: 'sentinel_updated_at', type: 'string', nullable: true),+ new OA\Property(property: 'traffic_topn', type: 'integer'),+ new OA\Property(property: 'traffic_sample_threshold', type: 'integer'),+ new OA\Property(property: 'traffic_retention_1h_days', type: 'integer'),+ new OA\Property(property: 'traffic_retention_1d_days', type: 'integer'),+ new OA\Property(property: 'is_geoip_enabled', type: 'boolean'),+ new OA\Property(property: 'geoip_refresh_days', type: 'integer'),+ new OA\Property(property: 'geoip_maxmind_license_key', type: 'string', description: 'Only present with read:sensitive.'),],type: 'object',),@@ -126,6 +147,13 @@ class ServerSentinelController extends Controllernew OA\Property(property: 'sentinel_metrics_history_days', type: 'integer', minimum: 1),new OA\Property(property: 'sentinel_push_interval_seconds', type: 'integer', minimum: 10),new OA\Property(property: 'sentinel_custom_url', type: 'string', nullable: true),+ new OA\Property(property: 'traffic_topn', type: 'integer', minimum: 1),+ new OA\Property(property: 'traffic_sample_threshold', type: 'integer', minimum: 0),+ new OA\Property(property: 'traffic_retention_1h_days', type: 'integer', minimum: 1),+ new OA\Property(property: 'traffic_retention_1d_days', type: 'integer', minimum: 1),+ new OA\Property(property: 'is_geoip_enabled', type: 'boolean'),+ new OA\Property(property: 'geoip_refresh_days', type: 'integer', minimum: 1),+ new OA\Property(property: 'geoip_maxmind_license_key', type: 'string', nullable: true),],type: 'object',),@@ -166,6 +194,13 @@ class ServerSentinelController extends Controller'sentinel_metrics_history_days' => 'integer|min:1','sentinel_push_interval_seconds' => 'integer|min:10','sentinel_custom_url' => 'nullable|url',+ 'traffic_topn' => 'integer|min:1',+ 'traffic_sample_threshold' => 'integer|min:0',+ 'traffic_retention_1h_days' => 'integer|min:1',+ 'traffic_retention_1d_days' => 'integer|min:1',+ 'is_geoip_enabled' => 'boolean',+ 'geoip_refresh_days' => 'integer|min:1',+ 'geoip_maxmind_license_key' => 'nullable|string|max:255',]);$extraFields = array_diff(array_keys($request->all()), self::ALLOWED_FIELDS);diff --git a/app/Livewire/Server/Sentinel.php b/app/Livewire/Server/Sentinel.phpindex cc2828086f..2a8e987f33 100644--- a/app/Livewire/Server/Sentinel.php+++ b/app/Livewire/Server/Sentinel.php@@ -43,6 +43,23 @@ class Sentinel extends Componentpublic bool $isTrafficAnalyticsEnabled;+ #[Validate(['required', 'integer', 'min:1'])]+ public int|string $trafficTopn;++ #[Validate(['required', 'integer', 'min:0'])]+ public int|string $trafficSampleThreshold;++ #[Validate(['required', 'integer', 'min:1'])]+ public int|string $trafficRetention1hDays;++ #[Validate(['required', 'integer', 'min:1'])]+ public int|string $trafficRetention1dDays;++ public bool $isGeoipEnabled;++ #[Validate(['required', 'integer', 'min:1'])]+ public int|string $geoipRefreshDays;+#[Validate(['nullable', 'string', 'max:255'])]public ?string $geoipMaxmindLicenseKey = null;@@ -73,6 +90,12 @@ class Sentinel extends Component$this->server->settings->sentinel_custom_url = $this->sentinelCustomUrl;$this->server->settings->is_sentinel_enabled = $this->isSentinelEnabled;$this->server->settings->is_sentinel_debug_enabled = $this->isSentinelDebugEnabled;+ $this->server->settings->traffic_topn = $this->trafficTopn;+ $this->server->settings->traffic_sample_threshold = $this->trafficSampleThreshold;+ $this->server->settings->traffic_retention_1h_days = $this->trafficRetention1hDays;+ $this->server->settings->traffic_retention_1d_days = $this->trafficRetention1dDays;+ $this->server->settings->is_geoip_enabled = $this->isGeoipEnabled;+ $this->server->settings->geoip_refresh_days = $this->geoipRefreshDays;$this->server->settings->geoip_maxmind_license_key = $this->geoipMaxmindLicenseKey;$this->server->settings->save();} else {@@ -86,6 +109,12 @@ class Sentinel extends Component$this->isSentinelDebugEnabled = $this->server->settings->is_sentinel_debug_enabled;$this->sentinelUpdatedAt = $this->server->sentinel_updated_at;$this->isTrafficAnalyticsEnabled = $this->server->isTrafficAnalyticsEnabled();+ $this->trafficTopn = $this->server->settings->traffic_topn;+ $this->trafficSampleThreshold = $this->server->settings->traffic_sample_threshold;+ $this->trafficRetention1hDays = $this->server->settings->traffic_retention_1h_days;+ $this->trafficRetention1dDays = $this->server->settings->traffic_retention_1d_days;+ $this->isGeoipEnabled = (bool) $this->server->settings->is_geoip_enabled;+ $this->geoipRefreshDays = $this->server->settings->geoip_refresh_days;$this->geoipMaxmindLicenseKey = $this->server->settings->geoip_maxmind_license_key;}}diff --git a/app/Models/ServerSetting.php b/app/Models/ServerSetting.phpindex 89e2120432..c838f21757 100644--- a/app/Models/ServerSetting.php+++ b/app/Models/ServerSetting.php@@ -27,6 +27,12 @@ use OpenApi\Attributes as OA;'is_logdrain_newrelic_enabled' => ['type' => 'boolean'],'is_metrics_enabled' => ['type' => 'boolean'],'is_traffic_analytics_enabled' => ['type' => 'boolean'],+ 'traffic_topn' => ['type' => 'integer'],+ 'traffic_sample_threshold' => ['type' => 'integer'],+ 'traffic_retention_1h_days' => ['type' => 'integer'],+ 'traffic_retention_1d_days' => ['type' => 'integer'],+ 'is_geoip_enabled' => ['type' => 'boolean'],+ 'geoip_refresh_days' => ['type' => 'integer'],'is_reachable' => ['type' => 'boolean'],'is_sentinel_enabled' => ['type' => 'boolean'],'is_swarm_manager' => ['type' => 'boolean'],@@ -102,6 +108,12 @@ class ServerSetting extends Model'disable_application_image_retention','connection_timeout','is_traffic_analytics_enabled',+ 'traffic_topn',+ 'traffic_sample_threshold',+ 'traffic_retention_1h_days',+ 'traffic_retention_1d_days',+ 'is_geoip_enabled',+ 'geoip_refresh_days','geoip_maxmind_license_key',];@@ -117,6 +129,12 @@ class ServerSetting extends Model'disable_application_image_retention' => 'boolean','connection_timeout' => 'integer','is_traffic_analytics_enabled' => 'boolean',+ 'traffic_topn' => 'integer',+ 'traffic_sample_threshold' => 'integer',+ 'traffic_retention_1h_days' => 'integer',+ 'traffic_retention_1d_days' => 'integer',+ 'is_geoip_enabled' => 'boolean',+ 'geoip_refresh_days' => 'integer','geoip_maxmind_license_key' => 'encrypted',];@@ -164,7 +182,14 @@ class ServerSetting extends Model$settings->wasChanged('sentinel_custom_url') ||$settings->wasChanged('sentinel_metrics_refresh_rate_seconds') ||$settings->wasChanged('sentinel_metrics_history_days') ||- $settings->wasChanged('sentinel_push_interval_seconds')+ $settings->wasChanged('sentinel_push_interval_seconds') ||+ $settings->wasChanged('traffic_topn') ||+ $settings->wasChanged('traffic_sample_threshold') ||+ $settings->wasChanged('traffic_retention_1h_days') ||+ $settings->wasChanged('traffic_retention_1d_days') ||+ $settings->wasChanged('is_geoip_enabled') ||+ $settings->wasChanged('geoip_refresh_days') ||+ $settings->wasChanged('geoip_maxmind_license_key')) {$settings->server->restartSentinel();}diff --git a/database/migrations/2026_08_10_191228_add_traffic_analytics_to_server_settings.php b/database/migrations/2026_08_10_191228_add_traffic_analytics_to_server_settings.phpindex 6fdd2a213c..535469ab8b 100644--- a/database/migrations/2026_08_10_191228_add_traffic_analytics_to_server_settings.php+++ b/database/migrations/2026_08_10_191228_add_traffic_analytics_to_server_settings.php@@ -14,6 +14,12 @@ return new class extends MigrationSchema::table('server_settings', function (Blueprint $table) {$table->boolean('is_traffic_analytics_enabled')->default(false);$table->text('geoip_maxmind_license_key')->nullable();+ $table->integer('traffic_topn')->default(50);+ $table->integer('traffic_sample_threshold')->default(0);+ $table->integer('traffic_retention_1h_days')->default(30);+ $table->integer('traffic_retention_1d_days')->default(395);+ $table->boolean('is_geoip_enabled')->default(true);+ $table->integer('geoip_refresh_days')->default(30);});}@@ -23,7 +29,16 @@ return new class extends Migrationpublic function down(): void{Schema::table('server_settings', function (Blueprint $table) {- $table->dropColumn(['is_traffic_analytics_enabled', 'geoip_maxmind_license_key']);+ $table->dropColumn([+ 'is_traffic_analytics_enabled',+ 'geoip_maxmind_license_key',+ 'traffic_topn',+ 'traffic_sample_threshold',+ 'traffic_retention_1h_days',+ 'traffic_retention_1d_days',+ 'is_geoip_enabled',+ 'geoip_refresh_days',+ ]);});}};diff --git a/resources/views/livewire/server/sentinel.blade.php b/resources/views/livewire/server/sentinel.blade.phpindex 67a47489f6..6ed58377f6 100644--- a/resources/views/livewire/server/sentinel.blade.php+++ b/resources/views/livewire/server/sentinel.blade.php@@ -6,7 +6,7 @@`$wire.set('sentinelCustomDockerImage', …)` (and similar) brieflyflashes this bar on every page open. --}}<x-unsaved-bar action="submit"- targets="sentinelCustomUrl,sentinelToken,sentinelMetricsRefreshRateSeconds,sentinelMetricsHistoryDays,sentinelPushIntervalSeconds,geoipMaxmindLicenseKey" />+ targets="sentinelCustomUrl,sentinelToken,sentinelMetricsRefreshRateSeconds,sentinelMetricsHistoryDays,sentinelPushIntervalSeconds,trafficTopn,trafficSampleThreshold,trafficRetention1hDays,trafficRetention1dDays,isGeoipEnabled,geoipRefreshDays,geoipMaxmindLicenseKey" />@endif<x-application.settings-section id="server-sentinel-overview-section" title="Sentinel"@@ -103,9 +103,30 @@@if ($isTrafficAnalyticsEnabled)<div class="grid gap-4 lg:grid-cols-2">+ <x-forms.input canGate="update" :canResource="$server" type="number" min="1"+ id="trafficTopn" label="Top-N cap" required+ helper="Maximum distinct values kept per dimension (paths, countries, browsers). Overflow folds into Other." />+ <x-forms.input canGate="update" :canResource="$server" type="number" min="0"+ id="trafficSampleThreshold" label="Sample threshold" required+ helper="Events per second above which Sentinel starts sampling. 0 disables sampling." />+ <x-forms.input canGate="update" :canResource="$server" type="number" min="1"+ id="trafficRetention1hDays" label="Hourly retention" required+ helper="Days of hourly rollups to keep. This is the fine-grained history window." />+ <x-forms.input canGate="update" :canResource="$server" type="number" min="1"+ id="trafficRetention1dDays" label="Daily retention" required+ helper="Days of daily rollups to keep before deletion." />+ <x-forms.listbox id="isGeoipEnabled" label="Geolocation"+ :options="[+ ['value' => true, 'label' => 'Enabled'],+ ['value' => false, 'label' => 'Disabled'],+ ]"+ helper="Country enrichment from visitor IPs. Disable to skip GeoIP lookups." />+ <x-forms.input canGate="update" :canResource="$server" type="number" min="1"+ id="geoipRefreshDays" label="GeoIP refresh interval" required+ helper="Days between GeoIP database update checks." /><x-forms.input canGate="update" :canResource="$server" type="password"id="geoipMaxmindLicenseKey" label="MaxMind GeoIP license key" placeholder="Optional"- helper="Used to download the GeoLite2 database for visitor geolocation. Leave empty to disable geolocation." />+ helper="Used to download the GeoLite2 database for visitor geolocation. Leave empty to use the default database source." /></div>@else<x-empty size="sm" title="Traffic analytics is disabled"diff --git a/tests/Feature/Api/ServerSubsystemsApiTest.php b/tests/Feature/Api/ServerSubsystemsApiTest.phpindex e31c8a051b..a4edeb0ddf 100644--- a/tests/Feature/Api/ServerSubsystemsApiTest.php+++ b/tests/Feature/Api/ServerSubsystemsApiTest.php@@ -212,7 +212,9 @@ describe('Sentinel API', function () {->getJson("/api/v1/servers/{$this->server->uuid}/sentinel")->assertOk()->assertJsonPath('is_sentinel_enabled', true)- ->assertJsonPath('is_metrics_enabled', true);+ ->assertJsonPath('is_metrics_enabled', true)+ ->assertJsonPath('traffic_topn', 50)+ ->assertJsonPath('is_geoip_enabled', true);expect($response->json())->not->toHaveKey('sentinel_token')->and($response->json())->not->toHaveKey('sentinel_custom_url');diff --git a/tests/Feature/Server/ServerSettingSentinelRestartTest.php b/tests/Feature/Server/ServerSettingSentinelRestartTest.phpindex 7a1c333ca7..57c256110d 100644--- a/tests/Feature/Server/ServerSettingSentinelRestartTest.php+++ b/tests/Feature/Server/ServerSettingSentinelRestartTest.php@@ -4,10 +4,13 @@ use App\Models\Server;use App\Models\ServerSetting;use App\Models\User;use Illuminate\Foundation\Testing\RefreshDatabase;+use Illuminate\Support\Facades\Queue;uses(RefreshDatabase::class);beforeEach(function () {+ Queue::fake();+// Create user (which automatically creates a team)$user = User::factory()->create();$this->team = $user->teams()->first();@@ -108,7 +111,14 @@ it('does not detect changes when unrelated field is changed', function () {$settings->wasChanged('sentinel_custom_url') ||$settings->wasChanged('sentinel_metrics_refresh_rate_seconds') ||$settings->wasChanged('sentinel_metrics_history_days') ||- $settings->wasChanged('sentinel_push_interval_seconds')+ $settings->wasChanged('sentinel_push_interval_seconds') ||+ $settings->wasChanged('traffic_topn') ||+ $settings->wasChanged('traffic_sample_threshold') ||+ $settings->wasChanged('traffic_retention_1h_days') ||+ $settings->wasChanged('traffic_retention_1d_days') ||+ $settings->wasChanged('is_geoip_enabled') ||+ $settings->wasChanged('geoip_refresh_days') ||+ $settings->wasChanged('geoip_maxmind_license_key')) {$changeDetected = true;}@@ -121,6 +131,22 @@ it('does not detect changes when unrelated field is changed', function () {expect($changeDetected)->toBeFalse();});+it('detects traffic analytics setting changes with wasChanged', function () {+ $changeDetected = false;++ ServerSetting::updated(function ($settings) use (&$changeDetected) {+ if ($settings->wasChanged('traffic_topn')) {+ $changeDetected = true;+ }+ });++ $settings = $this->server->settings;+ $settings->traffic_topn = 200;+ $settings->save();++ expect($changeDetected)->toBeTrue();+});+it('does not detect changes when sentinel field is set to same value', function () {$changeDetected = false;diff --git a/tests/Feature/TrafficAnalytics/ServerSettingTrafficTest.php b/tests/Feature/TrafficAnalytics/ServerSettingTrafficTest.phpindex 8196acf0a4..98710c688f 100644--- a/tests/Feature/TrafficAnalytics/ServerSettingTrafficTest.php+++ b/tests/Feature/TrafficAnalytics/ServerSettingTrafficTest.php@@ -4,10 +4,12 @@ use App\Models\Server;use App\Models\ServerSetting;use App\Models\User;use Illuminate\Foundation\Testing\RefreshDatabase;+use Illuminate\Support\Facades\Queue;uses(RefreshDatabase::class);beforeEach(function () {+ Queue::fake();$user = User::factory()->create();$this->team = $user->teams()->first();});@@ -52,6 +54,17 @@ it('respects an explicit traffic analytics value on creation', function () {expect($setting->is_traffic_analytics_enabled)->toBeFalse();});+it('defaults traffic collection and geoip settings to sentinel values', function () {+ $server = Server::factory()->create(['team_id' => $this->team->id]);++ expect($server->settings->traffic_topn)->toBe(50)+ ->and($server->settings->traffic_sample_threshold)->toBe(0)+ ->and($server->settings->traffic_retention_1h_days)->toBe(30)+ ->and($server->settings->traffic_retention_1d_days)->toBe(395)+ ->and($server->settings->is_geoip_enabled)->toBeTrue()+ ->and($server->settings->geoip_refresh_days)->toBe(30);+});+it('encrypts the maxmind license key and hides it from array output', function () {$server = Server::factory()->create(['team_id' => $this->team->id]);$server->settings->geoip_maxmind_license_key = 'secret-key';diff --git a/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php b/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.phpindex b48b0475f1..ac24331d52 100644--- a/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php+++ b/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php@@ -4,10 +4,12 @@ use App\Actions\Server\StartSentinel;use App\Models\Server;use App\Models\User;use Illuminate\Foundation\Testing\RefreshDatabase;+use Illuminate\Support\Facades\Queue;uses(RefreshDatabase::class);beforeEach(function () {+ Queue::fake();$user = User::factory()->create();$this->team = $user->teams()->first();});@@ -28,7 +30,33 @@ it('produces traffic + geoip env when enabled', function () {$env = StartSentinel::sentinelTrafficEnvironment($server->fresh());expect($env['TRAFFIC_ENABLED'])->toBe('true');expect($env['TRAFFIC_PROXY_TYPE'])->toBe('auto');+ expect($env['TRAFFIC_TOPN'])->toBe('50');+ expect($env['TRAFFIC_SAMPLE_THRESHOLD'])->toBe('0');+ expect($env['TRAFFIC_RETENTION_1H_DAYS'])->toBe('30');+ expect($env['TRAFFIC_RETENTION_1D_DAYS'])->toBe('395');expect($env['GEOIP_ENABLED'])->toBe('true');+ expect($env['GEOIP_REFRESH_DAYS'])->toBe('30');expect($env['GEOIP_MAXMIND_LICENSE_KEY'])->toBe('lic');expect($env)->toHaveKey('TRAFFIC_ACCESS_LOG_PATH');});++it('passes custom traffic settings as sentinel env', function () {+ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $server->settings->is_traffic_analytics_enabled = true;+ $server->settings->traffic_topn = 100;+ $server->settings->traffic_sample_threshold = 500;+ $server->settings->traffic_retention_1h_days = 14;+ $server->settings->traffic_retention_1d_days = 180;+ $server->settings->is_geoip_enabled = false;+ $server->settings->geoip_refresh_days = 7;+ $server->settings->save();++ $env = StartSentinel::sentinelTrafficEnvironment($server->fresh());+ expect($env['TRAFFIC_TOPN'])->toBe('100');+ expect($env['TRAFFIC_SAMPLE_THRESHOLD'])->toBe('500');+ expect($env['TRAFFIC_RETENTION_1H_DAYS'])->toBe('14');+ expect($env['TRAFFIC_RETENTION_1D_DAYS'])->toBe('180');+ expect($env['GEOIP_ENABLED'])->toBe('false');+ expect($env['GEOIP_REFRESH_DAYS'])->toBe('7');+ expect($env)->not->toHaveKey('GEOIP_MAXMIND_LICENSE_KEY');+});diff --git a/tests/Feature/TrafficAnalytics/ToggleTrafficAnalyticsTest.php b/tests/Feature/TrafficAnalytics/ToggleTrafficAnalyticsTest.phpindex 0ad50c9a5a..1ceb204fa4 100644--- a/tests/Feature/TrafficAnalytics/ToggleTrafficAnalyticsTest.php+++ b/tests/Feature/TrafficAnalytics/ToggleTrafficAnalyticsTest.php@@ -5,6 +5,7 @@ use App\Livewire\Server\Sentinel;use App\Models\Server;use App\Models\User;use Illuminate\Foundation\Testing\RefreshDatabase;+use Illuminate\Support\Facades\Queue;use Livewire\Livewire;uses(RefreshDatabase::class);@@ -53,6 +54,41 @@ it('does not enable traffic analytics on a swarm server', function () {expect($server->fresh()->isTrafficAnalyticsEnabled())->toBeFalse();});+it('saves traffic analytics settings from the sentinel form', function () {+ Queue::fake();++ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $server->settings->is_traffic_analytics_enabled = true;+ $server->settings->save();++ Livewire::test(Sentinel::class, ['server' => $server])+ ->set('trafficTopn', 100)+ ->set('trafficSampleThreshold', 500)+ ->set('trafficRetention1hDays', 14)+ ->set('trafficRetention1dDays', 180)+ ->set('isGeoipEnabled', false)+ ->set('geoipRefreshDays', 7)+ ->call('submit')+ ->assertHasNoErrors();++ $settings = $server->settings->fresh();+ expect($settings->traffic_topn)->toBe(100)+ ->and($settings->traffic_sample_threshold)->toBe(500)+ ->and($settings->traffic_retention_1h_days)->toBe(14)+ ->and($settings->traffic_retention_1d_days)->toBe(180)+ ->and($settings->is_geoip_enabled)->toBeFalse()+ ->and($settings->geoip_refresh_days)->toBe(7);+});++it('rejects a zero top-n cap', function () {+ $server = Server::factory()->create(['team_id' => $this->team->id]);++ Livewire::test(Sentinel::class, ['server' => $server])+ ->set('trafficTopn', 0)+ ->call('submit')+ ->assertHasErrors(['trafficTopn']);+});+it('does not enable traffic analytics on a build server', function () {ConfigureTrafficAnalytics::partialMock()->shouldReceive('handle')->never();