From 90aa4e7e73edf51aafea7e10283437a6265a6c40 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Wed, 27 May 2026 16:55:03 +0200 Subject: [PATCH] chore(sentinel): remove stale resource exit check --- app/Actions/Server/ResourcesCheck.php | 97 --------------------------- config/constants.php | 4 -- tests/Feature/ResourcesCheckTest.php | 78 --------------------- 3 files changed, 179 deletions(-) delete mode 100644 app/Actions/Server/ResourcesCheck.php delete mode 100644 tests/Feature/ResourcesCheckTest.php diff --git a/app/Actions/Server/ResourcesCheck.php b/app/Actions/Server/ResourcesCheck.php deleted file mode 100644 index cc11a2e07..000000000 --- a/app/Actions/Server/ResourcesCheck.php +++ /dev/null @@ -1,97 +0,0 @@ -staleSentinelServerIds($seconds); - - if ($staleServerIds->isEmpty()) { - return; - } - - [$standaloneDockerIds, $swarmDockerIds] = $this->destinationIdsForServers($staleServerIds); - - try { - Application::where(fn ($query) => $this->scopeDestination($query, $standaloneDockerIds, $swarmDockerIds)) - ->where('status', 'not like', 'exited%') - ->update(['status' => 'exited']); - - ServiceApplication::whereHas('service', fn ($query) => $query->whereIn('server_id', $staleServerIds)) - ->where('status', 'not like', 'exited%') - ->update(['status' => 'exited']); - - ServiceDatabase::whereHas('service', fn ($query) => $query->whereIn('server_id', $staleServerIds)) - ->where('status', 'not like', 'exited%') - ->update(['status' => 'exited']); - - collect([ - StandalonePostgresql::class, - StandaloneRedis::class, - StandaloneMongodb::class, - StandaloneMysql::class, - StandaloneMariadb::class, - StandaloneKeydb::class, - StandaloneDragonfly::class, - StandaloneClickhouse::class, - ])->each(function (string $databaseClass) use ($standaloneDockerIds, $swarmDockerIds) { - $databaseClass::query() - ->where(fn ($query) => $this->scopeDestination($query, $standaloneDockerIds, $swarmDockerIds)) - ->where('status', 'not like', 'exited%') - ->update(['status' => 'exited']); - }); - } catch (\Throwable $e) { - return handleError($e); - } - } - - private function staleSentinelServerIds(int $seconds): Collection - { - return Server::query() - ->whereNotNull('sentinel_updated_at') - ->where('sentinel_updated_at', '<', now()->subSeconds($seconds)) - ->whereHas('settings', fn ($query) => $query->where('is_sentinel_enabled', true)) - ->pluck('id'); - } - - private function destinationIdsForServers(Collection $serverIds): array - { - return [ - StandaloneDocker::whereIn('server_id', $serverIds)->pluck('id'), - SwarmDocker::whereIn('server_id', $serverIds)->pluck('id'), - ]; - } - - private function scopeDestination($query, Collection $standaloneDockerIds, Collection $swarmDockerIds): void - { - $query->where(function ($query) use ($standaloneDockerIds) { - $query->where('destination_type', StandaloneDocker::class) - ->whereIn('destination_id', $standaloneDockerIds); - })->orWhere(function ($query) use ($swarmDockerIds) { - $query->where('destination_type', SwarmDocker::class) - ->whereIn('destination_id', $swarmDockerIds); - }); - } -} diff --git a/config/constants.php b/config/constants.php index e967ca3bc..e5dcee3fe 100644 --- a/config/constants.php +++ b/config/constants.php @@ -98,10 +98,6 @@ return [ // every push. 'push_force_interval_seconds' => env('SENTINEL_PUSH_FORCE_INTERVAL_SECONDS', 300), - // How long a Sentinel-enabled server may go without a heartbeat before - // ResourcesCheck considers its resources stale. Per-resource - // last_online_at is only updated on real status changes, not every push. - 'resource_stale_seconds' => env('SENTINEL_RESOURCE_STALE_SECONDS', 300), ], 'proxy' => [ diff --git a/tests/Feature/ResourcesCheckTest.php b/tests/Feature/ResourcesCheckTest.php deleted file mode 100644 index 9fbf0ce2d..000000000 --- a/tests/Feature/ResourcesCheckTest.php +++ /dev/null @@ -1,78 +0,0 @@ - 300]); - - $application = resourcesCheckApplication([ - 'last_online_at' => now()->subHour(), - 'status' => 'running:healthy', - ], [ - 'sentinel_updated_at' => now()->subMinute(), - ]); - - ResourcesCheck::run(); - - $application->refresh(); - - expect($application->status)->toBe('running:healthy'); -}); - -it('marks resources exited when their sentinel server is stale', function () { - Carbon::setTestNow(Carbon::create(2026, 5, 27, 12, 0, 0, 'UTC')); - config(['constants.sentinel.resource_stale_seconds' => 300]); - - $application = resourcesCheckApplication([ - 'last_online_at' => now()->subHour(), - 'status' => 'running:healthy', - ], [ - 'sentinel_updated_at' => now()->subMinutes(10), - ]); - - ResourcesCheck::run(); - - $application->refresh(); - - expect($application->status)->toBe('exited:unhealthy'); -}); - -function resourcesCheckApplication(array $applicationAttributes = [], array $serverAttributes = []): Application -{ - $lastOnlineAt = $applicationAttributes['last_online_at'] ?? null; - unset($applicationAttributes['last_online_at']); - - $team = Team::factory()->create(); - $server = Server::factory()->create(array_merge([ - 'team_id' => $team->id, - ], $serverAttributes)); - $server->settings()->update(['is_sentinel_enabled' => true]); - - $destination = StandaloneDocker::where('server_id', $server->id)->first() - ?? StandaloneDocker::factory()->create(['server_id' => $server->id]); - $project = Project::factory()->create(['team_id' => $team->id]); - $environment = Environment::factory()->create(['project_id' => $project->id]); - - $application = Application::factory()->create(array_merge([ - 'environment_id' => $environment->id, - 'destination_id' => $destination->id, - 'destination_type' => $destination->getMorphClass(), - ], $applicationAttributes)); - - if ($lastOnlineAt !== null) { - $application->forceFill(['last_online_at' => $lastOnlineAt])->saveQuietly(); - } - - return $application; -}