From 453ce03881758498da9125829f8505f92a2fcdf7 Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 23 Oct 2023 00:47:48 +0300 Subject: [PATCH 1/2] fix mod condition --- app/controllers/api/projects.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 6f2f4f40e3..d8d9f64681 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -124,7 +124,7 @@ App::post('/v1/projects') $databaseOverride = App::getEnv('_APP_DATABASE_OVERRIDE', null); $index = array_search($databaseOverride, $databases); - if ($index) { + if ($index !== false) { $database = $databases[$index]; } else { $database = $databases[array_rand($databases)]; @@ -177,7 +177,8 @@ App::post('/v1/projects') $mod = 20; $index = array_search('database_db_fra1_self_hosted_0_0', $databases); if ($index !== false && ($project->getInternalId() % $mod === 0)) { - $project->setAttribute('database', $databases[$index]); + $database = $databases[$index]; + $project->setAttribute('database', $database); $dbForConsole->updateDocument('projects', $project); } From dd9d8010c12e3dba256a4446cceff99c37f45a8c Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 8 Nov 2023 15:20:50 +0200 Subject: [PATCH 2/2] db health api throws an error when ping fails --- app/controllers/api/health.php | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 8ca1371488..9eb190310b 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -87,22 +87,18 @@ App::get('/v1/health/db') 'ping' => \round((\microtime(true) - $checkStart) / 1000) ]); } else { - $output[] = new Document([ - 'name' => $key . " ($database)", - 'status' => 'fail', - 'ping' => \round((\microtime(true) - $checkStart) / 1000) - ]); + $failure[] = $database; } } catch (\Throwable $th) { - $output[] = new Document([ - 'name' => $key . " ($database)", - 'status' => 'fail', - 'ping' => \round((\microtime(true) - $checkStart) / 1000) - ]); + $failure[] = $database; } } } + if (!empty($failure)) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, 'DB failure on: ' . implode(", ", $failure)); + } + $response->dynamic(new Document([ 'statuses' => $output, 'total' => count($output), @@ -536,10 +532,10 @@ App::get('/v1/health/storage/local') foreach ( [ - 'Uploads' => APP_STORAGE_UPLOADS, - 'Cache' => APP_STORAGE_CACHE, - 'Config' => APP_STORAGE_CONFIG, - 'Certs' => APP_STORAGE_CERTIFICATES + 'Uploads' => APP_STORAGE_UPLOADS, + 'Cache' => APP_STORAGE_CACHE, + 'Config' => APP_STORAGE_CONFIG, + 'Certs' => APP_STORAGE_CERTIFICATES ] as $key => $volume ) { $device = new Local($volume); @@ -601,7 +597,7 @@ App::get('/v1/health/anti-virus') }); App::get('/v1/health/stats') // Currently only used internally - ->desc('Get system stats') +->desc('Get system stats') ->groups(['api', 'health']) ->label('scope', 'root') // ->label('sdk.auth', [APP_AUTH_TYPE_KEY])