Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Audit/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,13 @@ abstract public function find(array $queries = []): array;
* @throws \Exception
*/
abstract public function count(array $queries = [], ?int $max = null): int;

/**
* Ping the adapter to check connectivity.
*
* Returns false on any connectivity failure rather than throwing.
*
* @return bool True when the backing store is reachable, false otherwise.
*/
abstract public function ping(): bool;
}
23 changes: 23 additions & 0 deletions src/Audit/Adapter/ClickHouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ public function getName(): string
return 'ClickHouse';
}

/**
* Ping ClickHouse to check connectivity.
*
* Uses ClickHouse's dedicated /ping endpoint, which bypasses the query
* pipeline, requires no database context, and is not recorded in query
* logs. Returns false on any connectivity failure rather than throwing.
*
* @return bool True when ClickHouse is reachable, false otherwise.
*/
public function ping(): bool
{
$scheme = $this->secure ? 'https' : 'http';
$url = "{$scheme}://{$this->host}:{$this->port}/ping";

try {
$response = $this->client->fetch(url: $url, method: Client::METHOD_GET);
} catch (\Throwable) {
return false;
}

return $response->getStatusCode() === 200;
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.

/**
* Validate host parameter.
*
Expand Down
16 changes: 16 additions & 0 deletions src/Audit/Adapter/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ public function getName(): string
return 'Database';
}

/**
* Ping the database to check connectivity.
*
* Returns false on any connectivity failure rather than throwing.
*
* @return bool True when the database is reachable, false otherwise.
*/
public function ping(): bool
{
try {
return $this->db->ping();
} catch (\Throwable) {
return false;
}
}

/**
* Setup database structure.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Audit/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,16 @@ public function count(array $queries = [], ?int $max = null): int
{
return $this->adapter->count($queries, $max);
}

/**
* Ping the adapter to check connectivity.
*
* Returns false on any connectivity failure rather than throwing.
*
* @return bool True when the backing store is reachable, false otherwise.
*/
public function ping(): bool
{
return $this->adapter->ping();
}
}
5 changes: 5 additions & 0 deletions tests/Audit/AuditBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public function createLogs(): void
$this->assertInstanceOf('Utopia\\Audit\\Log', $this->audit->log(null, 'insert', 'user/null', $userAgent, $ip, $dataWithAttributes));
}

public function testPing(): void
{
$this->assertTrue($this->audit->ping());
}

public function testGetLogsByUser(): void
{
$logs = $this->audit->getLogsByUser('userId');
Expand Down
Loading