Add logging param to sites

This commit is contained in:
Khushboo Verma
2025-03-25 19:14:14 +05:30
parent 871e4b70f7
commit bf2b3b68e3
5 changed files with 75 additions and 12 deletions
+10 -10
View File
@@ -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,
@@ -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' => '',
@@ -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,
@@ -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.',
@@ -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);
}