From bf2b3b68e3666014f478e5b3b151bb936bd25651 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Tue, 25 Mar 2025 19:14:14 +0530 Subject: [PATCH] Add logging param to sites --- app/config/collections/projects.php | 20 ++++---- .../Modules/Sites/Http/Sites/Create.php | 5 +- .../Modules/Sites/Http/Sites/Update.php | 5 +- src/Appwrite/Utopia/Response/Model/Site.php | 6 +++ .../Services/Sites/SitesCustomServerTest.php | 51 +++++++++++++++++++ 5 files changed, 75 insertions(+), 12 deletions(-) diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index b209a7ec32..5c5f02daee 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -971,16 +971,16 @@ return [ 'default' => false, 'array' => false, ], - // [ - // '$id' => ID::custom('logging'), - // 'type' => Database::VAR_BOOLEAN, - // 'signed' => true, - // 'size' => 0, - // 'format' => '', - // 'filters' => [], - // 'required' => true, - // 'array' => false, - // ], + [ + '$id' => ID::custom('logging'), + 'type' => Database::VAR_BOOLEAN, + 'signed' => true, + 'size' => 0, + 'format' => '', + 'filters' => [], + 'required' => true, + 'array' => false, + ], [ '$id' => ID::custom('framework'), 'type' => Database::VAR_STRING, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php index ada665267a..bd76e19e3f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php @@ -64,7 +64,8 @@ class Create extends Base ->param('siteId', '', new CustomId(), 'Site ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Site name. Max length: 128 chars.') ->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.') - ->param('enabled', true, new Boolean(), 'Is site enabled? When set to \'disabled\', users cannot access the site but Server SDKs with and API key can still access the site. No data is lost when this is toggled.', true) // TODO: Add logging param later + ->param('enabled', true, new Boolean(), 'Is site enabled? When set to \'disabled\', users cannot access the site but Server SDKs with and API key can still access the site. No data is lost when this is toggled.', true) + ->param('logging', true, new Boolean(), 'Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project.', true) ->param('timeout', 15, new Range(1, (int) System::getEnv('_APP_COMPUTE_TIMEOUT', 900)), 'Maximum request time in seconds.', true) ->param('installCommand', '', new Text(8192, 0), 'Install Command.', true) ->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true) @@ -96,6 +97,7 @@ class Create extends Base string $name, string $framework, bool $enabled, + bool $logging, int $timeout, string $installCommand, string $buildCommand, @@ -140,6 +142,7 @@ class Create extends Base '$id' => $siteId, 'enabled' => $enabled, 'live' => true, + 'logging' => $logging, 'name' => $name, 'framework' => $framework, 'deploymentInternalId' => '', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index b971c4c4f3..1e82e83881 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -68,7 +68,8 @@ class Update extends Base ->param('siteId', '', new UID(), 'Site ID.') ->param('name', '', new Text(128), 'Site name. Max length: 128 chars.') ->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.') - ->param('enabled', true, new Boolean(), 'Is site enabled? When set to \'disabled\', users cannot access the site but Server SDKs with and API key can still access the site. No data is lost when this is toggled.', true) // TODO: Add logging param later + ->param('enabled', true, new Boolean(), 'Is site enabled? When set to \'disabled\', users cannot access the site but Server SDKs with and API key can still access the site. No data is lost when this is toggled.', true) + ->param('logging', true, new Boolean(), 'Whether logs and errors will be logged. When set to false, logs and errors will not be logged, but will reduce resource used by your Appwrite project.', true) ->param('timeout', 15, new Range(1, (int) System::getEnv('_APP_COMPUTE_TIMEOUT', 900)), 'Maximum request time in seconds.', true) ->param('installCommand', '', new Text(8192, 0), 'Install Command.', true) ->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true) @@ -103,6 +104,7 @@ class Update extends Base string $name, string $framework, bool $enabled, + bool $logging, int $timeout, string $installCommand, string $buildCommand, @@ -246,6 +248,7 @@ class Update extends Base 'name' => $name, 'framework' => $framework, 'enabled' => $enabled, + 'logging' => $logging, 'live' => $live, 'timeout' => $timeout, 'installCommand' => $installCommand, diff --git a/src/Appwrite/Utopia/Response/Model/Site.php b/src/Appwrite/Utopia/Response/Model/Site.php index 478b7881b3..8b28200de1 100644 --- a/src/Appwrite/Utopia/Response/Model/Site.php +++ b/src/Appwrite/Utopia/Response/Model/Site.php @@ -46,6 +46,12 @@ class Site extends Model 'default' => true, 'example' => false, ]) + ->addRule('logging', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether logs and errors will be logged. When set to false, logs and errors will not be logged, but will reduce resource used by your Appwrite project.', + 'default' => true, + 'example' => false, + ]) ->addRule('framework', [ 'type' => self::TYPE_STRING, 'description' => 'Site framework.', diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index a0880b0a4e..2cabaf88df 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1905,6 +1905,57 @@ class SitesCustomServerTest extends Scope $this->assertNotEquals($log1Id, $log2Id); + $site = $this->updateSite( + [ + '$id' => $siteId, + 'name' => 'SSR site', + 'framework' => 'astro', + 'adapter' => 'ssr', + 'buildRuntime' => 'node-22', + 'outputDirectory' => './dist', + 'buildCommand' => 'npm run build', + 'installCommand' => 'npm install', + 'fallbackFile' => '', + 'logging' => false // set logging to false + ] + ); + $this->assertEquals(200, $site['headers']['status-code']); + $response = $proxyClient->call(Client::METHOD_GET, '/logs-inline'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Inline logs printed.", $response['body']); + + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); + $this->assertStringContainsString("/logs-inline", $logs['body']['executions'][0]['requestPath']); + $this->assertStringContainsString("", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("", $logs['body']['executions'][0]['errors']); + $this->assertStringContainsString("", $logs['body']['executions'][0]['errors']); + $log1Id = $logs['body']['executions'][0]['$id']; + $this->assertNotEmpty($log1Id); + + $response = $proxyClient->call(Client::METHOD_GET, '/logs-action'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Action logs printed.", $response['body']); + + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); + $this->assertStringContainsString("/logs-action", $logs['body']['executions'][0]['requestPath']); + $this->assertStringContainsString("", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("", $logs['body']['executions'][0]['errors']); + $this->assertStringContainsString("", $logs['body']['executions'][0]['errors']); + $log2Id = $logs['body']['executions'][0]['$id']; + $this->assertNotEmpty($log2Id); + $this->cleanupSite($siteId); }