1
0
Fork 0
mirror of synced 2024-06-14 08:44:49 +12:00

Add health storage check

This commit is contained in:
Khushboo Verma 2024-02-15 11:57:24 +05:30
parent d4ad369a7e
commit 00db19257d
3 changed files with 56 additions and 0 deletions

View file

@ -702,6 +702,43 @@ App::get('/v1/health/storage/local')
$response->dynamic(new Document($output), Response::MODEL_HEALTH_STATUS);
});
App::get('/v1/health/storage')
->desc('Get storage')
->groups(['api', 'health'])
->label('scope', 'health.read')
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
->label('sdk.namespace', 'health')
->label('sdk.method', 'getStorage')
->label('sdk.description', '/docs/references/health/get-storage.md')
->label('sdk.response.code', Response::STATUS_CODE_OK)
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_HEALTH_STATUS)
->inject('response')
->inject('deviceFiles')
->action(function (Response $response, Device $deviceFiles) {
$checkStart = \microtime(true);
if (!$deviceFiles->write($deviceFiles->getPath('health.txt'), 'test', '')) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed writing test file');
}
if ($deviceFiles->read($deviceFiles->getPath('health.txt')) !== 'test') {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed reading test file');
}
if (!$deviceFiles->delete($deviceFiles->getPath('health.txt'))) {
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed deleting test file');
}
$output = [
'status' => 'pass',
'ping' => \round((\microtime(true) - $checkStart) / 1000)
];
$response->dynamic(new Document($output), Response::MODEL_HEALTH_STATUS);
});
App::get('/v1/health/anti-virus')
->desc('Get antivirus')
->groups(['api', 'health'])

View file

@ -0,0 +1 @@
Check the Appwrite storage device is up and connection is successful.

View file

@ -407,6 +407,24 @@ class HealthCustomServerTest extends Scope
return [];
}
public function testStorageSuccess(): array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/storage', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('pass', $response['body']['status']);
$this->assertIsInt($response['body']['ping']);
$this->assertLessThan(100, $response['body']['ping']);
return [];
}
public function testStorageAntiVirusSuccess(): array
{
/**